Example #1
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;
 }
Example #2
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;
  }
Example #3
0
 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;
 }