Changeset 11
- Timestamp:
- 05/17/13 15:41:11 (12 years ago)
- Location:
- trunk/objectmq/src/omq
- Files:
-
- 1 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/objectmq/src/omq/common/broker/Broker.java
r9 r11 7 7 import omq.client.remote.response.ResponseListener; 8 8 import omq.common.remote.OmqConnectionFactory; 9 import omq.common.util.Environment; 10 import omq.exception.EnvironmentException; 9 11 import omq.exception.RemoteException; 10 12 import omq.server.remote.request.RemoteObject; … … 16 18 private static Connection connection; 17 19 private static Channel channel; 18 private static Properties environment;19 20 20 21 public static void initBroker(Properties env) throws Exception { 21 if (environment == null) { 22 environment = env; 22 try { 23 Environment.getEnvironment(); 24 } catch (EnvironmentException ex) { // environment not set. 25 Environment.setEnvironment(env); 23 26 connection = OmqConnectionFactory.getConnection(env); 24 27 channel = connection.createChannel(); … … 37 40 public static Remote lookup(String reference, Class<?> contract) throws RemoteException { 38 41 try { 42 Properties environment = Environment.getEnvironment(); 43 39 44 if (ResponseListener.isVoid()) { 40 45 ResponseListener.init(environment); … … 54 59 public static void bind(String reference, RemoteObject remote) throws RemoteException { 55 60 try { 61 Properties environment = Environment.getEnvironment(); 56 62 remote.start(reference, environment); 57 63 } catch (Exception e) { -
trunk/objectmq/src/omq/common/util/Environment.java
r10 r11 11 11 * 12 12 */ 13 public class RevoEnvironment {13 public class Environment { 14 14 private static Properties env; 15 15 -
trunk/objectmq/src/omq/common/util/ParameterQueue.java
r9 r11 12 12 */ 13 13 14 public static String SERIALIZERNAME = "revo.serializer"; 15 public static String ENABLECOMPRESSION = "revo.compression"; 16 14 17 public static String SERVER_HOST = "revo.host"; 15 18 public static String SERVER_PORT = "revo.port"; -
trunk/objectmq/src/omq/common/util/Serializer.java
r10 r11 1 1 package omq.common.util; 2 3 import java.io.IOException; 4 import java.util.Properties; 2 5 3 6 import omq.common.message.Request; 4 7 import omq.common.message.Response; 5 import omq.common.util.Serializers.GsonImp;6 8 import omq.common.util.Serializers.ISerializer; 9 import omq.exception.EnvironmentException; 7 10 import omq.exception.SerializerException; 8 11 import omq.server.remote.request.RemoteObject; … … 16 19 public static ISerializer serializer; 17 20 18 public static ISerializer getInstance() { 21 private static Boolean getEnableCompression(){ 22 Boolean enableCompression = false; 23 try { 24 Properties env = Environment.getEnvironment(); 25 enableCompression = Boolean.valueOf(env.getProperty(ParameterQueue.ENABLECOMPRESSION, "false")); 26 } catch (EnvironmentException e) { } 27 28 return enableCompression; 29 } 30 31 public static ISerializer getInstance() throws SerializerException { 19 32 if (serializer == null) { 20 serializer = new GsonImp(); 21 // serializer = new JavaImp(); 22 // serializer = new KryoImp(); 33 try{ 34 Properties env = Environment.getEnvironment(); 35 String className = env.getProperty(ParameterQueue.SERIALIZERNAME, "omq.common.util.Serializers.JavaImp"); 36 37 serializer = (ISerializer) Class.forName(className).newInstance(); 38 } catch (Exception ex){ 39 throw new SerializerException(ex.getMessage(), ex); 40 } 23 41 } 42 24 43 return serializer; 25 44 } … … 27 46 public static byte[] serialize(Object obj) throws SerializerException { 28 47 ISerializer instance = getInstance(); 29 return instance.serialize(obj); 48 49 Boolean enableCompression = getEnableCompression(); 50 if(enableCompression){ 51 byte[] objSerialized = instance.serialize(obj); 52 try { 53 return Zipper.zip(objSerialized); 54 } catch (IOException e) { 55 throw new SerializerException(e.getMessage(), e); 56 } 57 } else{ 58 return instance.serialize(obj); 59 } 30 60 } 31 61 32 62 public static Request deserializeRequest(byte[] bytes, RemoteObject obj) throws SerializerException { 33 63 ISerializer instance = getInstance(); 34 return instance.deserializeRequest(bytes, obj); 64 65 Boolean enableCompression = getEnableCompression(); 66 if(enableCompression){ 67 try { 68 byte[] unZippedBytes = Zipper.unzip(bytes); 69 return instance.deserializeRequest(unZippedBytes, obj); 70 } catch (IOException e) { 71 throw new SerializerException(e.getMessage(), e); 72 } 73 } else{ 74 return instance.deserializeRequest(bytes, obj); 75 } 35 76 } 36 77 37 78 public static Response deserializeResponse(byte[] bytes, Class<?> type) throws SerializerException { 38 79 ISerializer instance = getInstance(); 39 return instance.deserializeResponse(bytes, type); 80 81 Boolean enableCompression = getEnableCompression(); 82 if(enableCompression){ 83 try { 84 byte[] unZippedBytes = Zipper.unzip(bytes); 85 return instance.deserializeResponse(unZippedBytes, type); 86 } catch (IOException e) { 87 throw new SerializerException(e.getMessage(), e); 88 } 89 } else{ 90 return instance.deserializeResponse(bytes, type); 91 } 40 92 } 41 93 } -
trunk/objectmq/src/omq/ztest/calculator/CalculatorTest.java
r9 r11 22 22 23 23 // Get host info of rabbimq (where it is) 24 env.setProperty(ParameterQueue.SERVER_HOST, "1 27.0.0.1");24 env.setProperty(ParameterQueue.SERVER_HOST, "10.30.239.228"); 25 25 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 26 env.setProperty(ParameterQueue.SERIALIZERNAME, "omq.common.util.Serializers.KryoImp"); 27 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "true"); 26 28 27 29 // Get info about the queue & the exchange where the RemoteListener will … … 44 46 45 47 // Set host info of rabbimq (where it is) 46 env.setProperty(ParameterQueue.SERVER_HOST, "1 27.0.0.1");48 env.setProperty(ParameterQueue.SERVER_HOST, "10.30.239.228"); 47 49 env.setProperty(ParameterQueue.SERVER_PORT, "5672"); 48 50 env.setProperty(ParameterQueue.SERIALIZERNAME, "omq.common.util.Serializers.KryoImp"); 51 env.setProperty(ParameterQueue.ENABLECOMPRESSION, "true"); 52 49 53 // Set info about where the message will be sent 50 54 env.setProperty(ParameterQueue.RPC_EXCHANGE, "rpc_exchange"); … … 57 61 58 62 Broker.initBroker(env); 59 60 63 remoteCalc = (Calculator) Broker.lookup(Calculator.class.getSimpleName(), Calculator.class); 61 64 }
Note: See TracChangeset
for help on using the changeset viewer.