public static ServiceProxyImpl forService(ServiceImpl owner, OmiscidService omiscidService) { Map<Integer, ProxyInfo> proxies; synchronized (proxyForService) { proxies = proxyForService.get(owner); if (proxies == null) { proxies = new Hashtable<Integer, ProxyInfo>(); proxyForService.put(owner, proxies); } } ProxyInfo proxyInfo; synchronized (proxies) { proxyInfo = proxies.get(omiscidService.getRemotePeerId()); if (proxyInfo == null) { proxyInfo = new ProxyInfo(); proxies.put(omiscidService.getRemotePeerId(), proxyInfo); } } synchronized (proxyInfo) { long now = System.currentTimeMillis(); if (proxyInfo.timeout < now) { try { proxyInfo.serviceProxyImpl = new ServiceProxyImpl(omiscidService); proxyInfo.timeout = Long.MAX_VALUE; // ignoring timeout for now //now + ???; } catch (RuntimeException e) { proxyInfo.serviceProxyImpl = null; proxyInfo.timeout = now; } } } return proxyInfo.serviceProxyImpl; // return new ServiceProxyImpl(omiscidService); }
public Iterable<Integer> getPeers(String connectorName) { omiscidService.requeryCompleteDescription(); InOutputAttribute connector = omiscidService.findConnector(connectorName); if (connector == null) { throw new UnknownConnector("Unknown connector: '" + connectorName + "'"); } Vector<Integer> peers = new Vector<Integer>(connector.getPeerVector()); return peers; }
private VariableAttribute getVariable(String varName) throws UnknownVariable { VariableAttribute varAttr = omiscidService.findVariable(varName); if (varAttr == null) { throw new UnknownVariable("Unknown variable: '" + varName + "'"); } return varAttr; }
public int getConnectorPeerId(String connectorName) { InOutputAttribute connector = omiscidService.findConnector(connectorName); if (connector == null) { throw new UnknownConnector("Unknown connector: '" + connectorName + "'"); } return connector.getPeerId(); }
private Attribute getConnector(int peerId) throws UnknownConnector { InOutputAttribute connector = omiscidService.findConnector(peerId); if (connector == null) { throw new UnknownConnector("Unknown connector with peer id: '" + peerId + "'"); } return connector; }
public String getConnectorDescription(String connectorName) throws UnknownConnector { checkedUpdateDescription(); InOutputAttribute connector = omiscidService.findConnector(connectorName); if (connector == null) { throw new UnknownConnector("Unknown connector '" + connectorName + "'"); } return connector.getDescription(); }
/* (non-Javadoc) * @see fr.prima.omiscid.service.ServiceProxy#removeRemoteVariableChangeListener(String, fr.prima.omiscid.variable.RemoteVariableChangeListener) */ public synchronized void removeRemoteVariableChangeListener( String varName, RemoteVariableChangeListener remoteVariableChangeListener) throws UnknownVariable { getVariable(varName); // This checks for the variable existence HashMap<RemoteVariableChangeListener, VariableChangeListener> listeners = remoteVariableListeners.get(varName); if (listeners != null) { VariableChangeListener varListener = listeners.get(remoteVariableChangeListener); omiscidService.unsubscribe(varName, varListener); } }
/* (non-Javadoc) * @see fr.prima.omiscid.service.ServiceProxy#addRemoteVariableChangeListener(String, fr.prima.omiscid.variable.RemoteVariableChangeListener) */ public synchronized void addRemoteVariableChangeListener( String varName, final RemoteVariableChangeListener remoteVariableChangeListener) throws UnknownVariable { getVariable(varName); // This checks for the variable existence HashMap<RemoteVariableChangeListener, VariableChangeListener> listeners = remoteVariableListeners.get(varName); if (listeners == null) // we have not registered listeners for this variable yet { listeners = new HashMap<RemoteVariableChangeListener, VariableChangeListener>(); remoteVariableListeners.put(varName, listeners); } VariableChangeListener variableChangeListener = new VariableChangeListener() { public void variableChanged(VariableAttribute var) { remoteVariableChangeListener.variableChanged( ServiceProxyImpl.this, var.getName(), var.getValueStr()); } }; listeners.put(remoteVariableChangeListener, variableChangeListener); omiscidService.subscribe(varName, variableChangeListener); }
/* (non-Javadoc) * @see fr.prima.bip.service.BipServiceProxy#getOutputConnectors() */ public Set<String> getOutputConnectors() { return omiscidService.getOutputNamesSet(); }
/* (non-Javadoc) * @see fr.prima.bip.service.BipServiceProxy#getVariables() */ public Set<String> getVariables() { return omiscidService.getVariableNamesSet(); }
/* (non-Javadoc) * @see fr.prima.bip.service.BipServiceProxy#getHostName() */ public String getHostName() { return omiscidService.getHostName(); }
/* (non-Javadoc) * @see fr.prima.omiscid.service.ServiceProxy#getName() */ public String getName() { return omiscidService.getSimplifiedName(); }
/* (non-Javadoc) * @see fr.prima.bip.service.BipServiceProxy#getPeerId() */ public int getPeerId() { return omiscidService.getRemotePeerId(); }
public String toString() { return omiscidService.toString() + " " + getInputOutputConnectors(); }
/* (non-Javadoc) * @see fr.prima.bip.service.BipServiceProxy#setVariableValue(java.lang.String, java.lang.String) */ public void setVariableValue(String varName, String value) throws UnknownVariable { getVariable(varName); // This checks for the variable existence omiscidService.queryVariableModification(varName, value); }
/* (non-Javadoc) * @see fr.prima.omiscid.service.ServiceProxy#getVariableValue(java.lang.String) */ public String getVariableValue(String varName) throws UnknownVariable { // return getVariable(varName).getValueStr(); return omiscidService.getVariableValue(getVariable(varName).getName()); }
public boolean checkedUpdateDescription() { return omiscidService.updateDescription(); }