private ServiceHandle getServiceHandle(Object o, List<String> watches, Entry[] entries) {
ServiceHandle handle = new ServiceHandle();
if(o instanceof Service) {
Service s = (Service)o;
try {
ServiceElement elem = ((ServiceAdmin)s.getAdmin()).getServiceElement();
OperationalStringManager opMgr = ((DeployAdmin)monitor.getAdmin()).getOperationalStringManager(elem.getOperationalStringName());
handle.setElem(elem);
handle.setOpMgr(opMgr);
for(String watch : watches) {
try {
WatchDataSource wds = s.fetch(watch);
logger.debug("WatchDataSource for watch [{}]: {}", watch, wds);
if(wds==null)
continue;
handle.addToWatchMap(watch, wds);
ThresholdValues tVals = wds.getThresholdValues();
if(tVals instanceof SLA) {
handle.addToSLAMap(watch, (SLA)tVals);
}
} catch (RemoteException e) {
logger.warn("Could not add AssociationsWatchDataReplicator to remote WatchDataSource.", e);
}
}
} catch (RemoteException e) {
handle = null;
logger.warn("Could not get ServiceElement or OperationalStringManager.", e);
} catch (OperationalStringException e) {
handle = null;
logger.error("Could not get OperationalStringManager, unable to create AssociationsWatchDataReplicator.",
e);
}
} else {
String opStringName = null;
for(Entry e : entries) {
if(e instanceof OperationalStringEntry) {
opStringName = ((OperationalStringEntry)e).name;
break;
}
}
logger.info("OperationalString for service: [{}]", opStringName);
if(opStringName!=null) {
try {
OperationalStringManager opMgr = ((DeployAdmin)monitor.getAdmin()).getOperationalStringManager(opStringName);
ServiceElement elem = opMgr.getServiceElement(o);
if(elem==null) {
logger.warn("Unable to obtain ServiceElement for service [{}], cannot create AssociationsWatchDataReplicator.",
o.toString());
return null;
}
handle.setElem(elem);
handle.setOpMgr(opMgr);
Cybernode c = null;
for(ServiceBeanInstance sbi : opMgr.getServiceBeanInstances(elem)) {
if(o.equals(sbi.getService())) {
elem.setServiceBeanConfig(sbi.getServiceBeanConfig());
Uuid uuid = sbi.getServiceBeanInstantiatorID();
for(ServiceBeanInstantiator s : monitor.getServiceBeanInstantiators()) {
if(uuid.equals(s.getInstantiatorUuid())) {
c = (Cybernode)s;
break;
}
}
}
}
if(c!=null) {
Watchable w;
if(elem.forkService()) {
int registryPort = ((CybernodeAdmin)c.getAdmin()).getRegistryPort();
String address = c.getInetAddress().getHostAddress();
Registry registry = LocateRegistry.getRegistry(address, registryPort);
Remote r = null;
NotBoundException notBound = null;
//for(int i=0; i<3; i++) {
try {
r = registry.lookup(RMIServiceNameHelper.createBindName(elem));
} catch (NotBoundException e) {
notBound = e;
//try {
// Thread.sleep(1000);
//} catch (InterruptedException e1) {
// e1.printStackTrace();
//}
}
//}
if(r==null) {
logger.error("Could not get ServiceBeanExecutor, unable to create AssociationsWatchDataReplicator.",
notBound);
return null;
}
if(r instanceof Watchable) {
w = (Watchable)r;
} else {
logger.warn("Could not get Watchable from Registry at [{}:{}], unable to " +
"create AssociationsWatchDataReplicator for service [{}]",
address, registryPort, elem.getName());
return null;
}
} else {
w = c;
}
for(String watch : watches) {
try {
WatchDataSource wds = w.fetch(watch);
logger.debug("WatchDataSource for watch [{}]: {}", watch, wds);
if(wds==null)
continue;
handle.addToWatchMap(watch, wds);
ThresholdValues tVals = wds.getThresholdValues();
if(tVals instanceof SLA) {
handle.addToSLAMap(watch, (SLA)tVals);
}
} catch (RemoteException e) {
logger.warn("Could not add AssociationsWatchDataReplicator to remote WatchDataSource.", e);
}
}
} else {
logger.warn("Unable to obtain Cybernode for service [{}]", elem.getName());
}
} catch (RemoteException e) {
handle = null;
logger.warn("Could not get ServiceElement or OperationalStringManager.", e);
} catch (OperationalStringException e) {