
org.zbus.server.AdminHandler 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.server;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.zbus.remoting.Message;
import org.zbus.remoting.MessageHandler;
import org.zbus.remoting.znet.Session;
import org.zbus.server.mq.ReplyHelper;
public class AdminHandler implements MessageHandler {
private String adminToken = "";
private Map handlerMap = new ConcurrentHashMap();
public void registerHandler(String command, MessageHandler handler){
this.handlerMap.put(command, handler);
}
@Override
public void handleMessage(Message msg, Session sess) throws IOException {
if(!adminToken.equals("") && !adminToken.equals(msg.getToken())){
ReplyHelper.reply403(msg, sess);
return;
}
String cmd = msg.getHeadOrParam("cmd", "");
MessageHandler handler = this.handlerMap.get(cmd);
if(handler == null){
msg.setBody("Admin cmd=%s Not Found", cmd);
ReplyHelper.reply400(msg, sess);
return;
}
handler.handleMessage(msg, sess);
}
public String getAdminToken() {
return adminToken;
}
public void setAdminToken(String adminToken) {
this.adminToken = adminToken;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy