Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
    public void fireProcess(ByteBuffer message) {
        for (ITransportHandlerListener<T> l : transportHandlerListener) {
            // TODO: flip() erases the contents of the message if
            // it was already flipped or just created...
            // In other words: This method expects that the byte buffer
            // is not fully prepared
            message.flip();
            l.process(message);
        }
    }
    
    public void fireProcess(T m) {
        for (ITransportHandlerListener<T> l : transportHandlerListener) {
            l.process(m);
        }        
    }
    public void fireProcess(String[] message) {
        for (ITransportHandlerListener<T> l : transportHandlerListener) {
            l.process(message);
        }
    }

The fireProcess methods can be used with ByteBuffers and String-Arrays or with a Generic. In the latter case, the corresponding ProtocolHandler must read this type, else a class cast exception will be thrown.

An example to the use fireProcess-Methods can be found in the RabbitMQ transport handler:

Code Block
languagejava
    @Override
    public void processInOpen() throws IOException {
        internalOpen();
        // Create Consumer
        boolean autoAck = false;
        channel.basicConsume(queueName, autoAck, consumerTag,
                new DefaultConsumer(channel) {
                    @Override
                    public void handleDelivery(
                            String consumerTag,
                            com.rabbitmq.client.Envelope envelope,
                            com.rabbitmq.client.AMQP.BasicProperties properties,
                            byte[] body) throws IOException {
//                        String routingKey = envelope.getRoutingKey();
//                        String contentType = properties.getContentType();
                        long deliveryTag = envelope.getDeliveryTag();
                        try{
                            ByteBuffer wrapped = ByteBuffer.wrap(body);
                            wrapped.position(wrapped.limit());
                            fireProcess(wrapped);
          public void fireOnConnect(ITransportHandler handler) {
               }catch(Exception e){
                            e.printStackTrace();
             for (ITransportHandlerListener<T> l : transportHandlerListener) {
      }
      l.onConnect(handler);
        }
    }
    public void fireOnDisconnect(ITransportHandler handler) {
channel.basicAck(deliveryTag, false);
           for (ITransportHandlerListener<T> l : transportHandlerListener) {
    };
        l.onDisonnect(handler);
        });
    }

Here you can see, that every source type needs a special handling for sending. Here e.g. a callback object (DefaultConsumer) is defined in RabbitMQ that calls fireProcess.

The fireProcess methods can be used with ByteBuffers and String-Arrays or with a Generic. In the latter case, the corresponding ProtocolHandler must read this type, else a class cast exception will be thrown. Two additional methods are used to inform listener about connection states (connect and disconnect)

...

These methode are defined in the interface ITransportHandlerListener that is implemented by IProtocolHandler, the basic interface for ProtocolHandler.

 

Registering the handler

Odysseus is OSGi based and all the handler are implemented as declartive services.

...