@Override
 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
   if (isRemote(ctx)) {
     broker.removeLocalSession(routeId);
   }
   ctx.fireChannelInactive();
 }
 @Override
 public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
   if (isRemote(ctx)) {
     byte[] data = getPayloadFromByteBuf(buffer);
     LOG.trace(
         "Read complete,send message to remote channel: "
             + routeId
             + ",message is "
             + new String(data));
     broker.sendRequest(new UscRemoteDataMessage(routeId, data, true));
     buffer.clear();
     return;
   }
   // propagate the data to rest of handlers in pipeline
   ctx.fireChannelReadComplete();
 }
Beispiel #3
0
 @Override
 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
   UscConnectionException ex = new UscConnectionException("The channel is closed.");
   UscRouteIdentifier routeId = ctx.channel().attr(UscPlugin.ROUTE_IDENTIFIER).get();
   if (routeId != null) {
     // this is a channel using remote channel
     if (broker == null) {
       broker = UscServiceUtils.getService(UscRouteBrokerService.class);
     }
     if (broker != null) {
       broker.removeLocalSession(routeId);
     } else {
       log.error(
           "Broker service is null! Can't check if it is remote channel message, failed to proccess this exception {}.",
           ex);
     }
     return;
   }
   throw ex;
 }
Beispiel #4
0
  @Override
  protected void channelRead0(ChannelHandlerContext ctx, UscException ex) throws Exception {
    log.trace("UscExceptionHandler channelRead0" + ex);

    final Throwable t = ex.getCause();
    Channel channel = ctx.channel();
    UscRouteIdentifier routeId = ctx.channel().attr(UscPlugin.ROUTE_IDENTIFIER).get();
    if (routeId != null) {
      // this is a channel using remote channel
      if (broker == null) {
        broker = UscServiceUtils.getService(UscRouteBrokerService.class);
      }
      if (broker != null) {
        broker.removeLocalSession(routeId);
      } else {
        log.error(
            "Broker service is null! Can't check if it is remote channel message, failed to proccess this exception {}.",
            ex);
      }
      return;
    }
    SettableFuture<UscSessionImpl> tmp = channel.attr(UscPlugin.SESSION).get();
    if (tmp != null) {
      UscSessionImpl session = tmp.get();
      UscChannelImpl connection = session.getChannel();

      // connection is down
      if (t instanceof UscConnectionException) {
        plugin.getConnectionManager().removeConnection(connection);
      } else if (t instanceof UscChannelException) {
        // TODO
        ;
      } else if (t instanceof UscSessionException) {
        connection.removeSession(session.getSessionId());
      }
    }

    throw ex;
  }
 private boolean isRemote(ChannelHandlerContext ctx) {
   routeId = ctx.channel().attr(UscPlugin.ROUTE_IDENTIFIER).get();
   if (routeId != null) {
     LOG.trace("UscRemoteDeviceHandler:Channel read finished for route id(" + routeId + ")");
     if (broker == null) {
       broker = UscServiceUtils.getService(UscRouteBrokerService.class);
     }
     if (broker != null) {
       if (broker.isLocalRemoteSession(routeId)) {
         return true;
       } else {
         LOG.debug(
             "It's not local to remote channel("
                 + routeId
                 + ") message, pass it to other handler");
       }
     } else {
       LOG.error(
           "Broker service is null! Can't check if it is remote channel message, and pass it to other handler.");
     }
   }
   return false;
 }