@Override public MessagingChannel newMessagingChannel(String id, String uri) { try { MessagingChannel channel = newMessagingChannel(id, new URI(uri)); if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; } catch (URISyntaxException e) { throw new IllegalArgumentException("Bad uri: " + uri, e); } } }
@Override public void onResult(ResultEvent event) { subscriptionId = (String)event.getResult(); channel.addConsumer(consumer); }
@Override public void onResult(ResultEvent event) { channel.removeConsumer(consumer); subscriptionId = null; }
public ResponseMessageFuture publish(Object message, ResponseListener...listeners) { PublishMessage publishMessage = new PublishMessage(destination, topic, message); publishMessage.getHeaders().putAll(defaultHeaders); return channel.send(publishMessage, listeners); }
/** * Called by {@link org.granite.client.tide.Identity} after session has expired */ public void sessionExpired() { log.info("Application session expired"); logoutState.sessionExpired(); context.getEventBus().raiseEvent(context, SESSION_EXPIRED); context.getEventBus().raiseEvent(context, LOGOUT); remotingChannel.logout(false); for (MessagingChannel messagingChannel : messagingChannelsByType.values()) messagingChannel.logout(false); sessionId = null; if (remotingChannel instanceof SessionAwareChannel) ((SessionAwareChannel)remotingChannel).setSessionId(null); for (MessagingChannel messagingChannel : messagingChannelsByType.values()) messagingChannel.setSessionId(null); }
/** * Return a messaging channel for the specified type * @param channelType channel type * @return messaging channel * @see org.granite.client.messaging.channel.ChannelType */ public MessagingChannel getMessagingChannel(String channelType) { MessagingChannel messagingChannel = messagingChannelsByType.get(channelType); if (messagingChannel != null) return messagingChannel; messagingChannel = channelFactory.newMessagingChannel(channelType, channelType + "amf", serverApp); messagingChannel.setSessionId(sessionId); setupChannel(messagingChannel); messagingChannelsByType.put(channelType, messagingChannel); return messagingChannel; }
/** * Implementation of login * Should not be called directly, called by {@link org.granite.client.tide.Identity#login} * * @param username user name * @param password password */ public void login(String username, String password) { remotingChannel.setCredentials(new UsernamePasswordCredentials(username, password)); for (MessagingChannel messagingChannel : messagingChannelsByType.values()) messagingChannel.setCredentials(new UsernamePasswordCredentials(username, password)); }
messagingChannel.logout();
/** * Publish a message on the channel * @param message message (any object or String) * @param listeners array of listeners that will be notified when the message is delivered * @return future triggered when the message is delivered */ public ResponseMessageFuture publish(Object message, ResponseListener...listeners) { PublishMessage publishMessage = new PublishMessage(destination, topic, message); publishMessage.getHeaders().putAll(defaultHeaders); return channel.send(publishMessage, listeners); }
messagingChannel.setSessionId(sessionId);
/** * Implementation of login using a specific charset for username/password encoding * Should not be called directly, called by {@link org.granite.client.tide.Identity#login} * * @param username user name * @param password password * @param charset charset used for encoding */ public void login(String username, String password, Charset charset) { remotingChannel.setCredentials(new UsernamePasswordCredentials(username, password, charset)); for (MessagingChannel messagingChannel : messagingChannelsByType.values()) messagingChannel.setCredentials(new UsernamePasswordCredentials(username, password, charset)); }
/** * Publish a message on the channel * @param message message (any object or String) * @param listeners array of listeners that will be notified when the message is delivered * @return future triggered when the message is delivered */ public ResponseMessageFuture publish(Object message, ResponseListener...listeners) { PublishMessage publishMessage = new PublishMessage(destination, topic, message); publishMessage.getHeaders().putAll(defaultHeaders); return channel.send(publishMessage, listeners); }
/** * Set default time to live on all channels * @param timeToLive time to live in milliseconds */ public void setDefaultTimeToLive(long timeToLive) { defaultTimeToLive = timeToLive; if (channelFactory != null) channelFactory.setDefaultTimeToLive(timeToLive); for (MessagingChannel messagingChannel : messagingChannelsByType.values()) messagingChannel.setDefaultTimeToLive(timeToLive); if (remotingChannel != null) remotingChannel.setDefaultTimeToLive(timeToLive); }
@Override public void onResult(ResultEvent event) { channel.removeConsumer(consumer); for (TopicSubscriptionListener subscriptionListener : subscriptionListeners.keySet()) subscriptionListener.onUnsubscriptionSuccess(Consumer.this, event, subscriptionId); subscriptionId = null; }
@Override public void onResult(ResultEvent event) { subscriptionId = (String)event.getResult(); channel.addConsumer(consumer); for (TopicSubscriptionListener subscriptionListener : subscriptionListeners.keySet()) subscriptionListener.onSubscriptionSuccess(Consumer.this, event, subscriptionId); }
/** * Callback called when a remoting fault is received * @param event fault event * @param emsg fault message */ public void onFaultEvent(FaultEvent event, FaultMessage emsg) { if (sessionExpirationFuture != null) sessionExpirationFuture.cancel(false); String oldSessionId = sessionId; sessionId = (String)event.getMessage().getHeader(SESSION_ID_TAG); if (sessionId != null) { long serverTime = (Long)event.getMessage().getHeader(SERVER_TIME_TAG); int sessionExpirationDelay = (Integer)event.getMessage().getHeader(SESSION_EXP_TAG); rescheduleSessionExpirationTask(serverTime, sessionExpirationDelay); } if (sessionId == null || !sessionId.equals(oldSessionId)) log.info("Received new sessionId %s", sessionId); if (oldSessionId != null || sessionId != null) { for (MessagingChannel messagingChannel : messagingChannelsByType.values()) messagingChannel.setSessionId(sessionId); } if (emsg != null && emsg.getCode().equals(Code.SERVER_CALL_FAILED)) status.setConnected(false); }
public ResponseMessageFuture publish(Object message, Map<String, Object> headers, ResponseListener...listeners) { PublishMessage publishMessage = new PublishMessage(destination, topic, message); publishMessage.getHeaders().putAll(defaultHeaders); publishMessage.getHeaders().putAll(headers); return channel.send(publishMessage, listeners); } }
@Override public MessagingChannel newMessagingChannel(String channelType, String id, URI uri) { Transport transport = getMessagingTransport(channelType); if (transport == null) throw new RuntimeException("No transport defined for channel type " + channelType + ", start the ChannelFactory first"); if (!transport.isStarted() && !transport.start()) throw new TransportException("Could not start messaging transport: " + transport); MessagingCodec<Message[]> codec = newMessagingCodec(Message[].class); for (ChannelBuilder builder : ServiceLoader.load(ChannelBuilder.class)) { MessagingChannel channel = builder.buildMessagingChannel(channelType, id, uri, transport, codec); if (channel != null) { if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; } } MessagingChannel channel = defaultChannelBuilder.buildMessagingChannel(channelType, id, uri, transport, codec); if (channel == null) throw new RuntimeException("Could not build channel for type " + channelType + " and uri " + uri); if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; }
@Override public void onResult(ResultEvent event) { channel.removeConsumer(consumer); for (TopicSubscriptionListener subscriptionListener : subscriptionListeners.keySet()) subscriptionListener.onUnsubscriptionSuccess(Consumer.this, event, subscriptionId); subscriptionId = null; }
@Override public void onResult(ResultEvent event) { subscriptionId = (String)event.getResult(); channel.addConsumer(consumer); for (TopicSubscriptionListener subscriptionListener : subscriptionListeners.keySet()) subscriptionListener.onSubscriptionSuccess(Consumer.this, event, subscriptionId); }