Search in sources :

Example 1 with Message

use of com.biglybt.pif.messaging.Message in project BiglyBT by BiglySoftware.

the class IncomingMessageQueueImpl method registerListenerSupport.

private void registerListenerSupport(final IncomingMessageQueueListener listener, final boolean is_priority) {
    com.biglybt.core.networkmanager.IncomingMessageQueue.MessageQueueListener core_listener = new com.biglybt.core.networkmanager.IncomingMessageQueue.MessageQueueListener() {

        @Override
        public boolean messageReceived(com.biglybt.core.peermanager.messaging.Message message) {
            if (message instanceof MessageAdapter) {
                // so just use original plugin message...i.e. unwrap out of MessageAdapter
                return listener.messageReceived(((MessageAdapter) message).getPluginMessage());
            }
            if (message instanceof BTMessage) {
                return listener.messageReceived(BTMessageManager.wrapCoreMessage((BTMessage) message));
            } else {
                return listener.messageReceived(new MessageAdapter(message));
            }
        }

        @Override
        public void protocolBytesReceived(int byte_count) {
            listener.bytesReceived(byte_count);
        }

        @Override
        public void dataBytesReceived(int byte_count) {
            listener.bytesReceived(byte_count);
        }

        @Override
        public boolean isPriority() {
            return (is_priority);
        }
    };
    // save this mapping for later
    registrations.put(listener, core_listener);
    core_queue.registerQueueListener(core_listener);
}
Also used : MessageAdapter(com.biglybt.pifimpl.local.messaging.MessageAdapter) BTMessage(com.biglybt.core.peermanager.messaging.bittorrent.BTMessage) Message(com.biglybt.pif.messaging.Message) IncomingMessageQueue(com.biglybt.pif.network.IncomingMessageQueue) IncomingMessageQueueListener(com.biglybt.pif.network.IncomingMessageQueueListener) BTMessage(com.biglybt.core.peermanager.messaging.bittorrent.BTMessage)

Example 2 with Message

use of com.biglybt.pif.messaging.Message in project BiglyBT by BiglySoftware.

the class OutgoingMessageQueueImpl method registerListener.

@Override
public void registerListener(final OutgoingMessageQueueListener listener) {
    com.biglybt.core.networkmanager.OutgoingMessageQueue.MessageQueueListener core_listener = new com.biglybt.core.networkmanager.OutgoingMessageQueue.MessageQueueListener() {

        @Override
        public boolean messageAdded(com.biglybt.core.peermanager.messaging.Message message) {
            if (message instanceof MessageAdapter) {
                // so just use original plugin message...i.e. unwrap out of MessageAdapter
                return listener.messageAdded(((MessageAdapter) message).getPluginMessage());
            }
            // message originally created by core
            return listener.messageAdded(new MessageAdapter(message));
        }

        @Override
        public void messageQueued(com.biglybt.core.peermanager.messaging.Message message) {
        /*nothing*/
        }

        @Override
        public void messageRemoved(com.biglybt.core.peermanager.messaging.Message message) {
        /*nothing*/
        }

        @Override
        public void messageSent(com.biglybt.core.peermanager.messaging.Message message) {
            if (message instanceof MessageAdapter) {
                // the message must have been originally created by plugin encoder and wrapped
                // so just use original plugin message...i.e. unwrap out of MessageAdapter
                listener.messageSent(((MessageAdapter) message).getPluginMessage());
                return;
            }
            // message originally created by core
            listener.messageSent(new MessageAdapter(message));
        }

        @Override
        public void protocolBytesSent(int byte_count) {
            listener.bytesSent(byte_count);
        }

        @Override
        public void dataBytesSent(int byte_count) {
            listener.bytesSent(byte_count);
        }

        @Override
        public void flush() {
        }
    };
    // save this mapping for later
    registrations.put(listener, core_listener);
    core_queue.registerQueueListener(core_listener);
}
Also used : MessageAdapter(com.biglybt.pifimpl.local.messaging.MessageAdapter) Message(com.biglybt.pif.messaging.Message) OutgoingMessageQueue(com.biglybt.pif.network.OutgoingMessageQueue) OutgoingMessageQueueListener(com.biglybt.pif.network.OutgoingMessageQueueListener)

Example 3 with Message

use of com.biglybt.pif.messaging.Message in project BiglyBT by BiglySoftware.

the class MessageStreamEncoderAdapter method encodeMessage.

@Override
public com.biglybt.core.networkmanager.RawMessage[] encodeMessage(com.biglybt.core.peermanager.messaging.Message message) {
    Message plug_msg;
    if (message instanceof MessageAdapter) {
        // original message created by plugin, unwrap
        plug_msg = ((MessageAdapter) message).getPluginMessage();
    } else {
        // core created
        plug_msg = new MessageAdapter(message);
    }
    RawMessage raw_plug = plug_encoder.encodeMessage(plug_msg);
    return new com.biglybt.core.networkmanager.RawMessage[] { new RawMessageAdapter(raw_plug) };
}
Also used : RawMessageAdapter(com.biglybt.pifimpl.local.network.RawMessageAdapter) Message(com.biglybt.pif.messaging.Message) RawMessage(com.biglybt.pif.network.RawMessage) RawMessageAdapter(com.biglybt.pifimpl.local.network.RawMessageAdapter) RawMessage(com.biglybt.pif.network.RawMessage)

Example 4 with Message

use of com.biglybt.pif.messaging.Message in project BiglyBT by BiglySoftware.

the class PeerImpl method getSupportedMessages.

@Override
public Message[] getSupportedMessages() {
    com.biglybt.core.peermanager.messaging.Message[] core_msgs = delegate.getSupportedMessages();
    Message[] plug_msgs = new Message[core_msgs.length];
    for (int i = 0; i < core_msgs.length; i++) {
        plug_msgs[i] = new MessageAdapter(core_msgs[i]);
    }
    return plug_msgs;
}
Also used : MessageAdapter(com.biglybt.pifimpl.local.messaging.MessageAdapter) Message(com.biglybt.pif.messaging.Message)

Aggregations

Message (com.biglybt.pif.messaging.Message)4 MessageAdapter (com.biglybt.pifimpl.local.messaging.MessageAdapter)3 BTMessage (com.biglybt.core.peermanager.messaging.bittorrent.BTMessage)1 IncomingMessageQueue (com.biglybt.pif.network.IncomingMessageQueue)1 IncomingMessageQueueListener (com.biglybt.pif.network.IncomingMessageQueueListener)1 OutgoingMessageQueue (com.biglybt.pif.network.OutgoingMessageQueue)1 OutgoingMessageQueueListener (com.biglybt.pif.network.OutgoingMessageQueueListener)1 RawMessage (com.biglybt.pif.network.RawMessage)1 RawMessageAdapter (com.biglybt.pifimpl.local.network.RawMessageAdapter)1