com.github.mrstampy.kitchensync.message.inbound.pingpong.PingInboundMessageHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of KitchenSync Show documentation
Show all versions of KitchenSync Show documentation
KitchenSync - A Java Library for Distributed Communication
/*
* KitchenSync Java Library Copyright (C) 2014 Burton Alexander
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package com.github.mrstampy.kitchensync.message.inbound.pingpong;
import com.github.mrstampy.kitchensync.message.KiSyMessage;
import com.github.mrstampy.kitchensync.message.KiSyMessageCreator;
import com.github.mrstampy.kitchensync.message.KiSyMessageType;
import com.github.mrstampy.kitchensync.message.inbound.AbstractInboundKiSyMessageHandler;
import com.github.mrstampy.kitchensync.netty.channel.KiSyChannel;
/**
* The Class PingInboundMessageHandler creates a pong message response and sends
* it to the originator.
*
* @param
* the generic type
*/
public class PingInboundMessageHandler extends AbstractInboundKiSyMessageHandler {
private static final long serialVersionUID = -3848676913366352139L;
/*
* (non-Javadoc)
*
* @see
* com.github.mrstampy.kitchensync.message.inbound.KiSyInboundMesssageHandler
* #canHandleMessage(java.lang.Object)
*/
@Override
public boolean canHandleMessage(MSG message) {
if (!(message instanceof KiSyMessage)) return false;
KiSyMessage msg = (KiSyMessage) message;
return msg.isType(KiSyMessageType.PING);
}
/*
* (non-Javadoc)
*
* @see com.github.mrstampy.kitchensync.message.inbound.
* AbstractInboundKiSyMessageHandler#onReceive(java.lang.Object,
* com.github.mrstampy.kitchensync.netty.channel.KiSyChannel)
*/
@Override
protected void onReceive(MSG message, KiSyChannel channel) {
if (!(message instanceof KiSyMessage)) return;
KiSyMessage msg = (KiSyMessage) message;
KiSyMessage pong = KiSyMessageCreator.createPong(channel);
channel.send(pong, msg.getReturnAddress());
}
/*
* (non-Javadoc)
*
* @see
* com.github.mrstampy.kitchensync.message.inbound.KiSyInboundMesssageHandler
* #getExecutionOrder()
*/
@Override
public int getExecutionOrder() {
return DEFAULT_EXECUTION_ORDER;
}
}