Commit f8be7949 by amir

end of day commits

parent 51425c54

40.2 KB | W: | H:

44.7 KB | W: | H:

doc/ZMQRestService.png
doc/ZMQRestService.png
doc/ZMQRestService.png
doc/ZMQRestService.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -14,6 +14,7 @@ import microservice.io.impl.*; ...@@ -14,6 +14,7 @@ import microservice.io.impl.*;
import microservice.params.RMQClientParams; import microservice.params.RMQClientParams;
import microservice.params.RestServerParams; import microservice.params.RestServerParams;
import microservice.services.CommonServices;
import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttException;
import rabbitmq.common.RMQId; import rabbitmq.common.RMQId;
...@@ -23,11 +24,8 @@ import rabbitmq.server.RMQServer; ...@@ -23,11 +24,8 @@ import rabbitmq.server.RMQServer;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Stream;
import static io.undertow.Handlers.resource; import static io.undertow.Handlers.resource;
import static microservice.handlers.MonitorHandler.MON_PREFIX;
/* /*
* TO DO: * TO DO:
......
...@@ -5,8 +5,7 @@ import java.util.Map; ...@@ -5,8 +5,7 @@ import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import microservice.defs.Enums; import microservice.services.CommonServices;
import microservice.io.iface.CommonServices;
import microservice.io.iface.IContainer; import microservice.io.iface.IContainer;
import microservice.io.iface.IRequest; import microservice.io.iface.IRequest;
import microservice.io.iface.IResponse; import microservice.io.iface.IResponse;
......
...@@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory; ...@@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import microservice.MicroserviceApp; import microservice.MicroserviceApp;
import microservice.defs.Enums; import microservice.defs.Enums;
import microservice.io.iface.CommonServices; import microservice.services.CommonServices;
import microservice.io.iface.IConfiguration; import microservice.io.iface.IConfiguration;
import microservice.io.impl.IMetricsFactoryImpl; import microservice.io.impl.IMetricsFactoryImpl;
import microservice.types.BaseRestResponse; import microservice.types.BaseRestResponse;
......
...@@ -3,7 +3,7 @@ package microservice.handlers; ...@@ -3,7 +3,7 @@ package microservice.handlers;
import io.undertow.util.PathTemplateMatcher; import io.undertow.util.PathTemplateMatcher;
import microservice.defs.Constants; import microservice.defs.Constants;
import microservice.defs.Enums; import microservice.defs.Enums;
import microservice.io.iface.CommonServices; import microservice.services.CommonServices;
import microservice.io.iface.ILogger; import microservice.io.iface.ILogger;
import microservice.io.iface.IMetricsFactory; import microservice.io.iface.IMetricsFactory;
......
package microservice.handlers; package microservice.handlers;
import com.eaio.uuid.UUID; import com.eaio.uuid.UUID;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException; import io.jsonwebtoken.ExpiredJwtException;
...@@ -21,6 +20,7 @@ import microservice.io.iface.IMetricsFactory.ITimer; ...@@ -21,6 +20,7 @@ import microservice.io.iface.IMetricsFactory.ITimer;
import microservice.io.impl.IMetricsFactoryImpl; import microservice.io.impl.IMetricsFactoryImpl;
import microservice.io.impl.IRequestRestImpl; import microservice.io.impl.IRequestRestImpl;
import microservice.io.impl.IResponseRestImpl; import microservice.io.impl.IResponseRestImpl;
import microservice.services.CommonServices;
import microservice.types.BaseRestResponse; import microservice.types.BaseRestResponse;
import microservice.types.UserProfile; import microservice.types.UserProfile;
......
...@@ -18,6 +18,8 @@ public interface IContainer ...@@ -18,6 +18,8 @@ public interface IContainer
{ {
public static Pattern slashSeperatorPattern = Pattern.compile("/"); public static Pattern slashSeperatorPattern = Pattern.compile("/");
public static Pattern spaceSeperatorPattern = 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); public void sendErrorResp(IResponse response, String error);
......
package microservice.io.iface; package microservice.services;
import microservice.defs.Enums; 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.params.CommandParams;
import microservice.types.BaseRestResponse; import microservice.types.BaseRestResponse;
......
package microservice.io.impl.service; package microservice.services;
import com.fasterxml.jackson.databind.JsonNode; import microservice.services.CommonServices;
import common.JsonHandler;
import microservice.io.iface.CommonServices;
import microservice.io.iface.IServiceDiscovery; import microservice.io.iface.IServiceDiscovery;
import org.eclipse.paho.client.mqttv3.*; import org.eclipse.paho.client.mqttv3.*;
......
package microservice.io.impl.service; package microservice.services;
import com.eaio.uuid.UUID; import com.eaio.uuid.UUID;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import common.Network; import common.Network;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
...@@ -28,6 +27,7 @@ import microservice.io.impl.IRequestRestImpl; ...@@ -28,6 +27,7 @@ import microservice.io.impl.IRequestRestImpl;
import microservice.io.impl.IResponseRestImpl; import microservice.io.impl.IResponseRestImpl;
import microservice.params.CommandParams; import microservice.params.CommandParams;
import microservice.params.RestServerParams; import microservice.params.RestServerParams;
import microservice.services.CommonServices;
import microservice.types.BaseRestResponse; import microservice.types.BaseRestResponse;
import microservice.types.UserProfile; import microservice.types.UserProfile;
......
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
...@@ -2,8 +2,7 @@ package microservice.types; ...@@ -2,8 +2,7 @@ package microservice.types;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
import io.jsonwebtoken.impl.DefaultClaims; import io.jsonwebtoken.impl.DefaultClaims;
import microservice.defs.Enums; import microservice.services.CommonServices;
import microservice.io.iface.CommonServices;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
......
package microservice.utils; package microservice.utils;
import microservice.io.iface.CommonServices; import microservice.services.CommonServices;
import microservice.io.iface.IRestClient; import microservice.io.iface.IRestClient;
import microservice.io.impl.IRestClientHttpImpl; import microservice.io.impl.IRestClientHttpImpl;
import microservice.io.impl.service.IRestServiceHttpImpl; import microservice.services.IRestServiceHttpImpl;
import microservice.io.impl.service.IRestServiceZmqImpl; import microservice.services.IRestServiceZmqImpl;
import microservice.params.RestClientParams; import microservice.params.RestClientParams;
import microservice.params.RestServerParams; import microservice.params.RestServerParams;
import microservice.params.ZMQParams; import microservice.params.ZMQParams;
......
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);
}
}
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);
}
}
...@@ -5,10 +5,10 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory; ...@@ -5,10 +5,10 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import microservice.common.context.RestContext; import microservice.common.context.RestContext;
import microservice.defs.Enums; import microservice.defs.Enums;
import microservice.io.iface.CommonServices; import microservice.services.CommonServices;
import microservice.io.iface.IRestClient; import microservice.io.iface.IRestClient;
import microservice.io.impl.*; import microservice.io.impl.*;
import microservice.io.impl.service.IRestServiceHttpImpl; import microservice.services.IRestServiceHttpImpl;
import microservice.params.*; import microservice.params.*;
import microservice.types.BaseRestResponse; import microservice.types.BaseRestResponse;
......
...@@ -2,20 +2,19 @@ package microservice; ...@@ -2,20 +2,19 @@ package microservice;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; 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.predicate.Predicate;
import io.undertow.util.PathTemplateMatcher; import io.undertow.util.PathTemplateMatcher;
import microservice.io.iface.CommonServices; import microservice.services.CommonServices;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.stream.Collectors;
/** /**
* Created by amir on 08/05/17. * Created by amir on 08/05/17.
...@@ -78,6 +77,57 @@ public class TestServicesAndMethods { ...@@ -78,6 +77,57 @@ public class TestServicesAndMethods {
// System.out.println("Found match: " + match.getMatchedTemplate()); // 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 @Test
public void testCache(){ public void testCache(){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment