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);
}
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);
}
}
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;
}
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");
}
}
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());
}
}
Aggregations