
org.zbus.remoting.ClientEventAdaptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zbus-client Show documentation
Show all versions of zbus-client Show documentation
lightweight message queue, service bus
The newest version!
package org.zbus.remoting;
import java.io.IOException;
import org.zbus.logging.Logger;
import org.zbus.logging.LoggerFactory;
import org.zbus.remoting.callback.ConnectedCallback;
import org.zbus.remoting.callback.ErrorCallback;
import org.zbus.remoting.callback.MessageCallback;
import org.zbus.remoting.ticket.Ticket;
import org.zbus.remoting.ticket.TicketManager;
import org.zbus.remoting.znet.EventAdaptor;
import org.zbus.remoting.znet.Session;
public class ClientEventAdaptor extends EventAdaptor{
private static final Logger log = LoggerFactory.getLogger(ClientEventAdaptor.class);
private MessageCallback messageCallback;
private ErrorCallback errorCallback;
private ConnectedCallback connectedCallback;
@Override
public void onMessage(Object obj, Session sess) throws IOException {
Message msg = (Message)obj;
//先验证是否有Ticket处理
Ticket ticket = TicketManager.getTicket(msg.getMsgId());
if(ticket != null){
ticket.notifyResponse(msg);
TicketManager.removeTicket(msg.getMsgId());
return;
}
if(messageCallback != null){
this.messageCallback.onMessage(msg, sess);
return;
}
log.warn("!!!!!!!!!!!!!!!!!!!!!!!!!!Drop,%s", msg);
}
@Override
public void onException(Throwable e, Session sess) throws IOException {
if(e instanceof IOException && this.errorCallback != null){
this.errorCallback.onError((IOException)e, sess);
} else {
super.onException(e, sess);
}
}
@Override
public void onSessionConnected(Session sess) throws IOException {
super.onSessionConnected(sess);
log.info("Connected: "+sess);
if(this.connectedCallback != null){
this.connectedCallback.onConnected(sess);
}
}
public void setMessageCallback(MessageCallback messageCallback) {
this.messageCallback = messageCallback;
}
public void setErrorCallback(ErrorCallback errorCallback) {
this.errorCallback = errorCallback;
}
public void setConnectedCallback(ConnectedCallback connectedCallback) {
this.connectedCallback = connectedCallback;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy