use of com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture in project baseio by generallycloud.
the class ConsumerOnFuture method onResponse.
@Override
public void onResponse(SocketSession session, Future future) {
ParamedProtobaseFuture f = (ParamedProtobaseFuture) future;
try {
Message message = messageDecoder.decode(f);
onMessage.onReceive(message);
} catch (MQException e) {
DebugUtil.debug(e);
}
}
use of com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture in project baseio by generallycloud.
the class FixedSession method request.
public ParamedProtobaseFuture request(String serviceName, String content, byte[] binary) throws IOException {
ParamedProtobaseFuture future = new ParamedProtobaseFutureImpl(context, serviceName);
if (!StringUtil.isNullOrBlank(content)) {
future.write(content);
}
if (binary != null) {
future.writeBinary(binary);
}
WaiterOnFuture onReadFuture = new WaiterOnFuture();
waiterListen(serviceName, onReadFuture);
session.flush(future);
// FIXME 连接丢失时叫醒我
if (onReadFuture.await(timeout)) {
CloseUtil.close(session);
throw new TimeoutException("timeout");
}
return (ParamedProtobaseFuture) onReadFuture.getReadFuture();
}
use of com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture in project baseio by generallycloud.
the class FixedSession method login4RES.
public RESMessage login4RES(String username, String password) {
try {
Map<String, Object> param = new HashMap<>();
param.put("username", username);
param.put("password", MD5Util.get32(password, context.getEncoding()));
String paramString = JSON.toJSONString(param);
ParamedProtobaseFuture future = request(ContainerConsotant.ACTION_LOGIN, paramString);
RESMessage message = RESMessageDecoder.decode(future.getReadText());
if (message.getCode() == 0) {
JSONObject o = (JSONObject) message.getData();
String className = o.getString("className");
Class<?> clazz = ClassUtil.forName(className);
Authority authority = (Authority) BeanUtil.map2Object(o, clazz);
setAuthority(authority);
}
return message;
} catch (Exception e) {
return new RESMessage(400, e.getMessage());
}
}
use of com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture in project baseio by generallycloud.
the class FixedSession method write.
public void write(String serviceName, String content, byte[] binary) throws IOException {
ParamedProtobaseFuture future = new ParamedProtobaseFutureImpl(context, serviceName);
if (!StringUtil.isNullOrBlank(content)) {
future.write(content);
}
if (binary != null) {
future.writeBinary(binary);
}
session.flush(future);
}
use of com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture in project baseio by generallycloud.
the class DefaultMessageBrowser method browser.
@Override
public Message browser(String messageId) throws MQException {
JSONObject param = new JSONObject();
param.put("messageId", messageId);
param.put("cmd", MQBrowserServlet.BROWSER);
ParamedProtobaseFuture future;
try {
future = session.request(SERVICE_NAME, param.toJSONString());
} catch (IOException e) {
throw new MQException(e.getMessage(), e);
}
return messageDecoder.decode(future);
}
Aggregations