Search in sources :

Example 1 with Authority

use of com.generallycloud.baseio.container.authority.Authority in project baseio by generallycloud.

the class AbstractProductLine method pollMessage.

@Override
public void pollMessage(SocketSession session, ProtobaseFuture future, MQSessionAttachment attachment) {
    if (attachment.getConsumer() != null) {
        return;
    }
    Authority authority = ApplicationContextUtil.getAuthority(session);
    String queueName = authority.getUuid();
    // 来自终端类型
    context.addReceiver(queueName);
    ConsumerQueue consumerQueue = getConsumerQueue(queueName);
    Consumer consumer = new Consumer(consumerQueue, attachment, session, future, queueName);
    attachment.setConsumer(consumer);
    consumerQueue.offer(consumer);
}
Also used : Authority(com.generallycloud.baseio.container.authority.Authority)

Example 2 with Authority

use of com.generallycloud.baseio.container.authority.Authority in project baseio by generallycloud.

the class RTPClient method leaveRoom.

public boolean leaveRoom() throws RTPException {
    try {
        Authority authority = session.getAuthority();
        if (authority == null) {
            throw new RTPException("not login");
        }
        ProtobaseFuture future = session.request(RTPJoinRoomServlet.SERVICE_NAME, roomId);
        this.handle.onBreak(this, new MapMessage("", authority.getUuid()));
        return JmsUtil.isTrue(future);
    } catch (IOException e) {
        throw new RTPException(e.getMessage(), e);
    }
}
Also used : ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Authority(com.generallycloud.baseio.container.authority.Authority) RTPException(com.generallycloud.baseio.container.rtp.RTPException) MapMessage(com.generallycloud.baseio.container.jms.MapMessage) IOException(java.io.IOException)

Example 3 with Authority

use of com.generallycloud.baseio.container.authority.Authority in project baseio by generallycloud.

the class RTPClient method inviteCustomer.

public void inviteCustomer(String inviteUsername) throws RTPException {
    if (roomId == null) {
        throw new RTPException("none roomId,create room first");
    }
    Authority authority = session.getAuthority();
    if (authority == null) {
        throw new RTPException("not login");
    }
    MapMessage message = new MapMessage("msgId", inviteUsername);
    message.put("eventName", "invite");
    message.put("roomId", roomId);
    message.put("inviteUsername", authority.getUsername());
    try {
        producer.offer(message);
    } catch (MQException e) {
        throw new RTPException(e);
    }
    this.inviteUsername = inviteUsername;
}
Also used : MQException(com.generallycloud.baseio.container.jms.MQException) Authority(com.generallycloud.baseio.container.authority.Authority) RTPException(com.generallycloud.baseio.container.rtp.RTPException) MapMessage(com.generallycloud.baseio.container.jms.MapMessage)

Example 4 with Authority

use of com.generallycloud.baseio.container.authority.Authority in project baseio by generallycloud.

the class RTPClient method bindTCPSession.

public void bindTCPSession() throws IOException {
    if (connector == null) {
        throw new IllegalArgumentException("null udp connector");
    }
    Authority authority = session.getAuthority();
    if (authority == null) {
        throw new IllegalArgumentException("not login");
    }
    JSONObject json = new JSONObject();
    json.put("serviceName", RTPServerDPAcceptor.BIND_SESSION);
    json.put("username", authority.getUsername());
    json.put("password", authority.getPassword());
    final DatagramPacket packet = DatagramPacket.createSendPacket(json.toJSONString().getBytes(context.getEncoding()));
    final String BIND_SESSION_CALLBACK = RTPServerDPAcceptor.BIND_SESSION_CALLBACK;
    final Waiter<Integer> waiter = new Waiter<>();
    session.listen(BIND_SESSION_CALLBACK, new OnFuture() {

        @Override
        public void onResponse(SocketSession session, Future future) {
            waiter.setPayload(0);
        }
    });
    final byte[] shortWaiter = new byte[] {};
    ThreadUtil.execute(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                try {
                    connector.sendDatagramPacket(packet);
                } catch (IOException e) {
                    DebugUtil.debug(e);
                }
                if (waiter.isDnoe()) {
                    break;
                }
                synchronized (shortWaiter) {
                    try {
                        shortWaiter.wait(300);
                    } catch (InterruptedException e) {
                        break;
                    }
                }
            }
        }
    });
    if (waiter.await(3000)) {
        CloseUtil.close(connector);
        throw new ClosedChannelException("disconnected");
    }
}
Also used : ClosedChannelException(com.generallycloud.baseio.ClosedChannelException) Authority(com.generallycloud.baseio.container.authority.Authority) OnFuture(com.generallycloud.baseio.container.OnFuture) IOException(java.io.IOException) JSONObject(com.alibaba.fastjson.JSONObject) SocketSession(com.generallycloud.baseio.component.SocketSession) DatagramPacket(com.generallycloud.baseio.protocol.DatagramPacket) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) OnFuture(com.generallycloud.baseio.container.OnFuture) Waiter(com.generallycloud.baseio.concurrent.Waiter)

Example 5 with Authority

use of com.generallycloud.baseio.container.authority.Authority 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)

Aggregations

Authority (com.generallycloud.baseio.container.authority.Authority)5 IOException (java.io.IOException)3 JSONObject (com.alibaba.fastjson.JSONObject)2 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)2 MapMessage (com.generallycloud.baseio.container.jms.MapMessage)2 RTPException (com.generallycloud.baseio.container.rtp.RTPException)2 ClosedChannelException (com.generallycloud.baseio.ClosedChannelException)1 TimeoutException (com.generallycloud.baseio.TimeoutException)1 ParamedProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)1 SocketSession (com.generallycloud.baseio.component.SocketSession)1 Waiter (com.generallycloud.baseio.concurrent.Waiter)1 OnFuture (com.generallycloud.baseio.container.OnFuture)1 MQException (com.generallycloud.baseio.container.jms.MQException)1 DatagramPacket (com.generallycloud.baseio.protocol.DatagramPacket)1 Future (com.generallycloud.baseio.protocol.Future)1 HashMap (java.util.HashMap)1