Changeset 110 for branches/supervisor
- Timestamp:
- 10/22/13 15:15:51 (11 years ago)
- Location:
- branches/supervisor
- Files:
-
- 2 added
- 1 deleted
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/supervisor/src/main/java/omq/client/proxy/Proxymq.java
r107 r110 380 380 381 381 @Override 382 public void setUID(String uID) { 382 public void setUID(String uID) {System.out.println("SET UID"); 383 383 this.UID = uID; 384 384 } -
branches/supervisor/src/main/java/omq/common/broker/RemoteBrokerImpl.java
r107 r110 28 28 @Override 29 29 public void spawnObject(String reference, String className, Properties env) throws Exception { 30 System.out.println("SPAWN broker = " + this.getUID()); 30 31 RemoteObject remote = (RemoteObject) Class.forName(className).newInstance(); 31 32 getBroker().bind(reference, remote, env); … … 34 35 @Override 35 36 public void spawnObject(String reference, String className) throws Exception { 37 System.out.println("SPAWN broker = " + this.getUID()); 36 38 RemoteObject remote = (RemoteObject) Class.forName(className).newInstance(); 37 39 getBroker().bind(reference, remote); … … 50 52 @Override 51 53 public HasObject hasObjectInfo(String reference) throws RetryException { 52 System.out.println("Hola soc un broker" + getRef() + ", "+getUID()+ ", fil: "+Thread.currentThread().getId());54 System.out.println("Hola soc un broker" + getRef() + ", " + getUID() + ", fil: " + Thread.currentThread().getId()); 53 55 if (getBroker().getRemoteObjs().containsKey(reference)) { 54 56 RemoteObject r = getBroker().getRemoteObjs().get(reference); -
branches/supervisor/src/main/java/omq/supervisor/RemoteBroker.java
r107 r110 1 package omq.common.broker; 1 package omq.supervisor; 2 3 import java.io.IOException; 4 import java.util.Properties; 2 5 3 6 import omq.Remote; 7 import omq.client.annotation.AsyncMethod; 4 8 import omq.client.annotation.MultiMethod; 5 9 import omq.client.annotation.SyncMethod; 10 import omq.common.broker.HasObject; 11 import omq.exception.RemoteException; 6 12 import omq.exception.RetryException; 7 13 8 public interface RemoteMultiBroker extends Remote { 14 public interface RemoteBroker extends Remote { 15 16 @AsyncMethod 17 public void spawnObject(String reference, String className, Properties env) throws Exception; 18 19 @AsyncMethod 20 public void spawnObject(String reference, String className) throws Exception; 21 22 @AsyncMethod 23 public void deleteObject(String reference) throws RemoteException, IOException; 9 24 10 25 @MultiMethod -
branches/supervisor/src/main/java/omq/supervisor/SupervisorImpl.java
r107 r110 1 1 package omq.supervisor; 2 2 3 import java.lang.reflect.Proxy;4 3 import java.util.HashMap; 4 import java.util.HashSet; 5 5 import java.util.Map; 6 6 import java.util.Set; 7 7 8 import omq.client.proxy.Proxymq;9 8 import omq.common.broker.HasObject; 10 import omq.common.broker.RemoteBroker;11 import omq.common.broker.RemoteMultiBroker;12 9 import omq.exception.RemoteException; 13 10 import omq.server.RemoteObject; … … 29 26 private long sleep; 30 27 private Map<String, OmqSettings> objectSettings; 31 private Remote MultiBroker multiBroker;32 private Map<String, RemoteBroker> brokerMap;28 private RemoteBroker broker; 29 private Set<String> brokers; 33 30 34 31 public SupervisorImpl(String brokerSet, long sleep) { 35 32 this.brokerSet = brokerSet; 36 33 this.sleep = sleep; 37 broker Map = new HashMap<String, RemoteBroker>();34 brokers = new HashSet<String>(); 38 35 objectSettings = new HashMap<String, OmqSettings>(); 39 36 } … … 42 39 public void run() { 43 40 try { 44 multiBroker = getBroker().lookup(brokerSet, RemoteMultiBroker.class);41 broker = getBroker().lookup(brokerSet, RemoteBroker.class); 45 42 while (true) { 46 43 try { … … 68 65 @Override 69 66 public void subscribe(String brokerSet, String brokerName) throws Exception { 70 if (brokerSet.equals(brokerSet) && !broker Map.containsKey(brokerName)) {67 if (brokerSet.equals(brokerSet) && !brokers.contains(brokerName)) { 71 68 logger.info("Broker " + brokerName + " subscrived"); 72 // RemoteBroker broker = getBroker().lookup(brokerSet, 73 // RemoteBroker.class); 74 Proxymq proxy = new Proxymq(brokerSet, RemoteBroker.class, getBroker()); 75 Class<?>[] array = { RemoteBroker.class }; 76 RemoteBroker broker = (RemoteBroker) Proxy.newProxyInstance(RemoteBroker.class.getClassLoader(), array, proxy); 77 broker.setUID(brokerName); 78 brokerMap.put(brokerSet, broker); 69 brokers.add(brokerName); 79 70 } else { 80 71 throw new Exception("blablabla"); … … 89 80 throw new Exception("JAJAJAJAJA"); 90 81 } 91 92 HasObject[] hasList = multiBroker.hasObjectInfo(reference);82 83 HasObject[] hasList = broker.hasObjectInfo(reference); 93 84 94 85 int minObjects = settings.getMinNumberObjects(); … … 104 95 105 96 int i = 0; 106 while (numObjects < =minObjects && i < numBrokers) {97 while (numObjects < minObjects && i < numBrokers) { 107 98 HasObject h = hasList[i++]; 108 if (h.hasObject()) { 109 brokerMap.get(h.getBrokerName()).spawnObject(reference, settings.getClassName()); 99 if (!h.hasObject()) { 100 // Use a single broker 101 broker.setUID(h.getBrokerName()); 102 broker.spawnObject(reference, settings.getClassName()); 103 // Remove the UID 104 broker.setUID(null); 110 105 numObjects++; 111 106 } 112 107 } 108 109 // Once there are some objects created, put objectSettings 113 110 objectSettings.put(reference, settings); 114 111 … … 117 114 @Override 118 115 public void spawnObject(OmqSettings settings, HasObject[] hasList, int numObjects) throws Exception { 119 116 System.out.println("FUNCIO SPAWN"); 120 117 String reference = settings.getReference(); 121 118 … … 124 121 } 125 122 123 int numBrokers = hasList.length; 124 125 if (numObjects < numBrokers) { 126 for (HasObject h : hasList) { 127 if (!h.hasObject()) { 128 // Use a single broker 129 broker.setUID(h.getBrokerName()); 130 broker.spawnObject(reference, settings.getClassName()); 131 // Remove the UID 132 broker.setUID(null); 133 break; 134 } 135 } 136 } 137 } 138 139 @Override 140 public void unbindObject(OmqSettings settings, HasObject[] hasList, int numObjects) throws Exception { 141 System.out.println("FUNCIO UNBIND"); 142 143 String reference = settings.getReference(); 144 126 145 int minObjects = settings.getMinNumberObjects(); 127 146 128 for (HasObject h : hasList) { 129 if (h.hasObject() && minObjects >= numObjects) { 130 brokerMap.get(h.getBrokerName()).spawnObject(reference, settings.getClassName(), settings.getProps()); 131 numObjects++; 132 if (minObjects >= numObjects) { 147 if (numObjects > minObjects) { 148 for (HasObject h : hasList) { 149 if (h.hasObject()) { 150 // Use a single broker 151 broker.setUID(h.getBrokerName()); 152 broker.deleteObject(reference); 153 // Remove the UID 154 broker.setUID(null); 133 155 break; 134 156 } 135 157 } 136 158 } 137 138 }139 140 @Override141 public void unbindObject(OmqSettings settings, HasObject[] hasList, int numObjects) throws Exception {142 // String reference = settings.getReference();143 //144 // int minObjects = settings.getMinNumberObjects();145 //146 // for (RemoteBroker broker : brokers) {147 // if (broker.hasObject(reference) && (numObjects - 1) >= minObjects) {148 // broker.deleteObject(reference);149 // break;150 // }151 // }152 153 159 } 154 160 … … 166 172 int numMessages = dok.getMessageCount(); 167 173 168 HasObject[] hasList = multiBroker.hasObjectInfo(reference);174 HasObject[] hasList = broker.hasObjectInfo(reference); 169 175 for (HasObject h : hasList) { 170 176 if (h.hasObject()) { … … 177 183 if (maxMessages < numMessages || numObjects < minObjects) { 178 184 logger.info("SPAWN TIME!!"); 185 System.out.println("SPAAAAAAAAAAAAAAAAAAAAAAAAAAWN TIME!!!!!"); 179 186 spawnObject(settings, hasList, numObjects); 180 187 } else if (numMessages < minMessages && minObjects < numObjects) { 181 188 logger.info("Unbinding object!!!"); 189 System.out.println("UNBINDIN OOOOOOOOOOOOOOOOOOBJECT!!!"); 182 190 unbindObject(settings, hasList, numObjects); 183 191 } … … 200 208 } 201 209 202 public RemoteMultiBroker getMultiBroker() {203 return multiBroker;204 }205 206 public void setMultiBroker(RemoteMultiBroker multiBroker) {207 this.multiBroker = multiBroker;208 }209 210 210 } -
branches/supervisor/src/main/resources/log4j.xml
r106 r110 4 4 <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> 5 5 <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender"> 6 <param name="Threshold" value=" DEBUG" />6 <param name="Threshold" value="INFO" /> 7 7 <layout class="org.apache.log4j.PatternLayout"> 8 8 <param name="ConversionPattern" value="%d{[yyyy-MM-dd HH:mm:ss]} %-5p %c:%L - %m%n" /> … … 30 30 31 31 <root> 32 <priority value =" DEBUG" />32 <priority value ="INFO" /> 33 33 <appender-ref ref="consoleAppender" /> 34 34 <appender-ref ref="A2" />
Note: See TracChangeset
for help on using the changeset viewer.