Search in sources :

Example 1 with ParamedProtobaseFuture

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);
    }
}
Also used : MQException(com.generallycloud.baseio.container.jms.MQException) OnMessage(com.generallycloud.baseio.container.jms.client.OnMessage) Message(com.generallycloud.baseio.container.jms.Message) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)

Example 2 with ParamedProtobaseFuture

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();
}
Also used : ParamedProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture) TimeoutException(com.generallycloud.baseio.TimeoutException)

Example 3 with ParamedProtobaseFuture

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());
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) Authority(com.generallycloud.baseio.container.authority.Authority) JSONObject(com.alibaba.fastjson.JSONObject) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture) IOException(java.io.IOException) TimeoutException(com.generallycloud.baseio.TimeoutException)

Example 4 with ParamedProtobaseFuture

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);
}
Also used : ParamedProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)

Example 5 with ParamedProtobaseFuture

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);
}
Also used : MQException(com.generallycloud.baseio.container.jms.MQException) JSONObject(com.alibaba.fastjson.JSONObject) IOException(java.io.IOException) ParamedProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)

Aggregations

ParamedProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)7 JSONObject (com.alibaba.fastjson.JSONObject)3 TimeoutException (com.generallycloud.baseio.TimeoutException)2 ParamedProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl)2 MQException (com.generallycloud.baseio.container.jms.MQException)2 IOException (java.io.IOException)2 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)1 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)1 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)1 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)1 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)1 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)1 SocketSession (com.generallycloud.baseio.component.SocketSession)1 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)1 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)1 FileReceiveUtil (com.generallycloud.baseio.container.FileReceiveUtil)1 FixedSession (com.generallycloud.baseio.container.FixedSession)1 OnFuture (com.generallycloud.baseio.container.OnFuture)1 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)1 Authority (com.generallycloud.baseio.container.authority.Authority)1