activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r379619 [8/30] - in /incubator/activemq/trunk: ./ activecluster/ activecluster/src/java/org/apache/activecluster/ activecluster/src/java/org/apache/activecluster/election/ activecluster/src/java/org/apache/activecluster/election/impl/ activ...
Date Tue, 21 Feb 2006 23:14:17 GMT
Modified: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/BytePacket.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/BytePacket.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/BytePacket.java (original)
+++ incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/BytePacket.java Tue Feb 21 15:12:56 2006
@@ -1,209 +1,209 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activeio.packet;
-
-import java.io.DataOutput;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.reflect.Constructor;
-
-
-/**
- * Provides a Packet implementation that is directly backed by a <code>byte</code>.
- * 
- * @version $Revision$
- */
-final public class BytePacket implements Packet {
-
-    private byte data;
-    private byte position;
-    private byte limit;
-
-    public BytePacket(byte data) {
-        this.data = data;
-        clear();
-    }
-
-    public int position() {
-        return position;
-    }
-
-    public void position(int position) {
-        this.position = (byte) position;
-    }
-
-    public int limit() {
-        return limit;
-    }
-
-    public void limit(int limit) {
-        this.limit = (byte) limit;
-    }
-
-    public void flip() {
-        limit(position());
-        position(0);
-    }
-
-    public int remaining() {
-        return limit() - position();
-    }
-
-    public void rewind() {
-        position(0);
-    }
-
-    public boolean hasRemaining() {
-        return remaining() > 0;
-    }
-
-    public void clear() {
-        position(0);
-        limit(capacity());
-    }
-
-    public int capacity() {
-        return 1;
-    }
-
-    public Packet slice() {
-        if( hasRemaining() )
-            return new BytePacket(data);
-        return EmptyPacket.EMPTY_PACKET;
-    }
-    
-    public Packet duplicate() {
-        BytePacket packet = new BytePacket(data);
-        packet.limit(limit());
-        packet.position(position());
-        return packet;
-    }
-    
-    public Object duplicate(ClassLoader cl) throws IOException {
-        try {
-            Class clazz = cl.loadClass(BytePacket.class.getName());
-            Constructor constructor = clazz.getConstructor(new Class[]{byte.class});
-            return constructor.newInstance(new Object[]{new Byte(data)});
-        } catch (Throwable e) {
-            throw (IOException)new IOException("Could not duplicate packet in a different classloader: "+e).initCause(e);
-        }
-    }
-
-    public void writeTo(OutputStream out) throws IOException {
-        if( hasRemaining() ) {
-            out.write(data);
-            position(1);
-        }
-    }
-
-    public void writeTo(DataOutput out) throws IOException {
-        if( hasRemaining() ) {
-            out.write(data);
-            position(1);
-        }
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#read()
-     */
-    public int read() {
-        if( !hasRemaining() )
-            return -1;
-        position(1);
-        return data & 0xff;
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#read(byte[], int, int)
-     */
-    public int read(byte[] data, int offset, int length) {
-        if( !hasRemaining() )
-            return -1;
-        
-        if( length > 0 ) {
-            data[offset] = this.data;
-            position(1);
-            return 1;
-        }
-        return 0;
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#write(int)
-     */
-    public boolean write(int data) {
-        if( !hasRemaining() )
-            return false;
-        
-        this.data = (byte) data; 
-        position(1);
-        return true;
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#write(byte[], int, int)
-     */
-    public int write(byte[] data, int offset, int length) {
-        if( !hasRemaining() )
-            return -1;
-
-        if( length > 0 ) {
-            this.data = data[offset] ;
-            position(1);
-            return 1;
-        }
-        return 0;
-    }
-
-    public ByteSequence asByteSequence() {
-        return null;
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#sliceAsBytes()
-     */
-    public byte[] sliceAsBytes() {
-        return null;
-    }
-    
-    /**
-     * @param dest
-     * @return the number of bytes read into the dest.
-     */
-    public int read(Packet dest) {
-        if( hasRemaining() ) {
-            dest.write(data);
-            position(1);
-            return 1;
-        }
-        return 0;
-    }
-    
-    public String toString() {
-        return "{position="+position()+",limit="+limit()+",capacity="+capacity()+"}";
-    }
-
-    public Object getAdapter(Class target) {
-        if( target.isAssignableFrom(getClass()) ) {
-            return this;
-        }
-        return null;
-    }
-    
-    public void dispose() {        
-    }
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activeio.packet;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+
+
+/**
+ * Provides a Packet implementation that is directly backed by a <code>byte</code>.
+ * 
+ * @version $Revision$
+ */
+final public class BytePacket implements Packet {
+
+    private byte data;
+    private byte position;
+    private byte limit;
+
+    public BytePacket(byte data) {
+        this.data = data;
+        clear();
+    }
+
+    public int position() {
+        return position;
+    }
+
+    public void position(int position) {
+        this.position = (byte) position;
+    }
+
+    public int limit() {
+        return limit;
+    }
+
+    public void limit(int limit) {
+        this.limit = (byte) limit;
+    }
+
+    public void flip() {
+        limit(position());
+        position(0);
+    }
+
+    public int remaining() {
+        return limit() - position();
+    }
+
+    public void rewind() {
+        position(0);
+    }
+
+    public boolean hasRemaining() {
+        return remaining() > 0;
+    }
+
+    public void clear() {
+        position(0);
+        limit(capacity());
+    }
+
+    public int capacity() {
+        return 1;
+    }
+
+    public Packet slice() {
+        if( hasRemaining() )
+            return new BytePacket(data);
+        return EmptyPacket.EMPTY_PACKET;
+    }
+    
+    public Packet duplicate() {
+        BytePacket packet = new BytePacket(data);
+        packet.limit(limit());
+        packet.position(position());
+        return packet;
+    }
+    
+    public Object duplicate(ClassLoader cl) throws IOException {
+        try {
+            Class clazz = cl.loadClass(BytePacket.class.getName());
+            Constructor constructor = clazz.getConstructor(new Class[]{byte.class});
+            return constructor.newInstance(new Object[]{new Byte(data)});
+        } catch (Throwable e) {
+            throw (IOException)new IOException("Could not duplicate packet in a different classloader: "+e).initCause(e);
+        }
+    }
+
+    public void writeTo(OutputStream out) throws IOException {
+        if( hasRemaining() ) {
+            out.write(data);
+            position(1);
+        }
+    }
+
+    public void writeTo(DataOutput out) throws IOException {
+        if( hasRemaining() ) {
+            out.write(data);
+            position(1);
+        }
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#read()
+     */
+    public int read() {
+        if( !hasRemaining() )
+            return -1;
+        position(1);
+        return data & 0xff;
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#read(byte[], int, int)
+     */
+    public int read(byte[] data, int offset, int length) {
+        if( !hasRemaining() )
+            return -1;
+        
+        if( length > 0 ) {
+            data[offset] = this.data;
+            position(1);
+            return 1;
+        }
+        return 0;
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#write(int)
+     */
+    public boolean write(int data) {
+        if( !hasRemaining() )
+            return false;
+        
+        this.data = (byte) data; 
+        position(1);
+        return true;
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#write(byte[], int, int)
+     */
+    public int write(byte[] data, int offset, int length) {
+        if( !hasRemaining() )
+            return -1;
+
+        if( length > 0 ) {
+            this.data = data[offset] ;
+            position(1);
+            return 1;
+        }
+        return 0;
+    }
+
+    public ByteSequence asByteSequence() {
+        return null;
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#sliceAsBytes()
+     */
+    public byte[] sliceAsBytes() {
+        return null;
+    }
+    
+    /**
+     * @param dest
+     * @return the number of bytes read into the dest.
+     */
+    public int read(Packet dest) {
+        if( hasRemaining() ) {
+            dest.write(data);
+            position(1);
+            return 1;
+        }
+        return 0;
+    }
+    
+    public String toString() {
+        return "{position="+position()+",limit="+limit()+",capacity="+capacity()+"}";
+    }
+
+    public Object getAdapter(Class target) {
+        if( target.isAssignableFrom(getClass()) ) {
+            return this;
+        }
+        return null;
+    }
+    
+    public void dispose() {        
+    }
 }

Propchange: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/BytePacket.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/ByteSequence.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/EOSPacket.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/EOSPacket.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/EOSPacket.java (original)
+++ incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/EOSPacket.java Tue Feb 21 15:12:56 2006
@@ -1,151 +1,151 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activeio.packet;
-
-import java.io.DataOutput;
-import java.io.IOException;
-import java.io.OutputStream;
-
-
-/**
- * Provides a Packet implementation that is used to represent the end of a stream.
- * 
- * @version $Revision$
- */
-final public class EOSPacket implements Packet {
-
-    static final public EOSPacket EOS_PACKET = new EOSPacket(); 
-    
-    private EOSPacket() {
-    }
-
-    public void writeTo(OutputStream out) throws IOException {
-    }
-    public void writeTo(DataOutput out) throws IOException {
-    }
-
-    public int position() {
-        return 1;
-    }
-
-    public void position(int position) {
-    }
-
-    public int limit() {
-        return 0;
-    }
-
-    public void limit(int limit) {
-    }
-
-    public void flip() {
-    }
-
-    public int remaining() {
-        return -1;
-    }
-
-    public void rewind() {
-    }
-
-    public boolean hasRemaining() {
-        return false;
-    }
-
-    public void clear() {
-    }
-
-    public int capacity() {
-        return 0;
-    }
-
-    public Packet slice() {
-        return this;
-    }
-    
-    public Packet duplicate() {
-        return this;               
-    }
-
-    public Object duplicate(ClassLoader cl) throws IOException {
-        try {
-            Class clazz = cl.loadClass(EOSPacket.class.getName());
-            return clazz.getField("EOS_PACKET").get(null);
-        } catch (Throwable e) {
-            throw (IOException)new IOException("Could not duplicate packet in a different classloader: "+e).initCause(e);
-        }
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#read()
-     */
-    public int read() {
-        return -1;
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#read(byte[], int, int)
-     */
-    public int read(byte[] data, int offset, int length) {
-        return -1;
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#write(int)
-     */
-    public boolean write(int data) {
-        return false;
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#write(byte[], int, int)
-     */
-    public int write(byte[] data, int offset, int length) {
-        return -1;
-    }
-    
-    public ByteSequence asByteSequence() {
-        return EmptyPacket.EMPTY_BYTE_SEQUENCE;
-    }
-
-    public byte[] sliceAsBytes() {
-        return EmptyPacket.EMPTY_BYTE_ARRAY;
-    }
-    
-    /**
-     * @param dest
-     * @return the number of bytes read into the dest.
-     */
-    public int read(Packet dest) {        
-	    return 0;
-    }    
-    
-    public String toString() {
-        return "{position="+position()+",limit="+limit()+",capacity="+capacity()+"}";
-    }
-
-    public Object getAdapter(Class target) {
-        if( target.isAssignableFrom(getClass()) ) {
-            return this;
-        }
-        return null;
-    }
-    
-    public void dispose() {        
-    }
-
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activeio.packet;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.OutputStream;
+
+
+/**
+ * Provides a Packet implementation that is used to represent the end of a stream.
+ * 
+ * @version $Revision$
+ */
+final public class EOSPacket implements Packet {
+
+    static final public EOSPacket EOS_PACKET = new EOSPacket(); 
+    
+    private EOSPacket() {
+    }
+
+    public void writeTo(OutputStream out) throws IOException {
+    }
+    public void writeTo(DataOutput out) throws IOException {
+    }
+
+    public int position() {
+        return 1;
+    }
+
+    public void position(int position) {
+    }
+
+    public int limit() {
+        return 0;
+    }
+
+    public void limit(int limit) {
+    }
+
+    public void flip() {
+    }
+
+    public int remaining() {
+        return -1;
+    }
+
+    public void rewind() {
+    }
+
+    public boolean hasRemaining() {
+        return false;
+    }
+
+    public void clear() {
+    }
+
+    public int capacity() {
+        return 0;
+    }
+
+    public Packet slice() {
+        return this;
+    }
+    
+    public Packet duplicate() {
+        return this;               
+    }
+
+    public Object duplicate(ClassLoader cl) throws IOException {
+        try {
+            Class clazz = cl.loadClass(EOSPacket.class.getName());
+            return clazz.getField("EOS_PACKET").get(null);
+        } catch (Throwable e) {
+            throw (IOException)new IOException("Could not duplicate packet in a different classloader: "+e).initCause(e);
+        }
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#read()
+     */
+    public int read() {
+        return -1;
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#read(byte[], int, int)
+     */
+    public int read(byte[] data, int offset, int length) {
+        return -1;
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#write(int)
+     */
+    public boolean write(int data) {
+        return false;
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#write(byte[], int, int)
+     */
+    public int write(byte[] data, int offset, int length) {
+        return -1;
+    }
+    
+    public ByteSequence asByteSequence() {
+        return EmptyPacket.EMPTY_BYTE_SEQUENCE;
+    }
+
+    public byte[] sliceAsBytes() {
+        return EmptyPacket.EMPTY_BYTE_ARRAY;
+    }
+    
+    /**
+     * @param dest
+     * @return the number of bytes read into the dest.
+     */
+    public int read(Packet dest) {        
+	    return 0;
+    }    
+    
+    public String toString() {
+        return "{position="+position()+",limit="+limit()+",capacity="+capacity()+"}";
+    }
+
+    public Object getAdapter(Class target) {
+        if( target.isAssignableFrom(getClass()) ) {
+            return this;
+        }
+        return null;
+    }
+    
+    public void dispose() {        
+    }
+
 }

Propchange: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/EOSPacket.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/EmptyPacket.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/EmptyPacket.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/EmptyPacket.java (original)
+++ incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/EmptyPacket.java Tue Feb 21 15:12:56 2006
@@ -1,153 +1,153 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activeio.packet;
-
-import java.io.DataOutput;
-import java.io.IOException;
-import java.io.OutputStream;
-
-
-/**
- * Provides a Packet implementation that is directly backed by a <code>byte[0]</code>.
- * 
- * @version $Revision$
- */
-final public class EmptyPacket implements Packet {
-
-    static final public EmptyPacket EMPTY_PACKET = new EmptyPacket(); 
-    static final byte EMPTY_BYTE_ARRAY[] = new byte[]{};
-    static final ByteSequence EMPTY_BYTE_SEQUENCE = new ByteSequence(EMPTY_BYTE_ARRAY,0,0);
-    
-    private EmptyPacket() {
-    }
-
-    public void writeTo(OutputStream out) throws IOException {
-    }
-    public void writeTo(DataOutput out) throws IOException {
-    }
-
-    public int position() {
-        return 0;
-    }
-
-    public void position(int position) {
-    }
-
-    public int limit() {
-        return 0;
-    }
-
-    public void limit(int limit) {
-    }
-
-    public void flip() {
-    }
-
-    public int remaining() {
-        return 0;
-    }
-
-    public void rewind() {
-    }
-
-    public boolean hasRemaining() {
-        return false;
-    }
-
-    public void clear() {
-    }
-
-    public int capacity() {
-        return 0;
-    }
-
-    public Packet slice() {
-        return this;
-    }
-    
-    public Packet duplicate() {
-        return this;               
-    }
-    
-    public Object duplicate(ClassLoader cl) throws IOException {
-        try {
-            Class clazz = cl.loadClass(EmptyPacket.class.getName());
-            return clazz.getField("EMPTY_PACKET").get(null);
-        } catch (Throwable e) {
-            throw (IOException)new IOException("Could not duplicate packet in a different classloader: "+e).initCause(e);
-        }
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#read()
-     */
-    public int read() {
-        return -1;
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#read(byte[], int, int)
-     */
-    public int read(byte[] data, int offset, int length) {
-        return -1;
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#write(int)
-     */
-    public boolean write(int data) {
-        return false;
-    }
-
-    /**
-     * @see org.apache.activeio.packet.Packet#write(byte[], int, int)
-     */
-    public int write(byte[] data, int offset, int length) {
-        return -1;
-    }
-    
-    public ByteSequence asByteSequence() {
-        return EMPTY_BYTE_SEQUENCE;
-    }
-
-    public byte[] sliceAsBytes() {
-        return EMPTY_BYTE_ARRAY;
-    }
-    
-    /**
-     * @param dest
-     * @return the number of bytes read into the dest.
-     */
-    public int read(Packet dest) {        
-	    return -1;
-    }    
-    
-    public String toString() {
-        return "{position="+position()+",limit="+limit()+",capacity="+capacity()+"}";
-    }
-
-    public Object getAdapter(Class target) {
-        if( target.isAssignableFrom(getClass()) ) {
-            return this;
-        }
-        return null;
-    }
-    
-    public void dispose() {        
-    }
-
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activeio.packet;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.OutputStream;
+
+
+/**
+ * Provides a Packet implementation that is directly backed by a <code>byte[0]</code>.
+ * 
+ * @version $Revision$
+ */
+final public class EmptyPacket implements Packet {
+
+    static final public EmptyPacket EMPTY_PACKET = new EmptyPacket(); 
+    static final byte EMPTY_BYTE_ARRAY[] = new byte[]{};
+    static final ByteSequence EMPTY_BYTE_SEQUENCE = new ByteSequence(EMPTY_BYTE_ARRAY,0,0);
+    
+    private EmptyPacket() {
+    }
+
+    public void writeTo(OutputStream out) throws IOException {
+    }
+    public void writeTo(DataOutput out) throws IOException {
+    }
+
+    public int position() {
+        return 0;
+    }
+
+    public void position(int position) {
+    }
+
+    public int limit() {
+        return 0;
+    }
+
+    public void limit(int limit) {
+    }
+
+    public void flip() {
+    }
+
+    public int remaining() {
+        return 0;
+    }
+
+    public void rewind() {
+    }
+
+    public boolean hasRemaining() {
+        return false;
+    }
+
+    public void clear() {
+    }
+
+    public int capacity() {
+        return 0;
+    }
+
+    public Packet slice() {
+        return this;
+    }
+    
+    public Packet duplicate() {
+        return this;               
+    }
+    
+    public Object duplicate(ClassLoader cl) throws IOException {
+        try {
+            Class clazz = cl.loadClass(EmptyPacket.class.getName());
+            return clazz.getField("EMPTY_PACKET").get(null);
+        } catch (Throwable e) {
+            throw (IOException)new IOException("Could not duplicate packet in a different classloader: "+e).initCause(e);
+        }
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#read()
+     */
+    public int read() {
+        return -1;
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#read(byte[], int, int)
+     */
+    public int read(byte[] data, int offset, int length) {
+        return -1;
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#write(int)
+     */
+    public boolean write(int data) {
+        return false;
+    }
+
+    /**
+     * @see org.apache.activeio.packet.Packet#write(byte[], int, int)
+     */
+    public int write(byte[] data, int offset, int length) {
+        return -1;
+    }
+    
+    public ByteSequence asByteSequence() {
+        return EMPTY_BYTE_SEQUENCE;
+    }
+
+    public byte[] sliceAsBytes() {
+        return EMPTY_BYTE_ARRAY;
+    }
+    
+    /**
+     * @param dest
+     * @return the number of bytes read into the dest.
+     */
+    public int read(Packet dest) {        
+	    return -1;
+    }    
+    
+    public String toString() {
+        return "{position="+position()+",limit="+limit()+",capacity="+capacity()+"}";
+    }
+
+    public Object getAdapter(Class target) {
+        if( target.isAssignableFrom(getClass()) ) {
+            return this;
+        }
+        return null;
+    }
+    
+    public void dispose() {        
+    }
+
 }

Propchange: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/EmptyPacket.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/FilterPacket.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/FilterPacket.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/FilterPacket.java (original)
+++ incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/FilterPacket.java Tue Feb 21 15:12:56 2006
@@ -1,137 +1,137 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activeio.packet;
-
-import java.io.DataOutput;
-import java.io.IOException;
-import java.io.OutputStream;
-
-
-/**
- * Provides a Packet implementation that filters operations to another packet.
- * 
- * Used to make it easier to augment the {@see #narrow(Class)}method.
- * 
- * @version $Revision$
- */
-public abstract class FilterPacket implements Packet {
-    final protected Packet next;
-
-    public FilterPacket(Packet next) {
-        this.next = next;
-    }
-
-    public ByteSequence asByteSequence() {
-        return next.asByteSequence();
-    }
-
-    public int capacity() {
-        return next.capacity();
-    }
-
-    public void clear() {
-        next.clear();
-    }
-
-    public void flip() {
-        next.flip();
-    }
-
-    public boolean hasRemaining() {
-        return next.hasRemaining();
-    }
-
-    public int limit() {
-        return next.limit();
-    }
-
-    public void limit(int limit) {
-        next.limit(limit);
-    }
-
-    public Object getAdapter(Class target) {
-        if( target.isAssignableFrom(getClass()) ) {
-            return this;
-        }
-        return next.getAdapter(target);
-    }
-
-    public int position() {
-        return next.position();
-    }
-
-    public void position(int position) {
-        next.position(position);
-    }
-
-    public int read() {
-        return next.read();
-    }
-
-    public int read(byte[] data, int offset, int length) {
-        return next.read(data, offset, length);
-    }
-
-    public int read(Packet dest) {
-        return next.read(dest);
-    }
-
-    public int remaining() {
-        return next.remaining();
-    }
-
-    public void rewind() {
-        next.rewind();
-    }
-
-    public byte[] sliceAsBytes() {
-        return next.sliceAsBytes();
-    }
-
-    public int write(byte[] data, int offset, int length) {
-        return next.write(data, offset, length);
-    }
-
-    public boolean write(int data) {
-        return next.write(data);
-    }
-
-    public void writeTo(OutputStream out) throws IOException {
-        next.writeTo(out);
-    }
-    public void writeTo(DataOutput out) throws IOException {
-        next.writeTo(out);
-    }
-
-    public Object duplicate(ClassLoader cl) throws IOException {
-        return next.duplicate(cl);
-    }
-
-    public Packet duplicate() {
-        return filter(next.duplicate());
-    }
-
-    public Packet slice() {
-        return filter(next.slice());
-    }
-    
-    public void dispose() {
-        next.dispose();
-    }
-
-    abstract public Packet filter(Packet packet);
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activeio.packet;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.OutputStream;
+
+
+/**
+ * Provides a Packet implementation that filters operations to another packet.
+ * 
+ * Used to make it easier to augment the {@see #narrow(Class)}method.
+ * 
+ * @version $Revision$
+ */
+public abstract class FilterPacket implements Packet {
+    final protected Packet next;
+
+    public FilterPacket(Packet next) {
+        this.next = next;
+    }
+
+    public ByteSequence asByteSequence() {
+        return next.asByteSequence();
+    }
+
+    public int capacity() {
+        return next.capacity();
+    }
+
+    public void clear() {
+        next.clear();
+    }
+
+    public void flip() {
+        next.flip();
+    }
+
+    public boolean hasRemaining() {
+        return next.hasRemaining();
+    }
+
+    public int limit() {
+        return next.limit();
+    }
+
+    public void limit(int limit) {
+        next.limit(limit);
+    }
+
+    public Object getAdapter(Class target) {
+        if( target.isAssignableFrom(getClass()) ) {
+            return this;
+        }
+        return next.getAdapter(target);
+    }
+
+    public int position() {
+        return next.position();
+    }
+
+    public void position(int position) {
+        next.position(position);
+    }
+
+    public int read() {
+        return next.read();
+    }
+
+    public int read(byte[] data, int offset, int length) {
+        return next.read(data, offset, length);
+    }
+
+    public int read(Packet dest) {
+        return next.read(dest);
+    }
+
+    public int remaining() {
+        return next.remaining();
+    }
+
+    public void rewind() {
+        next.rewind();
+    }
+
+    public byte[] sliceAsBytes() {
+        return next.sliceAsBytes();
+    }
+
+    public int write(byte[] data, int offset, int length) {
+        return next.write(data, offset, length);
+    }
+
+    public boolean write(int data) {
+        return next.write(data);
+    }
+
+    public void writeTo(OutputStream out) throws IOException {
+        next.writeTo(out);
+    }
+    public void writeTo(DataOutput out) throws IOException {
+        next.writeTo(out);
+    }
+
+    public Object duplicate(ClassLoader cl) throws IOException {
+        return next.duplicate(cl);
+    }
+
+    public Packet duplicate() {
+        return filter(next.duplicate());
+    }
+
+    public Packet slice() {
+        return filter(next.slice());
+    }
+    
+    public void dispose() {
+        next.dispose();
+    }
+
+    abstract public Packet filter(Packet packet);
 }

Propchange: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/FilterPacket.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/Packet.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/Packet.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/Packet.java (original)
+++ incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/Packet.java Tue Feb 21 15:12:56 2006
@@ -1,69 +1,69 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activeio.packet;
-
-import java.io.DataOutput;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import org.apache.activeio.Adaptable;
-
-/**
- * Provides a ByteBuffer like interface to work with IO channel packets of data.
- * 
- * @version $Revision$
- */
-public interface Packet extends Adaptable {
-    
-    public int position();
-    public void position(int position);
-    public int limit();
-    public void limit(int limit);
-    public void flip();
-    public int remaining();
-    public void rewind();
-    public boolean hasRemaining();
-    public void clear();
-    public Packet slice();
-    public Packet duplicate();
-    public Object duplicate(ClassLoader cl) throws IOException;
-    public int capacity();
-    public void dispose();
-    
-    public ByteSequence asByteSequence();
-    public byte[] sliceAsBytes();
-    
-    
-    /**
-     * Writes the remaing bytes in the packet to the output stream.
-     * 
-     * @param out
-     * @return
-     */
-    void writeTo(OutputStream out) throws IOException;   
-    void writeTo(DataOutput out) throws IOException;
-    
-    // To read data out of the packet.
-    public int read();
-    public int read(byte data[], int offset, int length);
-
-    // To write data into the packet.
-    public boolean write( int data );
-    public int write( byte data[], int offset, int length );
-    public int read(Packet dest);
-    
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activeio.packet;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.activeio.Adaptable;
+
+/**
+ * Provides a ByteBuffer like interface to work with IO channel packets of data.
+ * 
+ * @version $Revision$
+ */
+public interface Packet extends Adaptable {
+    
+    public int position();
+    public void position(int position);
+    public int limit();
+    public void limit(int limit);
+    public void flip();
+    public int remaining();
+    public void rewind();
+    public boolean hasRemaining();
+    public void clear();
+    public Packet slice();
+    public Packet duplicate();
+    public Object duplicate(ClassLoader cl) throws IOException;
+    public int capacity();
+    public void dispose();
+    
+    public ByteSequence asByteSequence();
+    public byte[] sliceAsBytes();
+    
+    
+    /**
+     * Writes the remaing bytes in the packet to the output stream.
+     * 
+     * @param out
+     * @return
+     */
+    void writeTo(OutputStream out) throws IOException;   
+    void writeTo(DataOutput out) throws IOException;
+    
+    // To read data out of the packet.
+    public int read();
+    public int read(byte data[], int offset, int length);
+
+    // To write data into the packet.
+    public boolean write( int data );
+    public int write( byte data[], int offset, int length );
+    public int read(Packet dest);
+    
+}

Propchange: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/Packet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/PacketData.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/PacketData.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/PacketData.java (original)
+++ incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/PacketData.java Tue Feb 21 15:12:56 2006
@@ -1,381 +1,381 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activeio.packet;
-
-import java.io.EOFException;
-import java.io.IOException;
-
-
-/**
- * Used to write and read primitives to and from a Packet.
- */
-final public class PacketData {
-
-    final private Packet packet;
-    private final boolean bigEndian;
-
-    public PacketData(Packet packet) {
-        this(packet, true);
-    }
-
-    public PacketData(Packet packet, boolean bigEndian) {
-        this.packet = packet;
-        this.bigEndian = bigEndian;
-    }
-
-    private static void spaceNeeded(Packet packet, int space) throws IOException {
-        if (packet.remaining() < space)
-            throw new EOFException("Not enough space left in the packet.");
-    }
-
-    public void readFully(byte[] b) throws IOException {
-        readFully(packet, b, 0, b.length);
-    }
-    
-    public static void readFully(Packet packet, byte[] b) throws IOException {
-        readFully(packet, b, 0, b.length);
-    }
-
-    public void readFully(byte[] b, int off, int len) throws IOException {
-        readFully(packet, b, off, len);
-    }
-    public static void readFully(Packet packet, byte[] b, int off, int len) throws IOException {
-        spaceNeeded(packet, len);
-        packet.read(b, off, len);
-    }
-
-    public int skipBytes(int n) throws IOException {
-        return skipBytes(packet, n);
-    }
-    public static int skipBytes(Packet packet, int n) throws IOException {
-        int rc = Math.min(n, packet.remaining());
-        packet.position(packet.position() + rc);
-        return rc;
-    }
-
-    public boolean readBoolean() throws IOException {
-        return readBoolean(packet);
-    }
-    public static boolean readBoolean(Packet packet) throws IOException {
-        spaceNeeded(packet, 1);
-        return packet.read() != 0;
-    }
-
-    public byte readByte() throws IOException {
-        return readByte(packet);
-    }
-    public static byte readByte(Packet packet) throws IOException {
-        spaceNeeded(packet, 1);
-        return (byte) packet.read();
-    }
-
-    public int readUnsignedByte() throws IOException {
-        return readUnsignedByte(packet);
-    }
-    public static int readUnsignedByte(Packet packet) throws IOException {
-        spaceNeeded(packet, 1);
-        return packet.read();
-    }
-
-    public short readShort() throws IOException {
-        if( bigEndian ) {
-            return readShortBig(packet);
-        } else {
-	        return readShortLittle(packet);
-        }        
-    }
-    public static short readShortBig(Packet packet) throws IOException {
-        spaceNeeded(packet, 2);
-        return (short) ((packet.read() << 8) + (packet.read() << 0));
-    }
-    public static short readShortLittle(Packet packet) throws IOException {
-        spaceNeeded(packet, 2);
-        return (short) ((packet.read() << 0) + (packet.read() << 8) );
-    }
-
-    public int readUnsignedShort() throws IOException {
-        if( bigEndian ) {
-            return readUnsignedShortBig(packet);
-        } else {
-	        return readUnsignedShortLittle(packet);
-        }        
-    }
-    public static int readUnsignedShortBig(Packet packet) throws IOException {
-        spaceNeeded(packet, 2);
-        return ((packet.read() << 8) + (packet.read() << 0));
-    }
-    public static int readUnsignedShortLittle(Packet packet) throws IOException {
-        spaceNeeded(packet, 2);
-        return ((packet.read() << 0) + (packet.read() << 8) );
-    }
-
-    public char readChar() throws IOException {
-        if( bigEndian ) {
-            return readCharBig(packet);
-        } else {
-	        return readCharLittle(packet);
-        }        
-    }
-    public static char readCharBig(Packet packet) throws IOException {
-        spaceNeeded(packet, 2);
-        return (char) ((packet.read() << 8) + (packet.read() << 0));
-    }
-    public static char readCharLittle(Packet packet) throws IOException {
-        spaceNeeded(packet, 2);
-        return (char) ((packet.read() << 0) + (packet.read() << 8) );
-    }
-
-    public int readInt() throws IOException {
-        if( bigEndian ) {
-	        return readIntBig(packet);
-        } else {
-	        return readIntLittle(packet);
-        }        
-    }    
-    public static int readIntBig(Packet packet) throws IOException {
-        spaceNeeded(packet, 4);
-        return ((packet.read() << 24) + 
-                (packet.read() << 16) + 
-                (packet.read() << 8) + 
-                (packet.read() << 0));
-    }    
-    public static int readIntLittle(Packet packet) throws IOException {
-        spaceNeeded(packet, 4);
-        return ((packet.read() << 0) +
-                (packet.read() << 8) + 
-                (packet.read() << 16) + 
-                (packet.read() << 24));
-    }    
-    
-    public long readLong() throws IOException {
-        if( bigEndian ) {
-	        return readLongBig(packet);
-        } else {
-	        return readLongLittle(packet);	                
-        }        
-    }
-    public static long readLongBig(Packet packet) throws IOException {
-        spaceNeeded(packet, 8);
-        return (((long) packet.read() << 56) + 
-                ((long) packet.read() << 48) + 
-                ((long) packet.read() << 40) + 
-                ((long) packet.read() << 32) + 
-                ((long) packet.read() << 24) + 
-                ((packet.read()) << 16) + 
-                ((packet.read()) << 8) + 
-                ((packet.read()) << 0));
-    }
-    public static long readLongLittle(Packet packet) throws IOException {
-        spaceNeeded(packet, 8);
-        return ((packet.read() << 0) +
-                (packet.read() << 8) + 
-                (packet.read() << 16) + 
-                ((long) packet.read() << 24) +
-                ((long) packet.read() << 32) + 
-                ((long) packet.read() << 40) + 
-                ((long) packet.read() << 48) + 
-                ((long) packet.read() << 56));                  
-    }
-    
-    public double readDouble() throws IOException {
-        return Double.longBitsToDouble(readLong());
-    }
-    public static double readDoubleBig(Packet packet) throws IOException {
-        return Double.longBitsToDouble(readLongBig(packet));
-    }
-    public static double readDoubleLittle(Packet packet) throws IOException {
-        return Double.longBitsToDouble(readLongLittle(packet));
-    }
-
-    public float readFloat() throws IOException {
-        return Float.intBitsToFloat(readInt());
-    }
-    public static float readFloatBig(Packet packet) throws IOException {
-        return Float.intBitsToFloat(readIntBig(packet));
-    }
-    public static float readFloatLittle(Packet packet) throws IOException {
-        return Float.intBitsToFloat(readIntLittle(packet));
-    }
-
-    public void write(int b) throws IOException {
-        write(packet, b);
-    }
-    public static void write(Packet packet, int b) throws IOException {
-        spaceNeeded(packet, 1);
-        packet.write(b);
-    }
-
-    public void write(byte[] b) throws IOException {
-        write(packet, b, 0, b.length);
-    }
-    public static void write(Packet packet, byte[] b) throws IOException {
-        write(packet, b, 0, b.length);
-    }
-
-    public void write(byte[] b, int off, int len) throws IOException {
-        write(packet, b, off, len);
-    }
-    public static void write(Packet packet, byte[] b, int off, int len) throws IOException {
-        spaceNeeded(packet, len);
-        packet.write(b, off, len);
-    }
-
-    public void writeBoolean(boolean v) throws IOException {
-        writeBoolean(packet, v);
-    }
-    public static void writeBoolean(Packet packet, boolean v) throws IOException {
-        spaceNeeded(packet, 1);
-        packet.write(v ? 1 : 0);
-    }
-
-    public void writeByte(int v) throws IOException {
-        writeByte(packet, v);
-    }
-    public static void writeByte(Packet packet, int v) throws IOException {
-        spaceNeeded(packet, 1);
-        packet.write(v);
-    }
-
-    public void writeShort(int v) throws IOException {
-        if (bigEndian) {
-	        writeShortBig(packet,v);
-	    } else {
-            writeShortLittle(packet,v);
-	    }
-    }
-    public static void writeShortBig(Packet packet, int v) throws IOException {
-        spaceNeeded(packet, 2);
-        packet.write((v >>> 8) & 0xFF);
-        packet.write((v >>> 0) & 0xFF);
-    }
-    public static void writeShortLittle(Packet packet, int v) throws IOException {
-        spaceNeeded(packet, 2);
-        packet.write((v >>> 0) & 0xFF);
-        packet.write((v >>> 8) & 0xFF);
-    }
-
-    public void writeChar(int v) throws IOException {
-        if (bigEndian) {
-            writeCharBig(packet, v);
-        } else {
-            writeCharLittle(packet, v);
-        }
-    }
-    public static void writeCharBig(Packet packet, int v) throws IOException {
-        spaceNeeded(packet, 2);
-        packet.write((v >>> 8) & 0xFF);
-        packet.write((v >>> 0) & 0xFF);
-    }
-    public static void writeCharLittle(Packet packet, int v) throws IOException {
-        spaceNeeded(packet, 2);
-        packet.write((v >>> 0) & 0xFF);
-        packet.write((v >>> 8) & 0xFF);
-    }
-
-    public void writeInt(int v) throws IOException {
-        if (bigEndian) {
-            writeIntBig(packet, v);
-        } else {
-            writeIntLittle(packet, v);
-        }
-    }
-    public static void writeIntBig(Packet packet, int v) throws IOException {
-        spaceNeeded(packet, 4);
-        packet.write((v >>> 24) & 0xFF);
-        packet.write((v >>> 16) & 0xFF);
-        packet.write((v >>> 8) & 0xFF);
-        packet.write((v >>> 0) & 0xFF);
-    }
-    public static void writeIntLittle(Packet packet, int v) throws IOException {
-        spaceNeeded(packet, 4);
-        packet.write((v >>> 0) & 0xFF);
-        packet.write((v >>> 8) & 0xFF);
-        packet.write((v >>> 16) & 0xFF);
-        packet.write((v >>> 24) & 0xFF);
-    }
-
-    public void writeLong(long v) throws IOException {
-        if (bigEndian) {
-            writeLongBig(packet, v);
-        } else {
-            writeLongLittle(packet, v);
-        }
-    }
-    public static void writeLongBig(Packet packet, long v) throws IOException {
-        spaceNeeded(packet, 8);
-        packet.write((int) (v >>> 56) & 0xFF);
-        packet.write((int) (v >>> 48) & 0xFF);
-        packet.write((int) (v >>> 40) & 0xFF);
-        packet.write((int) (v >>> 32) & 0xFF);
-        packet.write((int) (v >>> 24) & 0xFF);
-        packet.write((int) (v >>> 16) & 0xFF);
-        packet.write((int) (v >>> 8) & 0xFF);
-        packet.write((int) (v >>> 0) & 0xFF);
-    }
-    public static void writeLongLittle(Packet packet, long v) throws IOException {
-        spaceNeeded(packet, 8);
-        packet.write((int) (v >>> 0) & 0xFF);
-        packet.write((int) (v >>> 8) & 0xFF);
-        packet.write((int) (v >>> 16) & 0xFF);
-        packet.write((int) (v >>> 24) & 0xFF);
-        packet.write((int) (v >>> 32) & 0xFF);
-        packet.write((int) (v >>> 40) & 0xFF);
-        packet.write((int) (v >>> 48) & 0xFF);
-        packet.write((int) (v >>> 56) & 0xFF);
-    }
-    
-    public void writeDouble(double v) throws IOException {
-        writeLong(Double.doubleToLongBits(v));
-    }
-    public static void writeDoubleBig(Packet packet, double v) throws IOException {
-        writeLongBig(packet, Double.doubleToLongBits(v));
-    }
-    public static void writeDoubleLittle(Packet packet, double v) throws IOException {
-        writeLongLittle(packet, Double.doubleToLongBits(v));
-    }
-
-    public void writeFloat(float v) throws IOException {
-        writeInt(Float.floatToIntBits(v));
-    }
-    public static void writeFloatBig(Packet packet, float v) throws IOException {
-        writeIntBig(packet, Float.floatToIntBits(v));
-    }
-    public static void writeFloatLittle(Packet packet, float v) throws IOException {
-        writeIntLittle(packet, Float.floatToIntBits(v));
-    }
-    
-    public void writeRawDouble(double v) throws IOException {
-        writeLong(Double.doubleToRawLongBits(v));
-    }
-    public static void writeRawDoubleBig(Packet packet, double v) throws IOException {
-        writeLongBig(packet, Double.doubleToRawLongBits(v));
-    }
-    public static void writeRawDoubleLittle(Packet packet, double v) throws IOException {
-        writeLongLittle(packet, Double.doubleToRawLongBits(v));
-    }
-
-    public void writeRawFloat(float v) throws IOException {
-        writeInt(Float.floatToRawIntBits(v));
-    }
-    public static void writeRawFloatBig(Packet packet, float v) throws IOException {
-        writeIntBig(packet, Float.floatToRawIntBits(v));
-    }
-    public static void writeRawFloatLittle(Packet packet, float v) throws IOException {
-        writeIntLittle(packet, Float.floatToRawIntBits(v));
-    }
-
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activeio.packet;
+
+import java.io.EOFException;
+import java.io.IOException;
+
+
+/**
+ * Used to write and read primitives to and from a Packet.
+ */
+final public class PacketData {
+
+    final private Packet packet;
+    private final boolean bigEndian;
+
+    public PacketData(Packet packet) {
+        this(packet, true);
+    }
+
+    public PacketData(Packet packet, boolean bigEndian) {
+        this.packet = packet;
+        this.bigEndian = bigEndian;
+    }
+
+    private static void spaceNeeded(Packet packet, int space) throws IOException {
+        if (packet.remaining() < space)
+            throw new EOFException("Not enough space left in the packet.");
+    }
+
+    public void readFully(byte[] b) throws IOException {
+        readFully(packet, b, 0, b.length);
+    }
+    
+    public static void readFully(Packet packet, byte[] b) throws IOException {
+        readFully(packet, b, 0, b.length);
+    }
+
+    public void readFully(byte[] b, int off, int len) throws IOException {
+        readFully(packet, b, off, len);
+    }
+    public static void readFully(Packet packet, byte[] b, int off, int len) throws IOException {
+        spaceNeeded(packet, len);
+        packet.read(b, off, len);
+    }
+
+    public int skipBytes(int n) throws IOException {
+        return skipBytes(packet, n);
+    }
+    public static int skipBytes(Packet packet, int n) throws IOException {
+        int rc = Math.min(n, packet.remaining());
+        packet.position(packet.position() + rc);
+        return rc;
+    }
+
+    public boolean readBoolean() throws IOException {
+        return readBoolean(packet);
+    }
+    public static boolean readBoolean(Packet packet) throws IOException {
+        spaceNeeded(packet, 1);
+        return packet.read() != 0;
+    }
+
+    public byte readByte() throws IOException {
+        return readByte(packet);
+    }
+    public static byte readByte(Packet packet) throws IOException {
+        spaceNeeded(packet, 1);
+        return (byte) packet.read();
+    }
+
+    public int readUnsignedByte() throws IOException {
+        return readUnsignedByte(packet);
+    }
+    public static int readUnsignedByte(Packet packet) throws IOException {
+        spaceNeeded(packet, 1);
+        return packet.read();
+    }
+
+    public short readShort() throws IOException {
+        if( bigEndian ) {
+            return readShortBig(packet);
+        } else {
+	        return readShortLittle(packet);
+        }        
+    }
+    public static short readShortBig(Packet packet) throws IOException {
+        spaceNeeded(packet, 2);
+        return (short) ((packet.read() << 8) + (packet.read() << 0));
+    }
+    public static short readShortLittle(Packet packet) throws IOException {
+        spaceNeeded(packet, 2);
+        return (short) ((packet.read() << 0) + (packet.read() << 8) );
+    }
+
+    public int readUnsignedShort() throws IOException {
+        if( bigEndian ) {
+            return readUnsignedShortBig(packet);
+        } else {
+	        return readUnsignedShortLittle(packet);
+        }        
+    }
+    public static int readUnsignedShortBig(Packet packet) throws IOException {
+        spaceNeeded(packet, 2);
+        return ((packet.read() << 8) + (packet.read() << 0));
+    }
+    public static int readUnsignedShortLittle(Packet packet) throws IOException {
+        spaceNeeded(packet, 2);
+        return ((packet.read() << 0) + (packet.read() << 8) );
+    }
+
+    public char readChar() throws IOException {
+        if( bigEndian ) {
+            return readCharBig(packet);
+        } else {
+	        return readCharLittle(packet);
+        }        
+    }
+    public static char readCharBig(Packet packet) throws IOException {
+        spaceNeeded(packet, 2);
+        return (char) ((packet.read() << 8) + (packet.read() << 0));
+    }
+    public static char readCharLittle(Packet packet) throws IOException {
+        spaceNeeded(packet, 2);
+        return (char) ((packet.read() << 0) + (packet.read() << 8) );
+    }
+
+    public int readInt() throws IOException {
+        if( bigEndian ) {
+	        return readIntBig(packet);
+        } else {
+	        return readIntLittle(packet);
+        }        
+    }    
+    public static int readIntBig(Packet packet) throws IOException {
+        spaceNeeded(packet, 4);
+        return ((packet.read() << 24) + 
+                (packet.read() << 16) + 
+                (packet.read() << 8) + 
+                (packet.read() << 0));
+    }    
+    public static int readIntLittle(Packet packet) throws IOException {
+        spaceNeeded(packet, 4);
+        return ((packet.read() << 0) +
+                (packet.read() << 8) + 
+                (packet.read() << 16) + 
+                (packet.read() << 24));
+    }    
+    
+    public long readLong() throws IOException {
+        if( bigEndian ) {
+	        return readLongBig(packet);
+        } else {
+	        return readLongLittle(packet);	                
+        }        
+    }
+    public static long readLongBig(Packet packet) throws IOException {
+        spaceNeeded(packet, 8);
+        return (((long) packet.read() << 56) + 
+                ((long) packet.read() << 48) + 
+                ((long) packet.read() << 40) + 
+                ((long) packet.read() << 32) + 
+                ((long) packet.read() << 24) + 
+                ((packet.read()) << 16) + 
+                ((packet.read()) << 8) + 
+                ((packet.read()) << 0));
+    }
+    public static long readLongLittle(Packet packet) throws IOException {
+        spaceNeeded(packet, 8);
+        return ((packet.read() << 0) +
+                (packet.read() << 8) + 
+                (packet.read() << 16) + 
+                ((long) packet.read() << 24) +
+                ((long) packet.read() << 32) + 
+                ((long) packet.read() << 40) + 
+                ((long) packet.read() << 48) + 
+                ((long) packet.read() << 56));                  
+    }
+    
+    public double readDouble() throws IOException {
+        return Double.longBitsToDouble(readLong());
+    }
+    public static double readDoubleBig(Packet packet) throws IOException {
+        return Double.longBitsToDouble(readLongBig(packet));
+    }
+    public static double readDoubleLittle(Packet packet) throws IOException {
+        return Double.longBitsToDouble(readLongLittle(packet));
+    }
+
+    public float readFloat() throws IOException {
+        return Float.intBitsToFloat(readInt());
+    }
+    public static float readFloatBig(Packet packet) throws IOException {
+        return Float.intBitsToFloat(readIntBig(packet));
+    }
+    public static float readFloatLittle(Packet packet) throws IOException {
+        return Float.intBitsToFloat(readIntLittle(packet));
+    }
+
+    public void write(int b) throws IOException {
+        write(packet, b);
+    }
+    public static void write(Packet packet, int b) throws IOException {
+        spaceNeeded(packet, 1);
+        packet.write(b);
+    }
+
+    public void write(byte[] b) throws IOException {
+        write(packet, b, 0, b.length);
+    }
+    public static void write(Packet packet, byte[] b) throws IOException {
+        write(packet, b, 0, b.length);
+    }
+
+    public void write(byte[] b, int off, int len) throws IOException {
+        write(packet, b, off, len);
+    }
+    public static void write(Packet packet, byte[] b, int off, int len) throws IOException {
+        spaceNeeded(packet, len);
+        packet.write(b, off, len);
+    }
+
+    public void writeBoolean(boolean v) throws IOException {
+        writeBoolean(packet, v);
+    }
+    public static void writeBoolean(Packet packet, boolean v) throws IOException {
+        spaceNeeded(packet, 1);
+        packet.write(v ? 1 : 0);
+    }
+
+    public void writeByte(int v) throws IOException {
+        writeByte(packet, v);
+    }
+    public static void writeByte(Packet packet, int v) throws IOException {
+        spaceNeeded(packet, 1);
+        packet.write(v);
+    }
+
+    public void writeShort(int v) throws IOException {
+        if (bigEndian) {
+	        writeShortBig(packet,v);
+	    } else {
+            writeShortLittle(packet,v);
+	    }
+    }
+    public static void writeShortBig(Packet packet, int v) throws IOException {
+        spaceNeeded(packet, 2);
+        packet.write((v >>> 8) & 0xFF);
+        packet.write((v >>> 0) & 0xFF);
+    }
+    public static void writeShortLittle(Packet packet, int v) throws IOException {
+        spaceNeeded(packet, 2);
+        packet.write((v >>> 0) & 0xFF);
+        packet.write((v >>> 8) & 0xFF);
+    }
+
+    public void writeChar(int v) throws IOException {
+        if (bigEndian) {
+            writeCharBig(packet, v);
+        } else {
+            writeCharLittle(packet, v);
+        }
+    }
+    public static void writeCharBig(Packet packet, int v) throws IOException {
+        spaceNeeded(packet, 2);
+        packet.write((v >>> 8) & 0xFF);
+        packet.write((v >>> 0) & 0xFF);
+    }
+    public static void writeCharLittle(Packet packet, int v) throws IOException {
+        spaceNeeded(packet, 2);
+        packet.write((v >>> 0) & 0xFF);
+        packet.write((v >>> 8) & 0xFF);
+    }
+
+    public void writeInt(int v) throws IOException {
+        if (bigEndian) {
+            writeIntBig(packet, v);
+        } else {
+            writeIntLittle(packet, v);
+        }
+    }
+    public static void writeIntBig(Packet packet, int v) throws IOException {
+        spaceNeeded(packet, 4);
+        packet.write((v >>> 24) & 0xFF);
+        packet.write((v >>> 16) & 0xFF);
+        packet.write((v >>> 8) & 0xFF);
+        packet.write((v >>> 0) & 0xFF);
+    }
+    public static void writeIntLittle(Packet packet, int v) throws IOException {
+        spaceNeeded(packet, 4);
+        packet.write((v >>> 0) & 0xFF);
+        packet.write((v >>> 8) & 0xFF);
+        packet.write((v >>> 16) & 0xFF);
+        packet.write((v >>> 24) & 0xFF);
+    }
+
+    public void writeLong(long v) throws IOException {
+        if (bigEndian) {
+            writeLongBig(packet, v);
+        } else {
+            writeLongLittle(packet, v);
+        }
+    }
+    public static void writeLongBig(Packet packet, long v) throws IOException {
+        spaceNeeded(packet, 8);
+        packet.write((int) (v >>> 56) & 0xFF);
+        packet.write((int) (v >>> 48) & 0xFF);
+        packet.write((int) (v >>> 40) & 0xFF);
+        packet.write((int) (v >>> 32) & 0xFF);
+        packet.write((int) (v >>> 24) & 0xFF);
+        packet.write((int) (v >>> 16) & 0xFF);
+        packet.write((int) (v >>> 8) & 0xFF);
+        packet.write((int) (v >>> 0) & 0xFF);
+    }
+    public static void writeLongLittle(Packet packet, long v) throws IOException {
+        spaceNeeded(packet, 8);
+        packet.write((int) (v >>> 0) & 0xFF);
+        packet.write((int) (v >>> 8) & 0xFF);
+        packet.write((int) (v >>> 16) & 0xFF);
+        packet.write((int) (v >>> 24) & 0xFF);
+        packet.write((int) (v >>> 32) & 0xFF);
+        packet.write((int) (v >>> 40) & 0xFF);
+        packet.write((int) (v >>> 48) & 0xFF);
+        packet.write((int) (v >>> 56) & 0xFF);
+    }
+    
+    public void writeDouble(double v) throws IOException {
+        writeLong(Double.doubleToLongBits(v));
+    }
+    public static void writeDoubleBig(Packet packet, double v) throws IOException {
+        writeLongBig(packet, Double.doubleToLongBits(v));
+    }
+    public static void writeDoubleLittle(Packet packet, double v) throws IOException {
+        writeLongLittle(packet, Double.doubleToLongBits(v));
+    }
+
+    public void writeFloat(float v) throws IOException {
+        writeInt(Float.floatToIntBits(v));
+    }
+    public static void writeFloatBig(Packet packet, float v) throws IOException {
+        writeIntBig(packet, Float.floatToIntBits(v));
+    }
+    public static void writeFloatLittle(Packet packet, float v) throws IOException {
+        writeIntLittle(packet, Float.floatToIntBits(v));
+    }
+    
+    public void writeRawDouble(double v) throws IOException {
+        writeLong(Double.doubleToRawLongBits(v));
+    }
+    public static void writeRawDoubleBig(Packet packet, double v) throws IOException {
+        writeLongBig(packet, Double.doubleToRawLongBits(v));
+    }
+    public static void writeRawDoubleLittle(Packet packet, double v) throws IOException {
+        writeLongLittle(packet, Double.doubleToRawLongBits(v));
+    }
+
+    public void writeRawFloat(float v) throws IOException {
+        writeInt(Float.floatToRawIntBits(v));
+    }
+    public static void writeRawFloatBig(Packet packet, float v) throws IOException {
+        writeIntBig(packet, Float.floatToRawIntBits(v));
+    }
+    public static void writeRawFloatLittle(Packet packet, float v) throws IOException {
+        writeIntLittle(packet, Float.floatToRawIntBits(v));
+    }
+
+}

Propchange: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/PacketData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/PacketPool.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/PacketPool.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/PacketPool.java (original)
+++ incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/PacketPool.java Tue Feb 21 15:12:56 2006
@@ -1,144 +1,144 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activeio.packet;
-
-import java.util.ArrayList;
-
-import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Provides a simple pool of Packet objects.  When the packets that this pool produces are disposed,
- * they are returned to the pool.
- * 
- * @version $Revision: 1.1 $
- */
-abstract public class PacketPool {
-    
-    public static final int DEFAULT_POOL_SIZE = Integer.parseInt(System.getProperty("org.apache.activeio.journal.active.DefaultPoolSize", ""+(5)));
-    public static final int DEFAULT_PACKET_SIZE = Integer.parseInt(System.getProperty("org.apache.activeio.journal.active.DefaultPacketSize", ""+(1024*1024*4)));
-    
-	private final ArrayList pool = new ArrayList();
-	private final int maxPackets;
-    private int currentPoolSize;
-    private boolean disposed;
-    
-    public class PooledPacket extends FilterPacket {
-        private final AtomicInteger referenceCounter;
-        
-        public PooledPacket(Packet next) {
-            this(next, new AtomicInteger(0));
-        }
-        
-        private PooledPacket(Packet next, AtomicInteger referenceCounter) {
-            super(next);
-            this.referenceCounter=referenceCounter;
-            this.referenceCounter.incrementAndGet();
-        }
-        
-        public Packet filter(Packet packet) {
-            return new PooledPacket(next, referenceCounter);
-        }
-
-        int getReferenceCounter() {
-            return referenceCounter.get();
-        }
-        
-        public void dispose() {
-            if( referenceCounter.decrementAndGet()==0 ) {
-                returnPacket(next);
-            }
-        }
-    }
-	
-	/**
-	 * @param maxPackets the number of buffers that will be in the pool.
-	 */
-	public PacketPool(int maxPackets) {
-		this.maxPackets = maxPackets;
-	}
-	
-	/**
-	 * Blocks until a ByteBuffer can be retreived from the pool.
-	 * 
-	 * @return
-	 * @throws InterruptedException
-	 */
-	public Packet getPacket() throws InterruptedException {
-	    Packet answer=null;
-		synchronized(this) {
-			while(answer==null) {
-                 if( disposed )
-                     return null;                 
-				if( pool.size()>0) {
-					answer = (Packet) pool.remove(pool.size()-1);
-				} else if( currentPoolSize < maxPackets ) {
-                     answer = allocateNewPacket();
-                     currentPoolSize++;
-                 }
-				if( answer==null ) {
-					this.wait();
-				}
-			}
-		}
-		return new PooledPacket(answer);
-	}
-
-	/**
-	 * Returns a ByteBuffer to the pool.
-	 * 
-	 * @param packet
-	 */
-	private void returnPacket(Packet packet) {
-		packet.clear();
-		synchronized(this) {
-			pool.add(packet);
-			this.notify();
-		}
-	}
-    
-    synchronized public void dispose() {
-        disposed = true;
-        while( currentPoolSize>0 ) {
-            if( pool.size()>0) {
-                currentPoolSize -= pool.size();
-                pool.clear();
-            } else {
-                try {
-                    this.wait();
-                } catch (InterruptedException e) {
-                    return;
-                }
-            }
-        }
-    }
-    
-    synchronized public void waitForPacketsToReturn() {
-        while( currentPoolSize!=pool.size() ) {
-            try {
-                this.wait();
-            } catch (InterruptedException e) {
-                return;
-            }
-        }
-    }
-
-    /**
-     * @return
-     */
-    abstract protected Packet allocateNewPacket();
-        
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activeio.packet;
+
+import java.util.ArrayList;
+
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Provides a simple pool of Packet objects.  When the packets that this pool produces are disposed,
+ * they are returned to the pool.
+ * 
+ * @version $Revision: 1.1 $
+ */
+abstract public class PacketPool {
+    
+    public static final int DEFAULT_POOL_SIZE = Integer.parseInt(System.getProperty("org.apache.activeio.journal.active.DefaultPoolSize", ""+(5)));
+    public static final int DEFAULT_PACKET_SIZE = Integer.parseInt(System.getProperty("org.apache.activeio.journal.active.DefaultPacketSize", ""+(1024*1024*4)));
+    
+	private final ArrayList pool = new ArrayList();
+	private final int maxPackets;
+    private int currentPoolSize;
+    private boolean disposed;
+    
+    public class PooledPacket extends FilterPacket {
+        private final AtomicInteger referenceCounter;
+        
+        public PooledPacket(Packet next) {
+            this(next, new AtomicInteger(0));
+        }
+        
+        private PooledPacket(Packet next, AtomicInteger referenceCounter) {
+            super(next);
+            this.referenceCounter=referenceCounter;
+            this.referenceCounter.incrementAndGet();
+        }
+        
+        public Packet filter(Packet packet) {
+            return new PooledPacket(next, referenceCounter);
+        }
+
+        int getReferenceCounter() {
+            return referenceCounter.get();
+        }
+        
+        public void dispose() {
+            if( referenceCounter.decrementAndGet()==0 ) {
+                returnPacket(next);
+            }
+        }
+    }
+	
+	/**
+	 * @param maxPackets the number of buffers that will be in the pool.
+	 */
+	public PacketPool(int maxPackets) {
+		this.maxPackets = maxPackets;
+	}
+	
+	/**
+	 * Blocks until a ByteBuffer can be retreived from the pool.
+	 * 
+	 * @return
+	 * @throws InterruptedException
+	 */
+	public Packet getPacket() throws InterruptedException {
+	    Packet answer=null;
+		synchronized(this) {
+			while(answer==null) {
+                 if( disposed )
+                     return null;                 
+				if( pool.size()>0) {
+					answer = (Packet) pool.remove(pool.size()-1);
+				} else if( currentPoolSize < maxPackets ) {
+                     answer = allocateNewPacket();
+                     currentPoolSize++;
+                 }
+				if( answer==null ) {
+					this.wait();
+				}
+			}
+		}
+		return new PooledPacket(answer);
+	}
+
+	/**
+	 * Returns a ByteBuffer to the pool.
+	 * 
+	 * @param packet
+	 */
+	private void returnPacket(Packet packet) {
+		packet.clear();
+		synchronized(this) {
+			pool.add(packet);
+			this.notify();
+		}
+	}
+    
+    synchronized public void dispose() {
+        disposed = true;
+        while( currentPoolSize>0 ) {
+            if( pool.size()>0) {
+                currentPoolSize -= pool.size();
+                pool.clear();
+            } else {
+                try {
+                    this.wait();
+                } catch (InterruptedException e) {
+                    return;
+                }
+            }
+        }
+    }
+    
+    synchronized public void waitForPacketsToReturn() {
+        while( currentPoolSize!=pool.size() ) {
+            try {
+                this.wait();
+            } catch (InterruptedException e) {
+                return;
+            }
+        }
+    }
+
+    /**
+     * @return
+     */
+    abstract protected Packet allocateNewPacket();
+        
+}

Propchange: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/PacketPool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/async/AsyncChannel.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/async/AsyncChannel.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/async/AsyncChannel.java (original)
+++ incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/async/AsyncChannel.java Tue Feb 21 15:12:56 2006
@@ -1,61 +1,61 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activeio.packet.async;
-
-import java.io.IOException;
-
-import org.apache.activeio.Channel;
-import org.apache.activeio.packet.Packet;
-
-
-/**
- * AsyncChannel objects asynchronously push 'up' {@see org.apache.activeio.Packet} objects
- * to a registered {@see org.apache.activeio.ChannelConsumer}.
- * 
- * @version $Revision$
- */
-public interface AsyncChannel extends Channel {
-    
-    /**
-     * Registers the {@see ChannelConsumer} that the protcol will use to deliver packets
-     * coming 'up' the channel.
-     *  
-     * @param packetListener
-     */
-    void setAsyncChannelListener(AsyncChannelListener channelListener);
-    
-    /**
-     * @return the registered Packet consumer
-     */
-    AsyncChannelListener getAsyncChannelListener();
-    
-    /**
-     * Sends a packet down the channel towards the media.
-     * 
-     * @param packet
-     * @throws IOException
-     */
-    void write(Packet packet) throws IOException;
-
-    /**
-     * Some channels may buffer data which may be sent down if flush() is called.
-     * 
-     * @throws IOException
-     */
-    void flush() throws IOException;    
-
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activeio.packet.async;
+
+import java.io.IOException;
+
+import org.apache.activeio.Channel;
+import org.apache.activeio.packet.Packet;
+
+
+/**
+ * AsyncChannel objects asynchronously push 'up' {@see org.apache.activeio.Packet} objects
+ * to a registered {@see org.apache.activeio.ChannelConsumer}.
+ * 
+ * @version $Revision$
+ */
+public interface AsyncChannel extends Channel {
+    
+    /**
+     * Registers the {@see ChannelConsumer} that the protcol will use to deliver packets
+     * coming 'up' the channel.
+     *  
+     * @param packetListener
+     */
+    void setAsyncChannelListener(AsyncChannelListener channelListener);
+    
+    /**
+     * @return the registered Packet consumer
+     */
+    AsyncChannelListener getAsyncChannelListener();
+    
+    /**
+     * Sends a packet down the channel towards the media.
+     * 
+     * @param packet
+     * @throws IOException
+     */
+    void write(Packet packet) throws IOException;
+
+    /**
+     * Some channels may buffer data which may be sent down if flush() is called.
+     * 
+     * @throws IOException
+     */
+    void flush() throws IOException;    
+
+}

Propchange: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/async/AsyncChannel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/async/AsyncChannelFactory.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/async/AsyncChannelFactory.java?rev=379619&r1=379618&r2=379619&view=diff
==============================================================================
--- incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/async/AsyncChannelFactory.java (original)
+++ incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/async/AsyncChannelFactory.java Tue Feb 21 15:12:56 2006
@@ -1,47 +1,47 @@
-/**
- *
- * Copyright 2005-2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activeio.packet.async;
-
-import java.io.IOException;
-import java.net.URI;
-
-
-/**
- * AsyncChannelFactory objects can create {@see org.apache.activeio.AsyncChannel}
- * and {@see org.apache.activeio.AsyncChannelServer} objects. 
- * 
- * @version $Revision$
- */
-public interface AsyncChannelFactory {
-
-	/**
-     * Opens a connection to server.
-     * 
-     * @param location
-     * @return
-     */
-	public AsyncChannel openAsyncChannel(URI location) throws IOException;
-	
-	/**
-     * Binds a server at the URI location.
-     * 
-     * @param location
-     * @return
-     */
-	public AsyncChannelServer bindAsyncChannel(URI location) throws IOException;
-	
-}
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activeio.packet.async;
+
+import java.io.IOException;
+import java.net.URI;
+
+
+/**
+ * AsyncChannelFactory objects can create {@see org.apache.activeio.AsyncChannel}
+ * and {@see org.apache.activeio.AsyncChannelServer} objects. 
+ * 
+ * @version $Revision$
+ */
+public interface AsyncChannelFactory {
+
+	/**
+     * Opens a connection to server.
+     * 
+     * @param location
+     * @return
+     */
+	public AsyncChannel openAsyncChannel(URI location) throws IOException;
+	
+	/**
+     * Binds a server at the URI location.
+     * 
+     * @param location
+     * @return
+     */
+	public AsyncChannelServer bindAsyncChannel(URI location) throws IOException;
+	
+}

Propchange: incubator/activemq/trunk/activeio/activeio-core/src/main/java/org/apache/activeio/packet/async/AsyncChannelFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message