use of me.matoosh.undernet.event.channel.ChannelErrorEvent in project UnderNet by itsMatoosh.
the class Router method onEventCalled.
// EVENTS
/**
* Called when the handled event is called.
*
* @param e
*/
@Override
public void onEventCalled(Event e) {
// Connection established.
if (e.getClass() == ChannelCreatedEvent.class) {
ChannelCreatedEvent establishedEvent = (ChannelCreatedEvent) e;
logger.debug("New connection established with: " + establishedEvent.other);
} else // Connection dropped.
if (e.getClass() == ChannelClosedEvent.class) {
ChannelClosedEvent droppedEvent = (ChannelClosedEvent) e;
} else // Connection error.
if (e.getClass() == ChannelErrorEvent.class) {
ChannelErrorEvent errorEvent = (ChannelErrorEvent) e;
// TODO: Handle the error.
} else if (e.getClass() == RouterStatusEvent.class) {
RouterStatusEvent statusEvent = (RouterStatusEvent) e;
switch(statusEvent.newStatus) {
case STOPPED:
onConnectionEnded();
break;
case STARTING:
break;
case STARTED:
break;
case STOPPING:
break;
}
// TODO: Handle the status change.
} else if (e.getClass() == RouterErrorEvent.class) {
onRouterError((RouterErrorEvent) e);
} else if (e.getClass() == ServerStatusEvent.class) {
ServerStatusEvent statusEvent = (ServerStatusEvent) e;
if (statusEvent.newStatus.equals(InterfaceStatus.STARTED)) {
// In this case client doesn't yet have to be started.
if (client.status.equals(InterfaceStatus.STARTED)) {
// Both parts of the router started successfully.
onRouterStarted();
}
} else if (statusEvent.newStatus.equals(InterfaceStatus.STOPPED)) {
if (client.status.equals(InterfaceStatus.STOPPED)) {
// Both parts of the router stopped successfully.
onRouterStopped();
}
}
} else if (e.getClass() == ClientStatusEvent.class) {
ClientStatusEvent statusEvent = (ClientStatusEvent) e;
if (statusEvent.newStatus.equals(InterfaceStatus.STARTED)) {
if (server.status.equals(InterfaceStatus.STARTED)) {
// Both parts of the router started succesfully.
onRouterStarted();
}
} else if (statusEvent.newStatus.equals(InterfaceStatus.STOPPED)) {
if (server.status.equals(InterfaceStatus.STOPPED)) {
// Both parts of the router stopped successfully.
onRouterStopped();
}
}
} else if (e.getClass() == ClientExceptionEvent.class) {
ClientExceptionEvent exceptionEvent = (ClientExceptionEvent) e;
logger.error("Exception occurred with the client, shutting down the router!", exceptionEvent.exception);
this.stop();
} else if (e.getClass() == ServerExceptionEvent.class) {
ServerExceptionEvent exceptionEvent = (ServerExceptionEvent) e;
logger.error("Exception occurred with the server, shutting down the router!", exceptionEvent.exception);
this.stop();
}
}
use of me.matoosh.undernet.event.channel.ChannelErrorEvent in project UnderNet by itsMatoosh.
the class ServerChannelInitializer method exceptionCaught.
/**
* Handle the {@link Throwable} by logging and closing the {@link Channel}. Sub-classes may override this.
*
* @param ctx
* @param cause
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
Server.logger.error("An error occured while initializing the connection from: " + ctx.channel().remoteAddress(), cause);
EventManager.callEvent(new ChannelErrorEvent(ctx.channel(), true, cause));
// Closing the connection.
ctx.close();
}
use of me.matoosh.undernet.event.channel.ChannelErrorEvent in project UnderNet by itsMatoosh.
the class ServerNetworkMessageHandler method exceptionCaught.
/**
* Calls {@link ChannelHandlerContext#fireExceptionCaught(Throwable)} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
* <p>
* Sub-classes may override this method to change behavior.
*
* @param ctx
* @param cause
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
// Logging the exception.
logger.error("Error with connection from: " + ctx.channel().remoteAddress(), cause);
EventManager.callEvent(new ChannelErrorEvent(ctx.channel(), true, cause));
// Closing the connection.
ctx.close();
}
use of me.matoosh.undernet.event.channel.ChannelErrorEvent in project UnderNet by itsMatoosh.
the class ClientChannelInitializer method exceptionCaught.
/**
* Handle the {@link Throwable} by logging and closing the {@link Channel}. Sub-classes may override this.
*
* @param ctx
* @param cause
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
Client.logger.error("An error occured while initializing the connection to: " + ctx.channel().remoteAddress(), cause);
EventManager.callEvent(new ChannelErrorEvent(ctx.channel(), false, cause));
// Closing the connection.
ctx.close();
}
use of me.matoosh.undernet.event.channel.ChannelErrorEvent in project UnderNet by itsMatoosh.
the class ClientNetworkMessageHandler method exceptionCaught.
/**
* Calls {@link ChannelHandlerContext#fireExceptionCaught(Throwable)} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
* <p>
* Sub-classes may override this method to change behavior.
*
* @param ctx
* @param cause
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
// Logging the exception.
logger.error("Error with connection to: " + ctx.channel().remoteAddress(), cause);
EventManager.callEvent(new ChannelErrorEvent(ctx.channel(), false, cause));
// Closing the connection.
ctx.close();
}
Aggregations