Package org.activeio

Examples of org.activeio.Packet


            if( requestListener ==null )
                throw new IOException("The RequestListener has not been set.");

            PacketData data = new PacketData(packet);
            short requestId = data.readShort();           
            Packet reponse = requestListener.onRequest(packet);

            // Send the response...
            Packet header = createHeaderPacket(RESPONSE, requestId);       
            Packet rc = AppendedPacket.join(header, packet);       
            synchronized(writeMutex) {
                super.write(rc);
            }
        } catch (IOException e) {
            super.onPacketError(e);
View Full Code Here


       
        Short requestId = new Short(getNextRequestId());
        Slot responseSlot = new Slot();
        requestMap.put(requestId, responseSlot);
       
        Packet header = createHeaderPacket(REQUEST, requestId.shortValue());       
        Packet packet = AppendedPacket.join(header, request);
       
        synchronized(writeMutex) {
            super.write(packet);
        }
       
View Full Code Here

            }
        }
    }   
   
    public boolean readFromPacket(Packet packet) throws IOException {
        Packet dup = packet.duplicate();

        if( dup.remaining() < RECORD_HEADER_SIZE )
            return false;
        DataInputStream is = new DataInputStream(new PacketInputStream(dup));
        readHeader( is );
        if( dup.remaining() < payloadLength+RECORD_FOOTER_SIZE ) {
            return false;
        }
       
        // Set limit to create a slice of the payload.
        dup.limit(dup.position()+payloadLength);
        this.payload = dup.slice();       
      if( isChecksumingEnabled() ) {
          checksum(new DataInputStream(new PacketInputStream(payload)));
      }
     
      // restore the limit and seek to the footer.
        dup.limit(packet.limit());
        dup.position(dup.position()+payloadLength);
        readFooter(is);
       
        // If every thing went well.. advance the position of the orignal packet.
        packet.position(dup.position());
        dup.dispose();
        return true;       
    }
View Full Code Here

        String oldName = Thread.currentThread().getName();       
        Thread.currentThread().setName( synchChannel.toString() );       
        try {
          while (running.get()) {
              try {
                  Packet packet = synchChannel.read(500);
                  if( packet==null )
                      continue;   
                   
                    if( packet == EOSPacket.EOS_PACKET ) {
                        channelListener.onPacket(packet);
                        return;
                    }
                   
                    if( packet.hasRemaining() ) {
                        channelListener.onPacket(packet);
                    }
                   
              } catch (IOException e) {
                  channelListener.onPacketError(e);
View Full Code Here

       
        appendNode.setAppendOffset(offset);
       
        if( markLocation!=null ) {
            try {
                Packet packet = readPacket(markLocation);
                markLocation = Location.readFromPacket(packet);
            } catch (InvalidRecordLocationException e) {
                throw (IOException)new IOException(e.getMessage()).initCause(e);
            }
            updateMark(markLocation);
View Full Code Here

        }
       
    }

    private void storeState() throws IOException {
        Packet controlData = controlFile.getControlData();
        if( controlData.remaining() == 0 )
            return;
       
        DataOutput data = new DataOutputStream(new PacketOutputStream(controlData));

        data.writeInt(lastLogFileId);
View Full Code Here

        controlFile.store();
    }

    private void loadState() throws IOException {
        if( controlFile.load() ) {
            Packet controlData = controlFile.getControlData();
            if( controlData.remaining() == 0 )
                return;
           
            DataInput data = new DataInputStream(new PacketInputStream(controlData));
   
            lastLogFileId =data.readInt();
View Full Code Here

    public void onPacket(Packet packet) {
        if( packet == EOSPacket.EOS_PACKET ) {
            return;
        }
        try {
            Packet response = requestListener.onRequest(packet);
            next.write(response);
            next.flush();
        } catch (IOException e) {
            requestListener.onRquestError(e);
        }
View Full Code Here

                if( size2 > 0 )
                    size += size2;
              }
             
              ByteBuffer remaining = inputByteBuffer.slice();           
              Packet data = new ByteBufferPacket(((ByteBuffer)inputByteBuffer.flip()).slice());
              this.channelListener.onPacket( data );
                         
              // Keep the remaining buffer around to fill with data.
              inputByteBuffer = remaining;
             
View Full Code Here

            threadPool.execute(new Runnable() {
                public void run() {
                    try {
                        int c = 0;
                        while (c < packet.remaining()) {
                            Packet p = synchChannel.read(1000*5);
                            if( p==null ) {
                                continue;
                            }
                            if( p == EOSPacket.EOS_PACKET ) {
                                System.out.println("Peer disconnected.");
                                dispose();
                            }
                            c += p.remaining();
                        }
                        done.release();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
View Full Code Here

TOP

Related Classes of org.activeio.Packet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.