FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-sdk/src/main/java/co/stateful/RtCounter.java at master · sttc/java-sdk · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
sttc
/
java-sdk
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
9
Code
Issues
3
Pull requests
4
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
java-sdk
/
src
/
main
/
java
/
co
/
stateful
/
RtCounter.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
96 lines (87 loc) · 2.62 KB
Breadcrumbs
java-sdk
/
src
/
main
/
java
/
co
/
stateful
/
RtCounter.java
Copy path
File metadata and controls
96 lines (87 loc) · 2.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* SPDX-FileCopyrightText: Copyright (c) 2014-2026, stateful.co
* SPDX-License-Identifier: MIT
*/
package
co
.
stateful
;
import
com
.
jcabi
.
aspects
.
Immutable
;
import
com
.
jcabi
.
aspects
.
Loggable
;
import
com
.
jcabi
.
http
.
Request
;
import
com
.
jcabi
.
http
.
response
.
RestResponse
;
import
com
.
jcabi
.
http
.
response
.
XmlResponse
;
import
com
.
jcabi
.
log
.
Logger
;
import
jakarta
.
ws
.
rs
.
core
.
HttpHeaders
;
import
jakarta
.
ws
.
rs
.
core
.
MediaType
;
import
java
.
io
.
IOException
;
import
java
.
net
.
HttpURLConnection
;
import
lombok
.
EqualsAndHashCode
;
import
lombok
.
ToString
;
/**
* Counter.
* @since 0.1
*/
@
Immutable
@
Loggable
(
Loggable
.
DEBUG
)
@
ToString
(
of
=
"label"
,
includeFieldNames
=
false
)
@
EqualsAndHashCode
(
of
= {
"label"
,
"request"
})
final
class
RtCounter
implements
Counter
{
/**
* Its name.
*/
private
final
transient
String
label
;
/**
* Home request.
*/
private
final
transient
Request
request
;
/**
* Ctor.
* @param name Name of it
* @param req Home page request
*/
RtCounter
(
final
String
name
,
final
Request
req
) {
this
.
label
=
name
;
this
.
request
=
req
;
}
@
Override
public
String
name
() {
return
this
.
label
;
}
@
Override
public
void
set
(
final
long
value
)
throws
IOException
{
this
.
front
(
"set"
).
method
(
Request
.
PUT
)
.
uri
().
queryParam
(
"value"
,
value
).
back
()
.
fetch
()
.
as
(
RestResponse
.
class
)
.
assertStatus
(
HttpURLConnection
.
HTTP_OK
);
Logger
.
info
(
this
,
"counter
\"
%s
\"
set to %d"
,
this
.
label
,
value
);
}
@
Override
public
long
incrementAndGet
(
final
long
delta
)
throws
IOException
{
final
long
value
=
Long
.
parseLong
(
this
.
front
(
"increment"
).
method
(
Request
.
GET
)
.
uri
().
queryParam
(
"value"
,
delta
).
back
()
.
header
(
HttpHeaders
.
ACCEPT
,
MediaType
.
TEXT_PLAIN
)
.
fetch
()
.
as
(
RestResponse
.
class
)
.
assertStatus
(
HttpURLConnection
.
HTTP_OK
)
.
body
()
);
Logger
.
info
(
this
,
"counter
\"
%s
\"
incremented by %d to %d"
,
this
.
label
,
delta
,
value
);
return
value
;
}
private
Request
front
(
final
String
ops
)
throws
IOException
{
return
this
.
request
.
header
(
HttpHeaders
.
ACCEPT
,
MediaType
.
TEXT_XML
)
.
fetch
()
.
as
(
RestResponse
.
class
)
.
assertStatus
(
HttpURLConnection
.
HTTP_OK
)
.
as
(
XmlResponse
.
class
).
rel
(
String
.
format
(
"/page/counters/counter[name='%s']/links/link[@rel='%s']/@href"
,
this
.
label
,
ops
)
);
}
}
Back
|
FazBrowse Home
|
New Git URL