Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery.common.java
/
microservice
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f8be7949
authored
May 22, 2017
by
amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
end of day commits
parent
51425c54
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
222 additions
and
27 deletions
doc/ZMQRestService.graphml
doc/ZMQRestService.png
src/main/java/microservice/MicroserviceApp.java
src/main/java/microservice/common/context/RestContext.java
src/main/java/microservice/handlers/MonitorHandler.java
src/main/java/microservice/handlers/Reactor.java
src/main/java/microservice/handlers/RestHandler.java
src/main/java/microservice/io/iface/IContainer.java
src/main/java/microservice/io/iface/CommonServices.java → src/main/java/microservice/services/CommonServices.java
src/main/java/microservice/io/impl/service/IPubSubServiceMqttImpl.java → src/main/java/microservice/services/IPubSubServiceMqttImpl.java
src/main/java/microservice/io/impl/service/IRestServiceHttpImpl.java → src/main/java/microservice/services/IRestServiceHttpImpl.java
src/main/java/microservice/io/impl/service/IRestServiceZmqImpl.java → src/main/java/microservice/services/IRestServiceZmqImpl.java
src/main/java/microservice/services/protocol/zmq/RestImpl.java
src/main/java/microservice/types/UserProfile.java
src/main/java/microservice/utils/ServiceBuilderFactory.java
src/main/java/microservice/utils/ZSocketPool.java
src/main/java/microservice/utils/ZsocketPoolFactory.java
src/test/java/microservice/TestMicroserviceApp.java
src/test/java/microservice/TestServicesAndMethods.java
doc/ZMQRestService.graphml
View file @
f8be7949
This diff is collapsed.
Click to expand it.
doc/ZMQRestService.png
View file @
f8be7949
40.2 KB
|
W:
|
H:
44.7 KB
|
W:
|
H:
2-up
Swipe
Onion skin
src/main/java/microservice/MicroserviceApp.java
View file @
f8be7949
...
...
@@ -14,6 +14,7 @@ import microservice.io.impl.*;
import
microservice.params.RMQClientParams
;
import
microservice.params.RestServerParams
;
import
microservice.services.CommonServices
;
import
org.eclipse.paho.client.mqttv3.MqttException
;
import
rabbitmq.common.RMQId
;
...
...
@@ -23,11 +24,8 @@ import rabbitmq.server.RMQServer;
import
java.util.*
;
import
java.util.Map.Entry
;
import
java.util.function.BiConsumer
;
import
java.util.function.Consumer
;
import
java.util.stream.Stream
;
import
static
io
.
undertow
.
Handlers
.
resource
;
import
static
microservice
.
handlers
.
MonitorHandler
.
MON_PREFIX
;
/*
* TO DO:
...
...
src/main/java/microservice/common/context/RestContext.java
View file @
f8be7949
...
...
@@ -5,8 +5,7 @@ import java.util.Map;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
microservice.defs.Enums
;
import
microservice.io.iface.CommonServices
;
import
microservice.services.CommonServices
;
import
microservice.io.iface.IContainer
;
import
microservice.io.iface.IRequest
;
import
microservice.io.iface.IResponse
;
...
...
src/main/java/microservice/handlers/MonitorHandler.java
View file @
f8be7949
...
...
@@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
microservice.MicroserviceApp
;
import
microservice.defs.Enums
;
import
microservice.
io.iface
.CommonServices
;
import
microservice.
services
.CommonServices
;
import
microservice.io.iface.IConfiguration
;
import
microservice.io.impl.IMetricsFactoryImpl
;
import
microservice.types.BaseRestResponse
;
...
...
src/main/java/microservice/handlers/Reactor.java
View file @
f8be7949
...
...
@@ -3,7 +3,7 @@ package microservice.handlers;
import
io.undertow.util.PathTemplateMatcher
;
import
microservice.defs.Constants
;
import
microservice.defs.Enums
;
import
microservice.
io.iface
.CommonServices
;
import
microservice.
services
.CommonServices
;
import
microservice.io.iface.ILogger
;
import
microservice.io.iface.IMetricsFactory
;
...
...
src/main/java/microservice/handlers/RestHandler.java
View file @
f8be7949
package
microservice
.
handlers
;
import
com.eaio.uuid.UUID
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.ExpiredJwtException
;
...
...
@@ -21,6 +20,7 @@ import microservice.io.iface.IMetricsFactory.ITimer;
import
microservice.io.impl.IMetricsFactoryImpl
;
import
microservice.io.impl.IRequestRestImpl
;
import
microservice.io.impl.IResponseRestImpl
;
import
microservice.services.CommonServices
;
import
microservice.types.BaseRestResponse
;
import
microservice.types.UserProfile
;
...
...
src/main/java/microservice/io/iface/IContainer.java
View file @
f8be7949
...
...
@@ -18,6 +18,8 @@ public interface IContainer
{
public
static
Pattern
slashSeperatorPattern
=
Pattern
.
compile
(
"/"
);
public
static
Pattern
spaceSeperatorPattern
=
Pattern
.
compile
(
" "
);
public
static
Pattern
queryParamsSeperatorPattern
=
Pattern
.
compile
(
"&"
);
public
static
Pattern
keyvalParamSeperatorPattern
=
Pattern
.
compile
(
"="
);
public
void
sendErrorResp
(
IResponse
response
,
String
error
);
...
...
src/main/java/microservice/
io/iface
/CommonServices.java
→
src/main/java/microservice/
services
/CommonServices.java
View file @
f8be7949
package
microservice
.
io
.
iface
;
package
microservice
.
services
;
import
microservice.defs.Enums
;
import
microservice.io.iface.IRequest
;
import
microservice.io.iface.IResponse
;
import
microservice.io.iface.IServiceDiscovery
;
import
microservice.params.CommandParams
;
import
microservice.types.BaseRestResponse
;
...
...
src/main/java/microservice/
io/impl/service
/IPubSubServiceMqttImpl.java
→
src/main/java/microservice/
services
/IPubSubServiceMqttImpl.java
View file @
f8be7949
package
microservice
.
io
.
impl
.
service
;
package
microservice
.
services
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
common.JsonHandler
;
import
microservice.io.iface.CommonServices
;
import
microservice.services.CommonServices
;
import
microservice.io.iface.IServiceDiscovery
;
import
org.eclipse.paho.client.mqttv3.*
;
...
...
src/main/java/microservice/
io/impl/service
/IRestServiceHttpImpl.java
→
src/main/java/microservice/
services
/IRestServiceHttpImpl.java
View file @
f8be7949
package
microservice
.
io
.
impl
.
service
;
package
microservice
.
services
;
import
com.eaio.uuid.UUID
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
common.Network
;
import
io.jsonwebtoken.Claims
;
...
...
@@ -28,6 +27,7 @@ import microservice.io.impl.IRequestRestImpl;
import
microservice.io.impl.IResponseRestImpl
;
import
microservice.params.CommandParams
;
import
microservice.params.RestServerParams
;
import
microservice.services.CommonServices
;
import
microservice.types.BaseRestResponse
;
import
microservice.types.UserProfile
;
...
...
src/main/java/microservice/
io/impl/service
/IRestServiceZmqImpl.java
→
src/main/java/microservice/
services
/IRestServiceZmqImpl.java
View file @
f8be7949
This diff is collapsed.
Click to expand it.
src/main/java/microservice/services/protocol/zmq/RestImpl.java
0 → 100644
View file @
f8be7949
package
microservice
.
services
.
protocol
.
zmq
;
import
microservice.common.context.RestMsg
;
import
microservice.io.iface.IRequest
;
import
microservice.io.iface.IResponse
;
import
java.io.InputStream
;
import
java.nio.ByteBuffer
;
import
java.util.List
;
/**
* Created by amir on 22/05/17.
*/
public
class
RestImpl
{
public
static
class
IRequestZmqRestImpl
implements
IRequest
{
RestMsg
restMsg
=
null
;
public
IRequestZmqRestImpl
(
RestMsg
restMsg
)
{
this
.
restMsg
=
restMsg
;
}
@Override
public
InputStream
getInputStream
()
{
return
null
;
}
@Override
public
String
getQueryString
()
{
return
null
;
}
@Override
public
String
getRelativePath
()
{
return
null
;
}
@Override
public
String
getFirstHeader
(
String
headerName
)
{
return
null
;
}
@Override
public
List
<
String
>
getHeader
(
String
headerName
)
{
return
null
;
}
@Override
public
boolean
startAsync
(
Runnable
asyncFunc
)
{
return
false
;
}
}
public
static
class
IResponseZmqRestImpl
implements
IResponse
{
RestMsg
restMsg
=
null
;
public
IResponseZmqRestImpl
(
RestMsg
restMsg
)
{
this
.
restMsg
=
restMsg
;
}
@Override
public
void
send
(
ByteBuffer
buffer
)
{
}
@Override
public
void
send
(
String
response
)
{
}
}
}
\ No newline at end of file
src/main/java/microservice/types/UserProfile.java
View file @
f8be7949
...
...
@@ -2,8 +2,7 @@ package microservice.types;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.impl.DefaultClaims
;
import
microservice.defs.Enums
;
import
microservice.io.iface.CommonServices
;
import
microservice.services.CommonServices
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
src/main/java/microservice/utils/ServiceBuilderFactory.java
View file @
f8be7949
package
microservice
.
utils
;
import
microservice.
io.iface
.CommonServices
;
import
microservice.
services
.CommonServices
;
import
microservice.io.iface.IRestClient
;
import
microservice.io.impl.IRestClientHttpImpl
;
import
microservice.
io.impl.service
.IRestServiceHttpImpl
;
import
microservice.
io.impl.service
.IRestServiceZmqImpl
;
import
microservice.
services
.IRestServiceHttpImpl
;
import
microservice.
services
.IRestServiceZmqImpl
;
import
microservice.params.RestClientParams
;
import
microservice.params.RestServerParams
;
import
microservice.params.ZMQParams
;
...
...
src/main/java/microservice/utils/ZSocketPool.java
0 → 100644
View file @
f8be7949
package
microservice
.
utils
;
import
org.apache.commons.pool2.PooledObjectFactory
;
import
org.apache.commons.pool2.impl.GenericObjectPool
;
import
org.apache.commons.pool2.impl.GenericObjectPoolConfig
;
import
org.zeromq.ZSocket
;
/**
* Created by amir on 22/05/17.
*/
public
class
ZSocketPool
extends
GenericObjectPool
<
ZSocket
>
{
public
ZSocketPool
(
PooledObjectFactory
<
ZSocket
>
factory
,
int
maxTotal
)
{
super
(
factory
);
this
.
setMaxTotal
(
maxTotal
);
}
public
static
ZSocketPool
buildPool
(
String
address
,
int
socketType
,
int
maxTotal
){
return
new
ZSocketPool
(
new
ZsocketPoolFactory
(
address
,
socketType
),
maxTotal
);
}
}
src/main/java/microservice/utils/ZsocketPoolFactory.java
0 → 100644
View file @
f8be7949
package
microservice
.
utils
;
import
org.apache.commons.pool2.BasePooledObjectFactory
;
import
org.apache.commons.pool2.PooledObject
;
import
org.apache.commons.pool2.impl.DefaultPooledObject
;
import
org.zeromq.ZSocket
;
/**
* Created by amir on 22/05/17.
*/
public
class
ZsocketPoolFactory
extends
BasePooledObjectFactory
<
ZSocket
>
{
String
address
;
int
socketType
;
public
ZsocketPoolFactory
(
String
address
,
int
socketType
)
{
this
.
address
=
address
;
this
.
socketType
=
socketType
;
}
@Override
public
ZSocket
create
()
throws
Exception
{
ZSocket
socket
=
new
ZSocket
(
socketType
);
if
(!
socket
.
connect
(
address
))
socket
=
null
;
return
socket
;
}
@Override
public
PooledObject
<
ZSocket
>
wrap
(
ZSocket
obj
)
{
return
new
DefaultPooledObject
<
ZSocket
>(
obj
);
}
@Override
public
PooledObject
<
ZSocket
>
makeObject
()
throws
Exception
{
return
super
.
makeObject
();
}
@Override
public
boolean
validateObject
(
PooledObject
<
ZSocket
>
p
)
{
return
super
.
validateObject
(
p
);
}
@Override
public
void
activateObject
(
PooledObject
<
ZSocket
>
p
)
throws
Exception
{
super
.
activateObject
(
p
);
}
@Override
public
void
passivateObject
(
PooledObject
<
ZSocket
>
p
)
throws
Exception
{
super
.
passivateObject
(
p
);
}
}
src/test/java/microservice/TestMicroserviceApp.java
View file @
f8be7949
...
...
@@ -5,10 +5,10 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
microservice.common.context.RestContext
;
import
microservice.defs.Enums
;
import
microservice.
io.iface
.CommonServices
;
import
microservice.
services
.CommonServices
;
import
microservice.io.iface.IRestClient
;
import
microservice.io.impl.*
;
import
microservice.
io.impl.service
.IRestServiceHttpImpl
;
import
microservice.
services
.IRestServiceHttpImpl
;
import
microservice.params.*
;
import
microservice.types.BaseRestResponse
;
...
...
src/test/java/microservice/TestServicesAndMethods.java
View file @
f8be7949
...
...
@@ -2,20 +2,19 @@ package microservice;
import
com.google.common.cache.Cache
;
import
com.google.common.cache.CacheBuilder
;
import
com.google.common.cache.CacheLoader
;
import
com.google.common.cache.LoadingCache
;
import
common.CacheClient
;
import
common.GuavaCacheClient
;
import
io.undertow.predicate.Predicate
;
import
io.undertow.util.PathTemplateMatcher
;
import
microservice.
io.iface
.CommonServices
;
import
microservice.
services
.CommonServices
;
import
org.junit.Test
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.concurrent.TimeUnit
;
import
java.util.function.BiConsumer
;
import
java.util.stream.Collectors
;
/**
* Created by amir on 08/05/17.
...
...
@@ -78,6 +77,57 @@ public class TestServicesAndMethods {
// System.out.println("Found match: " + match.getMatchedTemplate());
}
@Test
public
void
testMap
(){
class
Staff
{
private
String
name
;
private
int
age
;
private
String
direction
;
public
Staff
(
String
name
,
int
age
,
String
direction
)
{
this
.
name
=
name
;
this
.
age
=
age
;
this
.
direction
=
direction
;
}
public
String
getName
()
{
return
name
;
}
public
int
getAge
()
{
return
age
;
}
public
String
getDirection
()
{
return
direction
;
}
@Override
public
String
toString
()
{
return
"Staff{"
+
"name='"
+
name
+
'\''
+
", age="
+
age
+
", direction='"
+
direction
+
'\''
+
'}'
;
}
}
//List<String> stringList = Arrays.asList("N", "S", "W", "E", "NW", "SW");
List
<
Staff
>
staff
=
Arrays
.
asList
(
new
Staff
(
"mkyong"
,
30
,
"N"
),
new
Staff
(
"jack"
,
27
,
"S"
),
new
Staff
(
"lawrence"
,
33
,
"SW"
),
new
Staff
(
"lucy"
,
33
,
"N"
)
);
//Java 8
// Map<String,String> map = staff.stream().collect(Collectors.toMap(Staff::getDirection,Staff::getName));
// System.out.println(map); //[mkyong, jack, lawrence]
final
Map
<
String
,
List
<
Staff
>>
listMap
=
staff
.
stream
().
collect
(
Collectors
.
groupingBy
(
s
->
s
.
getDirection
()));
System
.
out
.
println
(
listMap
);
//[mkyong, jack, lawrence]
}
@Test
public
void
testCache
(){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment