Пример #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();
 }