コード例 #1
0
ファイル: Example.java プロジェクト: akivalichtner/evs4j
  public static void main(String[] args) throws Exception {

    // this should be on stable storage as per article
    long lastKnownConfigurationId = 0L;

    // group member '1'
    Processor proc = new Processor(1);

    // totem-specific configuration parameters
    String props = "port=9100&ip=225.0.0.1&nic=192.168.254.0/255.255.255.0";

    Connection conn = new evs4j.impl.SRPConnection(lastKnownConfigurationId, proc, props);

    // the default listener just discards messages
    conn.setListener(new Example());
    conn.open();

    // send a message
    boolean agreed = false;
    boolean safe = true;
    Message message = conn.createMessage(agreed);
    byte[] data = "Hello World!".getBytes();
    System.arraycopy(data, 0, message.getData(), message.getOffset(), data.length);
    message.setLength(data.length);
    conn.send(message);
  }
コード例 #2
0
 public void closeServer() {
   isActive = false;
   // Remove all connections
   synchronized (connections) {
     for (Connection c : connections) {
       c.send(DISCONNECT);
       c.setState(DISCONNECTED);
     }
   }
   connections = Collections.synchronizedList(new ArrayList<Connection>());
 }
コード例 #3
0
ファイル: RpcTemplate.java プロジェクト: montge/eHMP
  protected RpcResponse doExecute(RpcRequest request) {
    Connection c = null;
    ConnectionSpec auth = null;
    try {
      try {
        outputRequestInfo("doExecute: Before validateRequest...", request);
        request = validateRequest(request);
        outputRequestInfo("doExecute: After validateRequest...", request);
        RpcHost host = request.getHost();
        auth = createConnectionSpec(request);
        outputAuthInfo(auth);
        c = this.connectionFactory.getConnection(host, auth);
      } catch (RpcException e) {
        logger.error("doExecute: RpcException occurred.  Error: " + e.getMessage(), e);
        fireRpcExceptionEvent(request, e);
        throw getExceptionTranslator()
            .translate("open", RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
      try {
        logger.debug("executing {}", RpcUriUtils.sanitize(request.getUriString(), auth));

        RpcResponse response = c.send(request);

        logger.debug("received  {}", response.toString());

        fireRpcResponseEvent(request, response);

        return response;
      } catch (RpcException e) {
        fireRpcExceptionEvent(request, e);
        throw getExceptionTranslator()
            .translate("send", RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
    } catch (DataAccessException e) {
      if (e instanceof PermissionDeniedDataAccessException) {
        logger.debug(
            "permission denied in " + RpcUriUtils.sanitize(request.getUriString(), auth), e);
      } else {
        logger.error("error in  " + RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
      throw e;
    } finally {
      try {
        if (c != null) c.close();
      } catch (RpcException e) {
        fireRpcExceptionEvent(request, e);
        throw getExceptionTranslator()
            .translate("close", RpcUriUtils.sanitize(request.getUriString(), auth), e);
      }
    }
  }
コード例 #4
0
  protected RpcResponse doExecute(RpcRequest request) {
    Connection c = null;
    AccessVerifyConnectionSpec auth = null;
    try {
      try {
        request = validateRequest(request);
        RpcHost host = request.getHost();
        auth = AccessVerifyConnectionSpec.create(request.getCredentials().toString());
        c = this.connectionFactory.getConnection(host, auth);
      } catch (RpcException e) {
        if (getRpcListener() != null) getRpcListener().onRpc(new RpcEvent(request, e));
        throw getExceptionTranslator()
            .translate("open", RpcUriUtils.sanitize(request.getURI(), auth), e);
      }
      try {
        logger.debug("executing {}", RpcUriUtils.sanitize(request.getURI(), auth));

        RpcResponse response = c.send(request);

        logger.debug("received  {}", RpcUriUtils.sanitize(request.getURI(), auth));

        if (getRpcListener() != null) getRpcListener().onRpc(new RpcEvent(request, response));

        return response;
      } catch (RpcException e) {
        if (getRpcListener() != null) getRpcListener().onRpc(new RpcEvent(request, e));
        throw getExceptionTranslator()
            .translate("send", RpcUriUtils.sanitize(request.getURI(), auth), e);
      }
    } catch (DataAccessException e) {
      logger.error("error in  " + RpcUriUtils.sanitize(request.getURI(), auth), e);
      throw e;
    } finally {
      try {
        if (c != null) c.close();
      } catch (RpcException e) {
        if (getRpcListener() != null) getRpcListener().onRpc(new RpcEvent(request, e));
        throw getExceptionTranslator()
            .translate("close", RpcUriUtils.sanitize(request.getURI(), auth), e);
      }
    }
  }