예제 #1
0
 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);
 }
예제 #2
0
 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;
 }
예제 #3
0
 private VariableAttribute getVariable(String varName) throws UnknownVariable {
   VariableAttribute varAttr = omiscidService.findVariable(varName);
   if (varAttr == null) {
     throw new UnknownVariable("Unknown variable: '" + varName + "'");
   }
   return varAttr;
 }
예제 #4
0
 public int getConnectorPeerId(String connectorName) {
   InOutputAttribute connector = omiscidService.findConnector(connectorName);
   if (connector == null) {
     throw new UnknownConnector("Unknown connector: '" + connectorName + "'");
   }
   return connector.getPeerId();
 }
예제 #5
0
 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;
 }
예제 #6
0
 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();
 }
예제 #7
0
  /* (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);
    }
  }
예제 #8
0
  /* (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);
  }
예제 #9
0
 /* (non-Javadoc)
  * @see fr.prima.bip.service.BipServiceProxy#getOutputConnectors()
  */
 public Set<String> getOutputConnectors() {
   return omiscidService.getOutputNamesSet();
 }
예제 #10
0
 /* (non-Javadoc)
  * @see fr.prima.bip.service.BipServiceProxy#getVariables()
  */
 public Set<String> getVariables() {
   return omiscidService.getVariableNamesSet();
 }
예제 #11
0
 /* (non-Javadoc)
  * @see fr.prima.bip.service.BipServiceProxy#getHostName()
  */
 public String getHostName() {
   return omiscidService.getHostName();
 }
예제 #12
0
 /* (non-Javadoc)
  * @see fr.prima.omiscid.service.ServiceProxy#getName()
  */
 public String getName() {
   return omiscidService.getSimplifiedName();
 }
예제 #13
0
 /* (non-Javadoc)
  * @see fr.prima.bip.service.BipServiceProxy#getPeerId()
  */
 public int getPeerId() {
   return omiscidService.getRemotePeerId();
 }
예제 #14
0
 public String toString() {
   return omiscidService.toString() + " " + getInputOutputConnectors();
 }
예제 #15
0
 /* (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);
 }
예제 #16
0
 /* (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());
 }
예제 #17
0
 public boolean checkedUpdateDescription() {
   return omiscidService.updateDescription();
 }