/* ------------------------------------------------------------ */ public MessageImpl newMessage(Message associated) { MessageImpl message = _messagePool.poll(); if (message == null) message = new MessageImpl(this); message.incRef(); if (associated != null) message.setAssociated(associated); return message; }
/* ------------------------------------------------------------ */ public void deliver(Client from, String toChannel, Object data, String id) { MessageImpl message = _bayeux.newMessage(); message.put(Bayeux.CHANNEL_FIELD, toChannel); message.put(Bayeux.DATA_FIELD, data); if (id != null) message.put(Bayeux.ID_FIELD, id); Message m = _bayeux.extendSendBayeux(from, message); if (m != null) doDelivery(from, m); if (m instanceof MessageImpl) ((MessageImpl) m).decRef(); }
public MessageImpl getMessage(QName name) { MessageImpl res = null; if (this.messages == null) { this.messages = this.findAllMessages(this); } for (final MessageImpl msg : this.messages) { if ((msg.getQName().getLocalPart().equals(name.getLocalPart())) && (msg.getQName().getNamespaceURI().equals(name.getNamespaceURI()))) { res = msg; break; } } return res; }
@Override public void clearBody() throws JMSException { super.clearBody(); this.writeOnlyMessage = new WriteOnlyMessage(); this.readOnlyMessage = null; this.readMode = false; }
/* ------------------------------------------------------------ */ protected void doDelivery(Client from, final Message msg) { final Message message = _bayeux.extendSendClient(from, this, msg); if (message == null) return; MessageListener[] alisteners = null; synchronized (this) { if (_maxQueue < 0) { // No queue limit, so always queue the message ((MessageImpl) message).incRef(); _queue.addUnsafe(message); } else { // We have a queue limit, boolean queue; if (_queue.size() >= _maxQueue) { // We are over the limit, so consult listeners if (_qListeners != null && _qListeners.length > 0) { queue = true; for (QueueListener l : _qListeners) queue &= l.queueMaxed(from, this, message); } else queue = false; } else // we are under limit, so queue the messages. queue = true; // queue the message if we are meant to if (queue) { ((MessageImpl) message).incRef(); _queue.addUnsafe(message); } } // deliver synchronized if (_syncMListeners != null) for (MessageListener l : _syncMListeners) l.deliver(from, this, message); alisteners = _asyncMListeners; if (_batch == 0 && _responsesPending < 1 && _queue.size() > 0) { if (((MessageImpl) message).isLazy()) lazyResume(); else resume(); } } // deliver unsynchronized if (alisteners != null) for (MessageListener l : alisteners) l.deliver(from, this, message); }
public List<MessageImpl> findAllMessages(AbsItfDescription parent) { List<MessageImpl> messages = new ArrayList<MessageImpl>(); for (final AbsItfImport impt : (List<AbsItfImport>) parent.getImports()) { if (impt.getDescription() != null) { final AbsItfDescription absDesc = impt.getDescription(); if (absDesc instanceof DescriptionImpl) { messages.addAll(((DescriptionImpl) absDesc).getMessages()); } messages.addAll(findAllMessages(impt.getDescription())); } } for (final Include incl : this.includes) { if (incl.getDescription() != null) { final AbsItfDescription absDesc = incl.getDescription(); if (absDesc instanceof DescriptionImpl) { messages.addAll(((DescriptionImpl) absDesc).getMessages()); } messages.addAll(findAllMessages(incl.getDescription())); } } boolean find = false; for (final TDocumented part : this.model.getAnyTopLevelOptionalElement()) { // get messages if (part instanceof TMessage) { messages.add(new MessageImpl((TMessage) part, this)); find = true; } } if (!find) { Iterator<Object> it = this.model.getAny().iterator(); while (it.hasNext()) { Object part = it.next(); // get import if (part instanceof Element) { if ((((Element) part).getLocalName().equals("message")) && verifWSDL11Ns((((Element) part).getNamespaceURI()))) { try { if (reader == null) { reader = new WSDLReaderImpl(); } TMessage tMessage = MessageImpl.replaceDOMElementByTMessage(this, (Element) part, reader); it = this.model.getAny().iterator(); messages.add(new MessageImpl((TMessage) tMessage, this)); } catch (WSDLException e) { // do nothing } } } } } return messages; }
@Override public void sendMessageAsync(Message msg, Consumer<Message> callback) { checkVerification(); SelfInfo self = getJDA().getSelfInfo(); if (!checkPermission(self, Permission.MESSAGE_WRITE)) throw new PermissionException(Permission.MESSAGE_WRITE); ((MessageImpl) msg).setChannelId(id); AsyncMessageSender.getInstance(getJDA(), guild.getId()).enqueue(msg, false, callback); }
private void convertMessageProperties( final javax.jms.Message message, final MessageImpl replacementMessage) throws JMSException { Enumeration propertyNames = message.getPropertyNames(); while (propertyNames.hasMoreElements()) { String propertyName = String.valueOf(propertyNames.nextElement()); // TODO: Shouldn't need to check for JMS properties here as don't think getPropertyNames() // should return them if (!propertyName.startsWith("JMSX_")) { Object value = message.getObjectProperty(propertyName); replacementMessage.setObjectProperty(propertyName, value); } } replacementMessage.setJMSDeliveryMode(message.getJMSDeliveryMode()); if (message.getJMSReplyTo() != null) { replacementMessage.setJMSReplyTo(message.getJMSReplyTo()); } replacementMessage.setJMSType(message.getJMSType()); replacementMessage.setJMSCorrelationID(message.getJMSCorrelationID()); }
@Override public PubSubProtocol.Message generateHedwigMessage() throws JMSException { PubSubProtocol.Message.Builder builder = PubSubProtocol.Message.newBuilder(); super.populateBuilderWithHeaders(builder); // Now set body and type. try { builder.setBody(ByteString.copyFrom(getPayloadData())); } catch (IOException e) { JMSException ex = new JMSException("Unable to read message data .. " + e); ex.setLinkedException(e); throw ex; } return builder.build(); }
/* ------------------------------------------------------------ */ public void recycleMessage(MessageImpl message) { message.clear(); _messagePool.offer(message); }
/* ------------------------------------------------------------ */ public MessageImpl newMessage() { MessageImpl message = _messagePool.poll(); if (message == null) message = new MessageImpl(this); message.incRef(); return message; }
protected synchronized void deliverInternal(ChannelImpl channel, Message[] msgs) { if (isLocal()) { // local clients must have a listener ArrayList<Message> list = new ArrayList<Message>(); for (int i = 0; msgs != null && i < msgs.length; i++) { // dont deliver to ourselves if (this != msgs[i].getClient()) list.add(msgs[i]); } if (getListener() != null && list.size() > 0) { getListener().deliver(list.toArray(new Message[0])); } } else { for (int i = 0; msgs != null && i < msgs.length; i++) { MessageImpl message = (MessageImpl) msgs[i]; if (this == message.getClient()) { // dont deliver to ourself continue; } // we are not implementing forever responses, if the client is connected // then we will fire off the message // first we check to see if we have any existing connections we can piggy back on CometEvent event = events.poll(); boolean delivered = false; // TODO TODO - check on thread safety, for writing and for getting last request. if (event != null) { synchronized (event) { RequestBase rq = (RequestBase) event.getHttpServletRequest().getAttribute(RequestBase.LAST_REQ_ATTR); if (rq != null) { Map map = new HashMap(); try { map.put(Bayeux.CHANNEL_FIELD, message.getChannel().getId()); map.put(Bayeux.DATA_FIELD, message); JSONObject json = new JSONObject(map); if (log.isDebugEnabled()) { log.debug( "Message instantly delivered to remote client[" + this + "] message:" + json); } rq.addToDeliveryQueue(this, json); // deliver the batch if (i == (msgs.length - 1)) { rq.deliver(event, this); event.close(); // todo, figure out a better way, this means only one message gets // delivered removeCometEvent(event); // and delivered instantly } delivered = true; } catch (Exception x) { log.error(x); } } } } if (!delivered) { if (log.isDebugEnabled()) { log.debug("Message added to queue for remote client[" + this + "] message:" + message); } // queue the message for the next round messages.add(message); } } } }