JBoss Remoting SVN: r4353 - in remoting3/trunk: testing-support/src/main and 1 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 19:47:24 -0400 (Thu, 03 Jul 2008)
New Revision: 4353
Added:
remoting3/trunk/testing-support/src/main/resources/
remoting3/trunk/testing-support/src/main/resources/testing.policy
Modified:
remoting3/trunk/build.properties
remoting3/trunk/build.xml
Log:
Our first tests. yay
Modified: remoting3/trunk/build.properties
===================================================================
--- remoting3/trunk/build.properties 2008-07-03 23:31:26 UTC (rev 4352)
+++ remoting3/trunk/build.properties 2008-07-03 23:47:24 UTC (rev 4353)
@@ -124,6 +124,14 @@
lib.jbossxb.local=${local.repository}/${lib.jbossxb.path}
lib.jbossxb.remote=${remote.repository}/jboss/${lib.jbossxb.path}
+lib.junit.version=3.8.1
+lib.junit.name=junit.jar
+lib.junit.license=cpl
+lib.junit.dir=junit/${lib.junit.version}/lib
+lib.junit.path=${lib.junit.dir}/${lib.junit.name}
+lib.junit.local=${local.repository}/${lib.junit.path}
+lib.junit.remote=${remote.repository}/${lib.junit.path}
+
lib.mina.version=2.0.0-M1-20071228.043505-111
lib.mina.name=mina-core-${lib.mina.version}.jar
lib.mina.license=apache-2.0
Modified: remoting3/trunk/build.xml
===================================================================
--- remoting3/trunk/build.xml 2008-07-03 23:31:26 UTC (rev 4352)
+++ remoting3/trunk/build.xml 2008-07-03 23:47:24 UTC (rev 4353)
@@ -139,6 +139,16 @@
<get src="${remote.license.dir}/${lib.jbossxb.license}.txt" dest="${lib.jbossxb.local}.license.txt" usetimestamp="true" ignoreerrors="false"/>
</target>
+ <target name="lib.junit-check">
+ <available property="lib.junit.exists" file="${lib.junit.local}"/>
+ </target>
+
+ <target name="lib.junit" depends="lib.junit-check" unless="lib.junit.exists">
+ <mkdir dir="${local.repository}/${lib.junit.dir}"/>
+ <get src="${lib.junit.remote}" dest="${lib.junit.local}" usetimestamp="true" ignoreerrors="false"/>
+ <get src="${remote.license.dir}/${lib.junit.license}.txt" dest="${lib.junit.local}.license.txt" usetimestamp="true" ignoreerrors="false"/>
+ </target>
+
<!-- External library: Servlet API 2.4 -->
<target name="lib.servlet-check">
@@ -209,6 +219,78 @@
<touch file="api/target/main/.lastcompile" verbose="false"/>
</target>
+ <target name="api.test.compile.depcheck">
+ <mkdir dir="api/target/test"/>
+ <uptodate property="api.compile.uptodate" targetfile="api/target/test/.lastcompile">
+ <srcfiles dir="api/src/test/java">
+ <include name="**/"/>
+ <include name="**/*.java"/>
+ <exclude name="**/.*"/>
+ </srcfiles>
+ </uptodate>
+ </target>
+
+ <target name="api.test.compile" depends="lib.junit,api.compile,api.test.compile.depcheck" unless="api.test.compile.uptodate">
+ <mkdir dir="api/target/test/classes"/>
+ <javac
+ source="${javac.source}"
+ target="${javac.target}"
+ srcdir="api/src/test/java"
+ destdir="api/target/test/classes"
+ debug="true">
+ <compilerarg value="-Xlint:unchecked"/>
+ <classpath>
+ <path refid="api.classpath"/>
+ <path refid="testing-support.classpath"/>
+ <pathelement location="${lib.junit.local}"/>
+ <pathelement location="${lib.xnio-api.local}"/>
+ </classpath>
+ </javac>
+ <touch file="api/target/test/.lastcompile" verbose="false"/>
+ </target>
+
+ <target name="api.test.pseudotarget">
+ <echo message="============================================="/>
+ <echo message="${message}"/>
+ <echo message="============================================="/>
+ <mkdir dir="api/target/test-results"/>
+ <junit printsummary="true" fork="yes" includeantruntime="true">
+ <sysproperty key="build.home" value="${basedir}"/>
+ <sysproperty key="ant.library.dir" value="${ant.home}/lib"/>
+ <sysproperty key="lib.junit.local" value="${lib.junit.local}"/>
+ <sysproperty key="lib.xnio-api.local" value="${lib.xnio-api.local}"/>
+ <jvmarg line="${test.jvmargs}"/>
+ <formatter type="plain" extension="${extension}"/>
+ <classpath>
+ <path refid="api.classpath"/>
+ <path refid="testing-support.classpath"/>
+ <path refid="util.classpath"/>
+ <pathelement location="api/target/test/classes"/>
+ <pathelement location="${lib.junit.local}"/>
+ <pathelement location="${lib.xnio-api.local}"/>
+ </classpath>
+ <batchtest fork="yes" todir="api/target/test-results"
+ haltonfailure="no">
+ <fileset dir="api/target/test/classes">
+ <include name="**/*TestCase.class"/>
+ </fileset>
+ </batchtest>
+ </junit>
+ </target>
+
+ <target name="api.test" depends="api,testing-support,api.test.compile">
+ <antcall inheritall="true" inheritrefs="true" target="api.test.pseudotarget">
+ <param name="extension" value=".txt"/>
+ <param name="message" value="Running with no security manager"/>
+ <param name="test.jvmargs" value="-Ddummy=dummy"/>
+ </antcall>
+ <antcall inheritall="true" inheritrefs="true" target="api.test.pseudotarget">
+ <param name="extension" value="-security.txt"/>
+ <param name="message" value="Running with security manager"/>
+ <param name="test.jvmargs" value="-Djava.security.manager=org.jboss.cx.remoting.test.support.LoggingSecurityManager -Djava.security.policy=${basedir}/testing-support/src/main/resources/testing.policy"/>
+ </antcall>
+ </target>
+
<target name="api.clean">
<delete dir="api/target"/>
</target>
@@ -717,6 +799,10 @@
destdir="testing-support/target/main/classes"
debug="true">
<compilerarg value="-Xlint:unchecked"/>
+ <classpath>
+ <pathelement location="${lib.junit.local}"/>
+ <pathelement location="${lib.xnio-api.local}"/>
+ </classpath>
</javac>
<touch file="testing-support/target/main/.lastcompile" verbose="false"/>
</target>
@@ -725,7 +811,7 @@
<delete dir="testing-support/target"/>
</target>
- <target name="testing-support" description="Build the testing-support module" depends="testing-support.compile">
+ <target name="testing-support" description="Build the testing-support module" depends="lib.junit,lib.xnio-api,testing-support.compile">
<path id="testing-support.classpath">
<pathelement location="testing-support/target/main/classes"/>
</path>
@@ -1022,4 +1108,6 @@
<target name="clean" description="Clean out all build files" depends="clean-core,clean-http"/>
+ <target name="test" description="Run all tests" depends="api.test"/>
+
</project>
Added: remoting3/trunk/testing-support/src/main/resources/testing.policy
===================================================================
--- remoting3/trunk/testing-support/src/main/resources/testing.policy (rev 0)
+++ remoting3/trunk/testing-support/src/main/resources/testing.policy 2008-07-03 23:47:24 UTC (rev 4353)
@@ -0,0 +1,39 @@
+
+// Permissions to grant to modules
+
+grant codeBase "file:${build.home}/api/target/main/classes/-"
+{
+};
+
+// Permissions to run the api test suite
+
+grant codeBase "file:${build.home}/api/target/main/classes/-"
+{
+};
+
+// Support classes
+
+grant codeBase "file:${build.home}/testing-support/target/main/classes/-"
+{
+ permission java.security.AllPermission;
+};
+
+grant codeBase "file:${idea.home}/lib/idea_rt.jar"
+{
+ permission java.security.AllPermission;
+};
+
+grant codeBase "file:${lib.junit.local}"
+{
+ permission java.security.AllPermission;
+};
+
+grant codeBase "file:${ant.library.dir}/-"
+{
+ permission java.security.AllPermission;
+};
+
+grant codeBase "file:${lib.xnio-api.local}"
+{
+ permission java.security.AllPermission;
+};
16 years, 6 months
JBoss Remoting SVN: r4352 - in remoting3/trunk: api/src/test and 9 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 19:31:26 -0400 (Thu, 03 Jul 2008)
New Revision: 4352
Added:
remoting3/trunk/api/src/test/
remoting3/trunk/api/src/test/java/
remoting3/trunk/api/src/test/java/org/
remoting3/trunk/api/src/test/java/org/jboss/
remoting3/trunk/api/src/test/java/org/jboss/cx/
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java
remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestByteBufferAllocator.java
remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestCharBufferAllocator.java
Log:
Add some tests to the api module, plus extra test support
Added: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java (rev 0)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/spi/marshal/ObjectResolverTestCase.java 2008-07-03 23:31:26 UTC (rev 4352)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.spi.marshal;
+
+import junit.framework.TestCase;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Arrays;
+
+/**
+ *
+ */
+public final class ObjectResolverTestCase extends TestCase {
+ public static final class ThingOne {
+
+ }
+
+ public static final class ThingTwo {
+
+ }
+
+ public static final class ResolverOne implements ObjectResolver {
+
+ private static final long serialVersionUID = 6121192940632885123L;
+
+ public Object writeReplace(final Object original) throws IOException {
+ if (original instanceof ThingOne) {
+ return "ThingOne";
+ } else {
+ return original;
+ }
+ }
+
+ public Object readResolve(final Object original) throws IOException {
+ if (original instanceof String && "ThingOne".equals(original)) {
+ return new ThingOne();
+ } else {
+ return original;
+ }
+ }
+ }
+
+ public static final class ResolverTwo implements ObjectResolver {
+
+ private static final long serialVersionUID = 7833685858039930273L;
+
+ public Object writeReplace(final Object original) throws IOException {
+ if (original instanceof ThingTwo) {
+ return "ThingTwo";
+ } else {
+ return original;
+ }
+ }
+
+ public Object readResolve(final Object original) throws IOException {
+ if (original instanceof String && "ThingTwo".equals(original)) {
+ return new ThingTwo();
+ } else {
+ return original;
+ }
+ }
+ }
+
+ public void testCompositeResolver() throws Throwable {
+ final CompositeObjectResolver compositeObjectResolver = new CompositeObjectResolver(Arrays.asList(new ResolverOne(), new ResolverTwo()));
+ assertEquals(compositeObjectResolver.writeReplace("Test"), "Test");
+ assertEquals(compositeObjectResolver.writeReplace(new ThingOne()), "ThingOne");
+ assertEquals(compositeObjectResolver.writeReplace(new ThingTwo()), "ThingTwo");
+ assertEquals(compositeObjectResolver.readResolve("Test"), "Test");
+ assertTrue(compositeObjectResolver.readResolve("ThingOne") instanceof ThingOne);
+ assertTrue(compositeObjectResolver.readResolve("ThingTwo") instanceof ThingTwo);
+ }
+}
Added: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java (rev 0)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferInputStreamTestCase.java 2008-07-03 23:31:26 UTC (rev 4352)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.stream;
+
+import junit.framework.TestCase;
+import java.util.Arrays;
+import java.nio.ByteBuffer;
+import org.jboss.cx.remoting.test.support.TestByteBufferAllocator;
+
+/**
+ *
+ */
+public final class ByteBufferInputStreamTestCase extends TestCase {
+ public void testBasic() throws Throwable {
+ final TestByteBufferAllocator allocator = new TestByteBufferAllocator(3);
+ final ByteBufferInputStream stream = new ByteBufferInputStream(Streams.<ByteBuffer>getIteratorObjectSource(Arrays.<ByteBuffer>asList(
+ ByteBuffer.wrap(new byte[] { 5, 100, 30, 12, -60, 25 }),
+ ByteBuffer.wrap(new byte[] { 15 }),
+ ByteBuffer.wrap(new byte[] { }),
+ ByteBuffer.wrap(new byte[] { 100, 0, 0, -128, 127, 0 })).iterator()), allocator);
+ assertEquals(5, stream.read());
+ assertEquals(100, stream.read());
+ assertEquals(30, stream.read());
+ assertEquals(12, stream.read());
+ assertEquals(-60 & 0xff, stream.read());
+ assertEquals(25, stream.read());
+ assertEquals(15, stream.read());
+ assertEquals(100, stream.read());
+ assertEquals(0, stream.read());
+ assertEquals(0, stream.read());
+ assertEquals(-128 & 0xff, stream.read());
+ assertEquals(127, stream.read());
+ assertEquals(0, stream.read());
+ assertEquals(-1, stream.read());
+ assertEquals(-1, stream.read());
+ // I fed it four buffers, so there should be -4
+ allocator.check(-4);
+ }
+
+ public void testArrayRead() throws Throwable {
+ final TestByteBufferAllocator allocator = new TestByteBufferAllocator(3);
+ final ByteBufferInputStream stream = new ByteBufferInputStream(Streams.<ByteBuffer>getIteratorObjectSource(Arrays.<ByteBuffer>asList(
+ ByteBuffer.wrap(new byte[] { 5, 100, 30, 12, -60, 25 }),
+ ByteBuffer.wrap(new byte[] { 15 }),
+ ByteBuffer.wrap(new byte[] { }),
+ ByteBuffer.wrap(new byte[] { 100, 0, 0, -128, 127, 0 })).iterator()), allocator);
+ assertEquals(5, stream.read());
+ assertEquals(100, stream.read());
+ assertEquals(30, stream.read());
+ byte[] bytes = new byte[5];
+ assertEquals(5, stream.read(bytes));
+ assertTrue(Arrays.equals(new byte[] { 12, -60, 25, 15, 100 }, bytes));
+ assertEquals(0, stream.read());
+ bytes = new byte[15];
+ Arrays.fill(bytes, (byte) 7);
+ assertEquals(3, stream.read(bytes, 4, 3));
+ assertTrue(Arrays.equals(new byte[] { 7, 7, 7, 7, 0, -128, 127, 7, 7, 7, 7, 7, 7, 7, 7 }, bytes));
+ assertEquals(0, stream.read());
+ assertEquals(-1, stream.read());
+ assertEquals(-1, stream.read());
+ // I fed it four buffers, so there should be -4
+ allocator.check(-4);
+ }
+}
Added: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java (rev 0)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/ByteBufferOutputStreamTestCase.java 2008-07-03 23:31:26 UTC (rev 4352)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.stream;
+
+import junit.framework.TestCase;
+import org.jboss.cx.remoting.test.support.TestByteBufferAllocator;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ */
+public final class ByteBufferOutputStreamTestCase extends TestCase {
+ public void testBasic() throws Throwable {
+ final TestByteBufferAllocator allocator = new TestByteBufferAllocator(4);
+ final List<ByteBuffer> list = new ArrayList<ByteBuffer>();
+ final ObjectSink<ByteBuffer> sink = Streams.getCollectionObjectSink(list);
+ final ByteBufferOutputStream stream = new ByteBufferOutputStream(sink, allocator);
+ stream.write(new byte[] { 6, 1, 5, 2, 4, 3, 2, 4, 1, 5, 0, 6 });
+ stream.write(new byte[0]);
+ stream.write(new byte[] { 4, 5, 6, 45, -20, 0, 0, 1, 12, 13, 19, 34 }, 3, 7);
+ stream.write(new byte[] { 45, -20, 0, 0, 1, 12, 13 }, 4, 0);
+ stream.write(0);
+ stream.write(10);
+ stream.flush();
+ stream.close();
+ final ByteBufferInputStream inputStream = new ByteBufferInputStream(Streams.getIteratorObjectSource(list.iterator()), allocator);
+ assertEquals(6, inputStream.read());
+ assertEquals(1, inputStream.read());
+ assertEquals(5, inputStream.read());
+ assertEquals(2, inputStream.read());
+ assertEquals(4, inputStream.read());
+ assertEquals(3, inputStream.read());
+ assertEquals(2, inputStream.read());
+ assertEquals(4, inputStream.read());
+ assertEquals(1, inputStream.read());
+ assertEquals(5, inputStream.read());
+ assertEquals(0, inputStream.read());
+ assertEquals(6, inputStream.read());
+ assertEquals(45, inputStream.read());
+ assertEquals(-20 & 0xff, inputStream.read());
+ assertEquals(0, inputStream.read());
+ assertEquals(0, inputStream.read());
+ assertEquals(1, inputStream.read());
+ assertEquals(12, inputStream.read());
+ assertEquals(13, inputStream.read());
+ assertEquals(0, inputStream.read());
+ assertEquals(10, inputStream.read());
+ assertEquals(-1, inputStream.read());
+ inputStream.close();
+ allocator.check(0);
+ }
+}
Added: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java (rev 0)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferReaderTestCase.java 2008-07-03 23:31:26 UTC (rev 4352)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.stream;
+
+import junit.framework.TestCase;
+import org.jboss.cx.remoting.test.support.TestCharBufferAllocator;
+import java.util.Arrays;
+import java.nio.CharBuffer;
+
+/**
+ *
+ */
+public final class CharBufferReaderTestCase extends TestCase {
+ public void testBasic() throws Throwable {
+ final TestCharBufferAllocator allocator = new TestCharBufferAllocator(10);
+ final ObjectSource<CharBuffer> source = Streams.getIteratorObjectSource(Arrays.asList(
+ CharBuffer.wrap("The quick brown "),
+ CharBuffer.wrap("fox j"),
+ CharBuffer.wrap("u"),
+ CharBuffer.allocate(0),
+ CharBuffer.wrap("mps over the la"),
+ CharBuffer.wrap("zy dogs.")
+ ).iterator());
+ CharBufferReader reader = new CharBufferReader(source, allocator);
+ String s = "The quick brown fox jumps over the lazy dogs.";
+ for (int i = 0; i < s.length(); i ++) {
+ assertEquals(s.charAt(i), reader.read());
+ }
+ assertEquals(-1, reader.read());
+ allocator.check(-6);
+ }
+}
Added: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java (rev 0)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/CharBufferWriterTestCase.java 2008-07-03 23:31:26 UTC (rev 4352)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.stream;
+
+import junit.framework.TestCase;
+import java.util.ArrayList;
+import java.util.List;
+import java.nio.CharBuffer;
+import org.jboss.cx.remoting.test.support.TestCharBufferAllocator;
+
+/**
+ *
+ */
+public final class CharBufferWriterTestCase extends TestCase {
+ public void testBasic() throws Throwable {
+ final TestCharBufferAllocator allocator = new TestCharBufferAllocator(7);
+ final List<CharBuffer> list = new ArrayList<CharBuffer>();
+ final ObjectSink<CharBuffer> sink = Streams.getCollectionObjectSink(list);
+ final CharBufferWriter writer = new CharBufferWriter(sink, allocator);
+ writer.append("Th");
+ writer.append("blah e qui blah", 5, 10);
+ writer.append('c');
+ writer.write('k');
+ writer.write(new char[] { ' ', 'b', 'r' });
+ writer.write(new char[] { 'x', 'x', 'o', 'w', 'n', ' ', 'x' }, 2, 4);
+ writer.write("fox jumps");
+ writer.write("blah over the lazy dogs. blah", 4, 20);
+ writer.flush();
+ writer.close();
+ final ObjectSource<CharBuffer> source = Streams.getIteratorObjectSource(list.iterator());
+ CharBufferReader reader = new CharBufferReader(source, allocator);
+ String s = "The quick brown fox jumps over the lazy dogs.";
+ for (int i = 0; i < s.length(); i ++) {
+ assertEquals("position = " + i, (char)s.charAt(i), (char)reader.read());
+ }
+ assertEquals(-1, reader.read());
+ allocator.check(0);
+ }
+}
Added: remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java
===================================================================
--- remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java (rev 0)
+++ remoting3/trunk/api/src/test/java/org/jboss/cx/remoting/stream/StreamsTestCase.java 2008-07-03 23:31:26 UTC (rev 4352)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.stream;
+
+import junit.framework.TestCase;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Arrays;
+import java.util.Vector;
+import java.io.EOFException;
+
+/**
+ *
+ */
+public final class StreamsTestCase extends TestCase {
+ public void testCollectionObjectSink() throws Throwable {
+ final ArrayList<String> strings = new ArrayList<String>();
+ final ObjectSink<String> sink = Streams.getCollectionObjectSink(strings);
+ sink.accept("Instance 1");
+ sink.accept("Instance 2");
+ sink.accept("Instance 3");
+ sink.accept("Instance 4");
+ sink.accept("Instance 5");
+ sink.close();
+ final Iterator<String> i = strings.iterator();
+ assertEquals(i.next(), "Instance 1");
+ assertEquals(i.next(), "Instance 2");
+ assertEquals(i.next(), "Instance 3");
+ assertEquals(i.next(), "Instance 4");
+ assertEquals(i.next(), "Instance 5");
+ assertFalse(i.hasNext());
+ }
+
+ public void testIteratorObjectSource() throws Throwable {
+ final ObjectSource<String> source = Streams.getIteratorObjectSource(Arrays.asList("One", "Two", "Three", "Four", "Five").iterator());
+ assertTrue(source.hasNext());
+ assertEquals(source.next(), "One");
+ assertTrue(source.hasNext());
+ assertEquals(source.next(), "Two");
+ assertTrue(source.hasNext());
+ assertEquals(source.next(), "Three");
+ assertTrue(source.hasNext());
+ assertEquals(source.next(), "Four");
+ assertTrue(source.hasNext());
+ assertTrue(source.hasNext()); // tricky!
+ assertEquals(source.next(), "Five");
+ assertFalse(source.hasNext());
+ assertFalse(source.hasNext()); // also tricky!
+ source.close();
+ assertFalse(source.hasNext()); // also also tricky!
+ assertFalse(source.hasNext()); // also also also tricky!
+ try {
+ source.next();
+ } catch (EOFException t) {
+ return;
+ }
+ fail("No exception thrown at end of iterator");
+ }
+
+ public void testEnumerationObjectSource() throws Throwable {
+ final ObjectSource<String> source = Streams.getEnumerationObjectSource(new Vector<String>(Arrays.asList("One", "Two", "Three", "Four", "Five")).elements());
+ assertTrue(source.hasNext());
+ assertEquals(source.next(), "One");
+ assertTrue(source.hasNext());
+ assertEquals(source.next(), "Two");
+ assertTrue(source.hasNext());
+ assertEquals(source.next(), "Three");
+ assertTrue(source.hasNext());
+ assertEquals(source.next(), "Four");
+ assertTrue(source.hasNext());
+ assertTrue(source.hasNext()); // tricky!
+ assertEquals(source.next(), "Five");
+ assertFalse(source.hasNext());
+ assertFalse(source.hasNext()); // also tricky!
+ source.close();
+ assertFalse(source.hasNext()); // also also tricky!
+ assertFalse(source.hasNext()); // also also also tricky!
+ try {
+ source.next();
+ } catch (EOFException t) {
+ return;
+ }
+ fail("No exception thrown at end of iterator");
+ }
+}
Added: remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestByteBufferAllocator.java
===================================================================
--- remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestByteBufferAllocator.java (rev 0)
+++ remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestByteBufferAllocator.java 2008-07-03 23:31:26 UTC (rev 4352)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.test.support;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.jboss.xnio.BufferAllocator;
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public final class TestByteBufferAllocator implements BufferAllocator<ByteBuffer> {
+
+ private final AtomicInteger count = new AtomicInteger();
+ private final int size;
+
+ public TestByteBufferAllocator(final int size) {
+ this.size = size;
+ }
+
+ public ByteBuffer allocate() {
+ final ByteBuffer buffer = ByteBuffer.allocate(size);
+ count.incrementAndGet();
+ return buffer;
+ }
+
+ public void free(final ByteBuffer buffer) {
+ if (buffer == null) {
+ throw new NullPointerException("buffer is null");
+ }
+ count.decrementAndGet();
+ }
+
+ public void check(int expectCount) {
+ TestCase.assertEquals(expectCount, count.get());
+ }
+}
Added: remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestCharBufferAllocator.java
===================================================================
--- remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestCharBufferAllocator.java (rev 0)
+++ remoting3/trunk/testing-support/src/main/java/org/jboss/cx/remoting/test/support/TestCharBufferAllocator.java 2008-07-03 23:31:26 UTC (rev 4352)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cx.remoting.test.support;
+
+import java.nio.CharBuffer;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.jboss.xnio.BufferAllocator;
+import junit.framework.TestCase;
+
+/**
+ *
+ */
+public final class TestCharBufferAllocator implements BufferAllocator<CharBuffer> {
+
+ private final AtomicInteger count = new AtomicInteger();
+ private final int size;
+
+ public TestCharBufferAllocator(final int size) {
+ this.size = size;
+ }
+
+ public CharBuffer allocate() {
+ final CharBuffer buffer = CharBuffer.allocate(size);
+ count.incrementAndGet();
+ return buffer;
+ }
+
+ public void free(final CharBuffer buffer) {
+ if (buffer == null) {
+ throw new NullPointerException("buffer is null");
+ }
+ count.decrementAndGet();
+ }
+
+ public void check(int expectCount) {
+ TestCase.assertEquals(expectCount, count.get());
+ }
+}
\ No newline at end of file
16 years, 6 months
JBoss Remoting SVN: r4351 - in remoting3/trunk: util/src/main/java/org/jboss/cx/remoting/util and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 19:31:01 -0400 (Thu, 03 Jul 2008)
New Revision: 4351
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java
Log:
Fix various minor bugs
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java 2008-07-03 18:37:32 UTC (rev 4350)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java 2008-07-03 23:31:01 UTC (rev 4351)
@@ -96,7 +96,9 @@
try {
final ByteBuffer buffer = current;
current = null;
- allocator.free(buffer);
+ if (buffer != null) {
+ allocator.free(buffer);
+ }
bufferSource.close();
} finally {
closed = true;
@@ -107,13 +109,16 @@
private ByteBuffer getBuffer() throws IOException {
final ByteBuffer buffer = current;
if (buffer == null) {
- if (bufferSource.hasNext()) {
+ while (bufferSource.hasNext()) {
final ByteBuffer newBuffer = bufferSource.next();
- current = newBuffer;
- return newBuffer;
- } else {
- return null;
+ if (newBuffer.hasRemaining()) {
+ current = newBuffer;
+ return newBuffer;
+ } else {
+ allocator.free(newBuffer);
+ }
}
+ return null;
} else {
return buffer;
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java 2008-07-03 18:37:32 UTC (rev 4350)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java 2008-07-03 23:31:01 UTC (rev 4351)
@@ -100,7 +100,9 @@
try {
final CharBuffer buffer = current;
current = null;
- allocator.free(buffer);
+ if (buffer != null) {
+ allocator.free(buffer);
+ }
bufferSource.close();
} finally {
closed = true;
@@ -147,13 +149,16 @@
private CharBuffer getBuffer() throws IOException {
final CharBuffer buffer = current;
if (buffer == null) {
- if (bufferSource.hasNext()) {
+ while (bufferSource.hasNext()) {
final CharBuffer newBuffer = bufferSource.next();
- current = newBuffer;
- return newBuffer;
- } else {
- return null;
+ if (newBuffer.hasRemaining()) {
+ current = newBuffer;
+ return newBuffer;
+ } else {
+ allocator.free(newBuffer);
+ }
}
+ return null;
} else {
return buffer;
}
Modified: remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java 2008-07-03 18:37:32 UTC (rev 4350)
+++ remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java 2008-07-03 23:31:01 UTC (rev 4351)
@@ -107,7 +107,7 @@
do {
final CharBuffer buffer = getBuffer();
final int rem = Math.min(len, buffer.remaining());
- buffer.put(str, off, rem);
+ buffer.put(str, off, off + rem);
if (! buffer.hasRemaining()) {
localFlush();
}
Modified: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java 2008-07-03 18:37:32 UTC (rev 4350)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java 2008-07-03 23:31:01 UTC (rev 4351)
@@ -578,7 +578,7 @@
public static <T> Iterable<T> reverse(final List<T> list) {
return new Iterable<T>() {
public Iterator<T> iterator() {
- return reverse(list.listIterator());
+ return reverse(list.listIterator(list.size()));
}
};
}
16 years, 6 months
JBoss Remoting SVN: r4350 - in remoting3/trunk: standalone/src/main/java/org/jboss/cx/remoting and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 14:37:32 -0400 (Thu, 03 Jul 2008)
New Revision: 4350
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
More cleanup, add general close-leak protection
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java 2008-07-03 17:08:28 UTC (rev 4349)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractAutoCloseable.java 2008-07-03 18:37:32 UTC (rev 4350)
@@ -38,7 +38,7 @@
private final AtomicInteger refcount = new AtomicInteger(1);
private final Executor executor;
- private static Logger log = Logger.getLogger(AbstractAutoCloseable.class);
+ private static final Logger log = Logger.getLogger(AbstractAutoCloseable.class);
protected AbstractAutoCloseable(final Executor executor) {
super(executor);
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java 2008-07-03 17:08:28 UTC (rev 4349)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java 2008-07-03 18:37:32 UTC (rev 4350)
@@ -26,6 +26,8 @@
import org.jboss.cx.remoting.RemotingException;
import org.jboss.cx.remoting.CloseHandler;
import org.jboss.cx.remoting.spi.SpiUtils;
+import org.jboss.xnio.IoUtils;
+import org.jboss.xnio.log.Logger;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executor;
@@ -36,6 +38,8 @@
*/
public abstract class AbstractCloseable<T> implements Closeable<T> {
+ private static final Logger log = Logger.getLogger(AbstractCloseable.class);
+
protected final Executor executor;
private final Object closeLock = new Object();
private final AtomicBoolean closed = new AtomicBoolean();
@@ -82,4 +86,15 @@
protected Executor getExecutor() {
return executor;
}
+
+ protected void finalize() throws Throwable {
+ try {
+ super.finalize();
+ } finally {
+ if (isOpen()) {
+ log.warn("Leaked a %s instance!", getClass().getName());
+ IoUtils.safeClose(this);
+ }
+ }
+ }
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-03 17:08:28 UTC (rev 4349)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-03 18:37:32 UTC (rev 4350)
@@ -81,10 +81,6 @@
// Lifecycle
- public void create() {
- // todo security check
- }
-
public void start() {
// todo security check
if (executor == null) {
@@ -104,10 +100,6 @@
// todo
}
- public void destroy() {
- executor = null;
- }
-
// Endpoint implementation
public ConcurrentMap<Object, Object> getAttributes() {
Modified: remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
===================================================================
--- remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03 17:08:28 UTC (rev 4349)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03 18:37:32 UTC (rev 4350)
@@ -1,7 +1,6 @@
package org.jboss.cx.remoting;
import java.io.IOException;
-import java.util.concurrent.ConcurrentMap;
import org.jboss.cx.remoting.core.EndpointImpl;
import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
@@ -15,19 +14,10 @@
public static Endpoint createEndpoint(String name) throws IOException {
synchronized (lifecycle) {
- boolean ok = false;
final EndpointImpl endpointImpl = new EndpointImpl();
endpointImpl.setName(name);
- endpointImpl.create();
- try {
- endpointImpl.start();
- ok = true;
- return endpointImpl;
- } finally {
- if (! ok) {
- endpointImpl.destroy();
- }
- }
+ endpointImpl.start();
+ return endpointImpl;
}
}
@@ -35,9 +25,7 @@
synchronized (lifecycle) {
if (endpoint instanceof EndpointImpl) {
final EndpointImpl endpointImpl = (EndpointImpl) endpoint;
- final ConcurrentMap<Object, Object> attributes = endpointImpl.getAttributes();
endpointImpl.stop();
- endpointImpl.destroy();
}
}
}
16 years, 6 months
JBoss Remoting SVN: r4349 - in remoting3/trunk: standalone/src/main/java/org/jboss/cx/remoting and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 13:08:28 -0400 (Thu, 03 Jul 2008)
New Revision: 4349
Modified:
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java
remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
Convenience method to cleanly/safely create a client
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java 2008-07-03 14:19:31 UTC (rev 4348)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalBasicExampleMain.java 2008-07-03 17:08:28 UTC (rev 4349)
@@ -19,7 +19,7 @@
final StringRot13RequestListener listener = new StringRot13RequestListener();
final Endpoint endpoint = Remoting.createEndpoint("simple");
try {
- final Client<String,String> client = endpoint.createClient(listener).getClient();
+ final Client<String,String> client = Remoting.createLocalClient(endpoint, listener);
try {
final String original = "The Secret Message\n";
final String result = client.invoke(original);
Modified: remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java 2008-07-03 14:19:31 UTC (rev 4348)
+++ remoting3/trunk/samples/src/main/java/org/jboss/cx/remoting/samples/simple/LocalStreamExampleMain.java 2008-07-03 17:08:28 UTC (rev 4349)
@@ -25,7 +25,7 @@
final StreamingRot13RequestListener listener = new StreamingRot13RequestListener();
final Endpoint endpoint = Remoting.createEndpoint("simple");
try {
- final Client<Reader,Reader> client = endpoint.createClient(listener).getClient();
+ final Client<Reader,Reader> client = Remoting.createLocalClient(endpoint, listener);
try {
final String original = "The Secret Message\n";
final StringReader originalReader = new StringReader(original);
Modified: remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
===================================================================
--- remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03 14:19:31 UTC (rev 4348)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03 17:08:28 UTC (rev 4349)
@@ -3,6 +3,8 @@
import java.io.IOException;
import java.util.concurrent.ConcurrentMap;
import org.jboss.cx.remoting.core.EndpointImpl;
+import org.jboss.cx.remoting.spi.remote.RemoteClientEndpoint;
+import org.jboss.cx.remoting.spi.remote.RemoteServiceEndpoint;
/**
*
@@ -40,6 +42,24 @@
}
}
+ public static <I, O> Client<I, O> createLocalClient(Endpoint endpoint, RequestListener<I, O> requestListener) throws RemotingException {
+ final RemoteClientEndpoint<I, O> clientEndpoint = endpoint.createClient(requestListener);
+ try {
+ return clientEndpoint.getClient();
+ } finally {
+ clientEndpoint.autoClose();
+ }
+ }
+
+ public static <I, O> ClientSource<I, O> createLocalClientSource(Endpoint endpoint, RequestListener<I, O> requestListener) throws RemotingException {
+ final RemoteServiceEndpoint<I, O> clientEndpoint = endpoint.createService(requestListener);
+ try {
+ return clientEndpoint.getClientSource();
+ } finally {
+ clientEndpoint.autoClose();
+ }
+ }
+
// privates
private Remoting() { /* empty */ }
16 years, 6 months
JBoss Remoting SVN: r4348 - remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 10:19:31 -0400 (Thu, 03 Jul 2008)
New Revision: 4348
Removed:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AbstractTypeMap.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/HashTypeMap.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/LinkedHashTypeMap.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/TypeMap.java
Log:
Yet more cleanup
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AbstractTypeMap.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AbstractTypeMap.java 2008-07-03 14:16:42 UTC (rev 4347)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AbstractTypeMap.java 2008-07-03 14:19:31 UTC (rev 4348)
@@ -1,232 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- *
- */
-public abstract class AbstractTypeMap<B> implements TypeMap<B> {
- private final ConcurrentMap<Class<? extends B>, B> map;
- private final Set<Entry<? extends B>> entrySet;
-
- protected AbstractTypeMap(ConcurrentMap<Class<? extends B>, B> map) {
- if (map == null) {
- throw new NullPointerException("map is null");
- }
- this.map = map;
- entrySet = new EntrySet();
- }
-
- protected AbstractTypeMap(Map<Class<? extends B>, B> map) {
- if (map == null) {
- throw new NullPointerException("map is null");
- }
- this.map = new AtomicMap<Class<? extends B>, B>(map);
- entrySet = new EntrySet();
- }
-
- public void clear() {
- map.clear();
- }
-
- public boolean containsKey(final Class<?> key) {
- return map.containsKey(key);
- }
-
- public boolean containsValue(final Object value) {
- // since we key by type, we can do an O(1) search for value!
- // todo - unless the given value is stored at a key of one of its super-types
- final Class<? extends Object> claxx = value.getClass();
- return map.containsKey(claxx) && isEqual(value, map.get(claxx));
- }
-
- private static boolean isEqual(final Object a, final Object b) {
- return (a == null) == (b == null) && (a == null || a.equals(b));
- }
-
- public Set<Entry<? extends B>> entrySet() {
- return entrySet;
- }
-
- @SuppressWarnings ({"unchecked"})
- public <T extends B> T get(final Class<T> key) {
- return (T) map.get(key);
- }
-
- public boolean isEmpty() {
- return map.isEmpty();
- }
-
- public Set<Class<? extends B>> keySet() {
- return map.keySet();
- }
-
- @SuppressWarnings ({"unchecked"})
- public <T extends B> T put(final Class<T> key, final T value) {
- return (T) map.put(key, value);
- }
-
- public <T extends B> void putAll(final TypeMap<T> m) {
- for (Entry<? extends T> e : m.entrySet()) {
- map.put(e.getKey(), e.getValue());
- }
- }
-
- @SuppressWarnings ({"unchecked"})
- public <T extends B> T remove(final Class<T> key) {
- return (T) map.remove(key);
- }
-
- public int size() {
- return map.size();
- }
-
- public Collection<? extends B> values() {
- return map.values();
- }
-
- @SuppressWarnings ({"unchecked"})
- public <T extends B> T putIfAbsent(final Class<T> key, final T value) {
- return (T) map.putIfAbsent(key, value);
- }
-
- public <T extends B> boolean remove(final Class<T> key, final Object value) {
- return map.remove(key, value);
- }
-
- @SuppressWarnings ({"unchecked"})
- public <T extends B> T replace(final Class<T> key, final T value) {
- return (T) map.replace(key, value);
- }
-
- public <T extends B> boolean replace(final Class<T> key, final T oldValue, final T newValue) {
- return map.replace(key, oldValue, newValue);
- }
-
- private final class EntrySet implements Set<Entry<? extends B>> {
- private final Set<Map.Entry<Class<? extends B>,B>> entries = map.entrySet();
-
- private EntrySet() {
- }
-
- public int size() {
- return entries.size();
- }
-
- public boolean isEmpty() {
- return entries.isEmpty();
- }
-
- public boolean contains(final Object o) {
- // containsValue(T)==true implies containsKey(T.class)==true
- return o instanceof Entry && map.containsValue(((Entry<?>) o).getValue());
- }
-
- public Iterator<Entry<? extends B>> iterator() {
- return new EntryIterator();
- }
-
- public Object[] toArray() {
- throw new UnsupportedOperationException("toArray() not allowed");
- }
-
- public <T> T[] toArray(final T[] a) {
- throw new UnsupportedOperationException("toArray() not allowed");
- }
-
- public boolean add(final Entry<? extends B> o) {
- throw new UnsupportedOperationException("add() not allowed");
- }
-
- @SuppressWarnings ({"unchecked"})
- public boolean remove(final Object o) {
- if (! (o instanceof Entry)) {
- return false;
- }
- Class<? extends B> key = ((Entry<? extends B>)o).getKey();
- final Object value = ((Entry<? extends B>) o).getValue();
- return AbstractTypeMap.this.remove(key, value);
- }
-
- public boolean containsAll(final Collection<?> c) {
- for (Object x : c) {
- if (! contains(x)) {
- return false;
- }
- }
- return true;
- }
-
- public boolean addAll(final Collection<? extends Entry<? extends B>> c) {
- throw new UnsupportedOperationException("addAll() not allowed");
- }
-
- public boolean retainAll(final Collection<?> c) {
- throw new UnsupportedOperationException("retainAll() not allowed");
- }
-
- public boolean removeAll(final Collection<?> c) {
- throw new UnsupportedOperationException("removeAll() not allowed");
- }
-
- public void clear() {
- map.clear();
- }
- }
-
- private final class EntryIterator implements Iterator<Entry<? extends B>> {
- private final Iterator<Map.Entry<Class<? extends B>,B>> iterator = map.entrySet().iterator();
-
- private EntryIterator() {}
-
- public boolean hasNext() {
- return iterator.hasNext();
- }
-
- @SuppressWarnings ({"unchecked"})
- public Entry<? extends B> next() {
- return new EntryImpl(iterator.next());
- }
-
- public void remove() {
- iterator.remove();
- }
- }
-
- private final class EntryImpl<Z> implements Entry<Z> {
- private final Map.Entry<Class<Z>, Z> entry;
-
- public EntryImpl(final Map.Entry<Class<Z>, Z> entry) {
- this.entry = entry;
- }
-
- public Class<Z> getKey() {
- return entry.getKey();
- }
-
- public Z getValue() {
- return entry.getValue();
- }
-
- public Z setValue(final Z value) {
- return entry.setValue(value);
- }
-
- public boolean equals(Object obj) {
- if (obj instanceof Entry) {
- Entry<?> other = (Entry<?>) obj;
- return isEqual(other.getKey(), entry.getKey()) && isEqual(other.getValue(), entry.getValue());
- } else {
- return false;
- }
- }
-
- public int hashCode() {
- return entry.hashCode();
- }
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/HashTypeMap.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/HashTypeMap.java 2008-07-03 14:16:42 UTC (rev 4347)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/HashTypeMap.java 2008-07-03 14:19:31 UTC (rev 4348)
@@ -1,12 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.util.HashMap;
-
-/**
- *
- */
-public final class HashTypeMap<B> extends AbstractTypeMap<B> {
- public HashTypeMap() {
- super(new HashMap<Class<? extends B>, B>());
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/LinkedHashTypeMap.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/LinkedHashTypeMap.java 2008-07-03 14:16:42 UTC (rev 4347)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/LinkedHashTypeMap.java 2008-07-03 14:19:31 UTC (rev 4348)
@@ -1,12 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.util.LinkedHashMap;
-
-/**
- *
- */
-public final class LinkedHashTypeMap<B> extends AbstractTypeMap<B> {
- public LinkedHashTypeMap() {
- super(new LinkedHashMap<Class<? extends B>, B>());
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/TypeMap.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/TypeMap.java 2008-07-03 14:16:42 UTC (rev 4347)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/TypeMap.java 2008-07-03 14:19:31 UTC (rev 4348)
@@ -1,45 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A map with classes for keys.
- */
-public interface TypeMap<B> {
- void clear();
-
- boolean containsKey(Class<?> key);
-
- boolean containsValue(Object value);
-
- Set<Entry<? extends B>> entrySet();
-
- <T extends B> T get(Class<T> key);
-
- boolean isEmpty();
-
- Set<Class<? extends B>> keySet();
-
- <T extends B> T put(Class<T> key, T value);
-
- <T extends B> void putAll(TypeMap<T> m);
-
- <T extends B> T remove(Class<T> key);
-
- int size();
-
- Collection<? extends B> values();
-
- <T extends B> T putIfAbsent(Class<T> key, T value);
-
- <T extends B> boolean remove(Class<T> key, Object value);
-
- <T extends B> T replace(Class<T> key, T value);
-
- <T extends B> boolean replace(Class<T> key, T oldValue, T newValue);
-
- interface Entry<T> extends Map.Entry<Class<T>, T> {
- }
-}
16 years, 6 months
JBoss Remoting SVN: r4347 - in remoting3/trunk: http/src/main/java/org/jboss/cx/remoting/http and 3 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 10:16:42 -0400 (Thu, 03 Jul 2008)
New Revision: 4347
Removed:
remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java
remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/AbstractHttpUrlChannel.java
remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/HttpUrlChannel.java
remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/HttpsUrlChannel.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/AbstractHttpChannel.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/AbstractHttpMessageWriter.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/Http.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/HttpMessageWriter.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpChannelContext.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpServerContext.java
remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/impl/
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AbstractOutputStreamByteMessageOutput.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ByteMessageInput.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ByteMessageOutput.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/DataMessageInput.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/DataMessageOutput.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/InputStreamByteMessageInput.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ObjectMessageInput.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ObjectMessageOutput.java
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSourceStreamSerializerFactory.java
Log:
More cleanup
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSourceStreamSerializerFactory.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSourceStreamSerializerFactory.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/stream/ObjectSourceStreamSerializerFactory.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,11 +1,6 @@
package org.jboss.cx.remoting.core.stream;
import java.io.IOException;
-import java.util.LinkedList;
-import java.util.NoSuchElementException;
-import java.util.Queue;
-import org.jboss.cx.remoting.util.ObjectMessageInput;
-import org.jboss.cx.remoting.util.ObjectMessageOutput;
import org.jboss.cx.remoting.spi.stream.StreamSerializerFactory;
import org.jboss.cx.remoting.spi.marshal.MarshallerFactory;
import org.jboss.cx.remoting.stream.ObjectSource;
Deleted: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/AbstractHttpChannel.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/AbstractHttpChannel.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/AbstractHttpChannel.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,93 +0,0 @@
-package org.jboss.cx.remoting.http;
-
-import org.jboss.cx.remoting.http.RemotingHttpChannelContext;
-
-/**
- *
- */
-public abstract class AbstractHttpChannel {
-
- protected AbstractHttpChannel() {
- }
-
- // Configuration
-
- private int localParkTime = -1;
- private int remoteParkTime = -1;
-
- /**
- * Get the amount of time that a given channel member may be locally parked. A value of {@code -1} means "park
- * indefinitely". A value of {@code 0} means "do not park". Otherwise the value is interpreted as milliseconds.
- *
- * In the case of an HTTP server, the minimum of this time and the client-requested timeout should be used.
- *
- * @return the local park time
- */
- public int getLocalParkTime() {
- return localParkTime;
- }
-
- /**
- * Set the amount of time that a given channel member may be locally parked. A value of {@code -1} means "park
- * indefinitely". A value of {@code 0} means "do not park". Otherwise the value is interpreted as milliseconds.
- *
- * In the case of an HTTP server, the minimum of this time and the client-requested timeout should be used.
- *
- * @param localParkTime the local park time
- */
- public void setLocalParkTime(final int localParkTime) {
- this.localParkTime = localParkTime;
- }
-
- /**
- * Get the amount of time that a given channel member may be remotely parked. A value of {@code -1} means "park
- * indefinitely". A value of {@code 0} means "do not park". Otherwise the value is interpreted as milliseconds.
- *
- * @return the remote park time
- */
- public int getRemoteParkTime() {
- return remoteParkTime;
- }
-
- /**
- * Set the amount of time that a given channel member may be remotely parked. A value of {@code -1} means "park
- * indefinitely". A value of {@code 0} means "do not park". Otherwise the value is interpreted as milliseconds.
- *
- * @param remoteParkTime the remote park time
- */
- public void setRemoteParkTime(final int remoteParkTime) {
- this.remoteParkTime = remoteParkTime;
- }
-
- // Dependencies
-
- private RemotingHttpChannelContext channelContext;
-
- public RemotingHttpChannelContext getChannelContext() {
- return channelContext;
- }
-
- public void setChannelContext(final RemotingHttpChannelContext channelContext) {
- this.channelContext = channelContext;
- }
-
- // Lifecycle
-
- public void create() {
- if (channelContext == null) {
- throw new NullPointerException("channelContext is null");
- }
- }
-
- public void start() {
-
- }
-
- public void stop() {
-
- }
-
- public void destroy() {
-
- }
-}
Deleted: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/AbstractHttpMessageWriter.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/AbstractHttpMessageWriter.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/AbstractHttpMessageWriter.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,8 +0,0 @@
-package org.jboss.cx.remoting.http;
-
-/**
- *
- */
-public abstract class AbstractHttpMessageWriter implements HttpMessageWriter {
-
-}
Deleted: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/Http.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/Http.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/Http.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,34 +0,0 @@
-package org.jboss.cx.remoting.http;
-
-/**
- *
- */
-public final class Http {
- private Http() {}
-
- enum MessageType {
- SESSION_OPEN,
- SESSION_JOIN,
- SESSION_CLOSE,
-
- STREAM_OPEN,
- STREAM_CLOSE,
- STREAM_DATA,
-
- SERVICE_CLOSING,
-
- SERVICE_CLOSE,
- SERVICE_CONTEXT_OPEN,
-
- CONTEXT_CLOSE,
-
- CONTEXT_CLOSING,
-
- REQUEST,
- REQUEST_CANCEL,
-
- REQUEST_REPLY,
- REQUEST_EXCEPTION,
- REQUEST_CANCELLED,
- }
-}
Deleted: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/HttpMessageWriter.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/HttpMessageWriter.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/HttpMessageWriter.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,11 +0,0 @@
-package org.jboss.cx.remoting.http;
-
-import java.io.IOException;
-import org.jboss.cx.remoting.util.ByteMessageOutput;
-
-/**
- *
- */
-public interface HttpMessageWriter {
- void writeMessageData(ByteMessageOutput byteOutput) throws IOException;
-}
Deleted: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpChannelContext.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpChannelContext.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpChannelContext.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,25 +0,0 @@
-package org.jboss.cx.remoting.http;
-
-import org.jboss.cx.remoting.util.ByteMessageInput;
-
-/**
- *
- */
-public interface RemotingHttpChannelContext {
- /**
- * Process an HTTP message that has arrived.
- *
- * @param input the source of the message data
- */
- void processInboundMessage(ByteMessageInput input);
-
- /**
- * Wait for an outgoing HTTP message to become available, up to a certain time limit. If no message is available
- * within the specified time limit, or if the thread is interrupted before a message could become available, return
- * an empty message.
- *
- * @param millis the amount of time to wait in millseconds, {@code 0} to not wait, or {@code -1} to wait indefinitely.
- * @return an outgoing HTTP message
- */
- HttpMessageWriter waitForOutgoingHttpMessage(int millis);
-}
Deleted: remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpServerContext.java
===================================================================
--- remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpServerContext.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/http/src/main/java/org/jboss/cx/remoting/http/RemotingHttpServerContext.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,10 +0,0 @@
-package org.jboss.cx.remoting.http;
-
-import org.jboss.cx.remoting.util.ByteMessageInput;
-
-/**
- *
- */
-public interface RemotingHttpServerContext {
- RemotingHttpChannelContext processUnsolicitedInboundMessage(ByteMessageInput messageInput);
-}
Deleted: remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java
===================================================================
--- remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/http-se6/src/main/java/org/jboss/cx/remoting/http/se6/SunHttpServerChannel.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,179 +0,0 @@
-package org.jboss.cx.remoting.http.se6;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.List;
-import java.util.Random;
-import java.util.concurrent.ConcurrentMap;
-import java.security.SecureRandom;
-import org.jboss.cx.remoting.http.AbstractHttpChannel;
-import org.jboss.cx.remoting.http.HttpMessageWriter;
-import org.jboss.cx.remoting.http.RemotingHttpChannelContext;
-import org.jboss.cx.remoting.http.RemotingHttpServerContext;
-import org.jboss.cx.remoting.util.AbstractOutputStreamByteMessageOutput;
-import org.jboss.cx.remoting.util.CollectionUtil;
-import org.jboss.cx.remoting.util.InputStreamByteMessageInput;
-import org.jboss.xnio.IoUtils;
-
-import com.sun.net.httpserver.Headers;
-import com.sun.net.httpserver.HttpContext;
-import com.sun.net.httpserver.HttpExchange;
-import com.sun.net.httpserver.HttpHandler;
-
-/**
- *
- */
-public final class SunHttpServerChannel extends AbstractHttpChannel implements HttpHandler {
-
- public SunHttpServerChannel() {
- }
-
- // Configuration
-
- private CookieParser cookieParser;
-
- public CookieParser getCookieParser() {
- return cookieParser;
- }
-
- public void setCookieParser(final CookieParser cookieParser) {
- this.cookieParser = cookieParser;
- }
-
- // Dependencies
-
- private RemotingHttpServerContext serverContext;
- private HttpContext httpContext;
- private Random random;
-
- public RemotingHttpServerContext getServerContext() {
- return serverContext;
- }
-
- public void setServerContext(final RemotingHttpServerContext serverContext) {
- this.serverContext = serverContext;
- }
-
- public HttpContext getHttpContext() {
- return httpContext;
- }
-
- public void setHttpContext(final HttpContext httpContext) {
- this.httpContext = httpContext;
- }
-
- public Random getRandom() {
- return random;
- }
-
- public void setRandom(final Random random) {
- this.random = random;
- }
-
- // Lifecycle
-
- public void create() {
- if (serverContext == null) {
- throw new NullPointerException("serverContext is null");
- }
- if (random == null) {
- random = new SecureRandom();
- }
- }
-
- public void start() {
- httpContext.setHandler(this);
- }
-
- public void stop() {
- httpContext.setHandler(new HttpHandler() {
- public void handle(final HttpExchange exchange) throws IOException {
- throw new IOException("Context is not available");
- }
- });
- }
-
- public void destroy() {
- serverContext = null;
- httpContext = null;
- random = null;
- }
-
- // Implementation
-
- private final ConcurrentMap<String, RemotingHttpChannelContext> sessions = CollectionUtil.concurrentMap();
-
- public void handle(final HttpExchange exchange) throws IOException {
- // it could be a non-https exchange (in the case of a separate SSL frontend)
- final boolean secure = "https".equals(exchange.getProtocol());
- final Headers requestHeader = exchange.getRequestHeaders();
- final List<String> cookieHeaders = requestHeader.get("Cookie");
- int parkTimeout = -1;
- String sessionId = null;
- for (String cookieString : cookieHeaders) {
- final List<Cookie> cookies = cookieParser.parseCookie(cookieString);
- for (Cookie cookie : cookies) {
- if ("Park-Timeout".equals(cookie.getName())) {
- try {
- parkTimeout = Integer.parseInt(cookie.getValue());
- } catch (NumberFormatException e) {
- // oh well
- }
- } else if ("JSESSIONID".equals(cookie.getName())) {
- sessionId = cookie.getValue();
- }
- }
- }
- final boolean needToSetSession;
- RemotingHttpChannelContext context = sessions.get(sessionId);
- final InputStream inputStream = exchange.getRequestBody();
- try {
- if (context == null) {
- needToSetSession = true;
- context = serverContext.processUnsolicitedInboundMessage(new InputStreamByteMessageInput(inputStream, -1));
- } else {
- needToSetSession = false;
- context.processInboundMessage(new InputStreamByteMessageInput(inputStream, -1));
- }
- } finally {
- IoUtils.safeClose(inputStream);
- }
- if (needToSetSession) {
- final StringBuilder setCookieBuilder = new StringBuilder(60);
- setCookieBuilder.append("JSESSIONID=");
- for (;;) {
- String jsessionid = generateSessionId();
- if (sessions.putIfAbsent(jsessionid, context) == null) {
- setCookieBuilder.append(jsessionid);
- break;
- }
- }
- if (secure) {
- setCookieBuilder.append("; secure");
- }
- exchange.getResponseHeaders().set("Set-Cookie", setCookieBuilder.toString());
- }
- final HttpMessageWriter messageWriter = context.waitForOutgoingHttpMessage(parkTimeout);
- final OutputStream outputStream = exchange.getResponseBody();
- try {
- messageWriter.writeMessageData(new AbstractOutputStreamByteMessageOutput(outputStream) {
- public void commit() throws IOException {
- }
- });
- } finally {
- IoUtils.safeClose(outputStream);
- }
- }
-
- private String generateSessionId() {
- final byte[] bytes = new byte[16];
- StringBuilder builder = new StringBuilder(bytes.length * 2);
- random.nextBytes(bytes);
- for (byte b : bytes) {
- builder.append(Character.forDigit(b >>> 4 & 15, 16));
- builder.append(Character.forDigit(b & 15, 16));
- }
- return builder.toString();
- }
-}
Deleted: remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/AbstractHttpUrlChannel.java
===================================================================
--- remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/AbstractHttpUrlChannel.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/AbstractHttpUrlChannel.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,236 +0,0 @@
-package org.jboss.cx.remoting.http.urlconnection;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.List;
-import java.util.concurrent.Executor;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.FutureTask;
-import java.util.concurrent.Future;
-import org.jboss.cx.remoting.http.AbstractHttpChannel;
-import org.jboss.cx.remoting.http.HttpMessageWriter;
-import org.jboss.cx.remoting.http.RemotingHttpChannelContext;
-import org.jboss.xnio.log.Logger;
-import org.jboss.cx.remoting.util.AbstractOutputStreamByteMessageOutput;
-import org.jboss.cx.remoting.util.NamingThreadFactory;
-import org.jboss.cx.remoting.util.InputStreamByteMessageInput;
-import org.jboss.xnio.IoUtils;
-
-/**
- *
- */
-public abstract class AbstractHttpUrlChannel extends AbstractHttpChannel {
-
- private static final Logger log = Logger.getLogger(AbstractHttpUrlChannel.class);
-
- private final CookieClientSession cookieClientSession = new CookieClientSession();
-
- protected AbstractHttpUrlChannel() {
- }
-
- // Configuration
-
- private int concurrentRequests = 2;
- private int connectTimeout = 5000;
- private int readTimeout = 0; // Default to unlimited to support "parking" the connection at the other end
- private int errorBackoffTime = 5000;
- private URL connectUrl;
-
- public int getConcurrentRequests() {
- return concurrentRequests;
- }
-
- public void setConcurrentRequests(final int concurrentRequests) {
- this.concurrentRequests = concurrentRequests;
- }
-
- public int getConnectTimeout() {
- return connectTimeout;
- }
-
- public void setConnectTimeout(final int connectTimeout) {
- this.connectTimeout = connectTimeout;
- }
-
- public int getReadTimeout() {
- return readTimeout;
- }
-
- public void setReadTimeout(final int readTimeout) {
- this.readTimeout = readTimeout;
- }
-
- public int getErrorBackoffTime() {
- return errorBackoffTime;
- }
-
- public void setErrorBackoffTime(final int errorBackoffTime) {
- this.errorBackoffTime = errorBackoffTime;
- }
-
- public URL getConnectUrl() {
- return connectUrl;
- }
-
- public void setConnectUrl(final URL connectUrl) {
- this.connectUrl = connectUrl;
- }
-
- // Dependencies
-
- private Executor executor;
-
- public Executor getExecutor() {
- return executor;
- }
-
- public void setExecutor(final Executor executor) {
- this.executor = executor;
- }
-
- // Lifecycle
-
- private ExecutorService executorService;
- private Future[] futures;
-
- public void create() {
- super.create();
- if (executor == null) {
- executor = executorService = Executors.newFixedThreadPool(concurrentRequests, new NamingThreadFactory(Executors.defaultThreadFactory(), "Remoting HTTP client %s"));
- }
- if (connectUrl == null) {
- throw new NullPointerException("connectUrl is null");
- }
- }
-
- public void start() {
- final Future[] futures = new Future[concurrentRequests];
- for (int i = 0; i < futures.length; i++) {
- final FutureTask task = new FutureTask<Void>(null) {
- public void run() {
- while (! isCancelled()) try {
- handleRequest();
- } catch (Throwable t) {
- log.trace(t, "Request hander failed");
- }
- }
- };
- executor.execute(task);
- futures[i] = task;
- }
- this.futures = futures;
- }
-
- public void stop() {
- if (futures != null) {
- final Future[] futures = this.futures;
- this.futures = null;
- for (Future future : futures) try {
- future.cancel(true);
- } catch (Throwable t) {
- log.trace(t, "Error cancelling task");
- }
- }
- }
-
- public void destroy() {
- try {
- super.destroy();
- } finally {
- if (executorService != null) {
- executorService.shutdown();
- }
- }
- executor = executorService = null;
- }
-
- // Interface
-
- protected void handleRequest() {
- final URL connectUrl = getConnectUrl();
- final RemotingHttpChannelContext channelContext = getChannelContext();
- final int localParkTime = getLocalParkTime();
- final int remoteParkTime = getRemoteParkTime();
- final HttpMessageWriter messageWriter = channelContext.waitForOutgoingHttpMessage(localParkTime);
- try {
- final HttpURLConnection httpConnection = intializeConnection(connectUrl);
- try {
- if (remoteParkTime >= 0) {
- httpConnection.addRequestProperty("Park-Timeout", Integer.toString(remoteParkTime));
- }
- httpConnection.connect();
- final OutputStream outputStream = httpConnection.getOutputStream();
- try {
- messageWriter.writeMessageData(new AbstractOutputStreamByteMessageOutput(outputStream) {
- public void commit() throws IOException {
- }
- });
- // now read the reply
- final String responseMessage = httpConnection.getResponseMessage();
- log.trace("HTTP server sent back a response message: %s", responseMessage);
- final List<String> setCookies = httpConnection.getHeaderFields().get("Set-Cookie");
- for (String s : setCookies) {
- cookieClientSession.handleSetCookieHeader(s, connectUrl.getHost(), connectUrl.getPath());
- }
- final InputStream inputStream = httpConnection.getInputStream();
- try {
- channelContext.processInboundMessage(new InputStreamByteMessageInput(inputStream, -1));
- } finally {
- IoUtils.safeClose(inputStream);
- }
- } finally {
- IoUtils.safeClose(outputStream);
- }
- } catch (IOException e) {
- // probably a HTTP error occurred, so let's consume it
- try {
- final InputStream errorStream = httpConnection.getErrorStream();
- if (errorStream != null) try {
- // consume & discard the error stream
- while (errorStream.read() > -1);
- errorStream.close();
- } finally {
- IoUtils.safeClose(errorStream);
- } else {
- log.trace(e, "Connection failed but there is no error stream");
- }
- } catch (IOException e2) {
- log.trace(e2, "Error consuming the error stream from remote URL '%s'", connectUrl);
- }
- final int time = errorBackoffTime;
- if (time > 0) {
- try {
- log.debug("HTTP error occurred; backing off for %d milliseconds", Integer.valueOf(time));
- Thread.sleep(time);
- } catch (InterruptedException e1) {
- log.trace("Thread interrupted while waiting for error backoff time to expire");
- Thread.currentThread().interrupt();
- }
- }
- }
- } catch (IOException e) {
- log.trace(e, "Error establishing connection");
- }
- }
-
- protected HttpURLConnection intializeConnection(final URL connectUrl) throws IOException {
- final HttpURLConnection httpConnection = (HttpURLConnection) connectUrl.openConnection();
- httpConnection.setDoInput(true);
- httpConnection.setDoOutput(true);
- httpConnection.setDefaultUseCaches(false);
- httpConnection.setUseCaches(false);
- httpConnection.setInstanceFollowRedirects(false);
- httpConnection.setConnectTimeout(getConnectTimeout());
- httpConnection.setReadTimeout(getReadTimeout());
- httpConnection.setRequestMethod("POST"); // All remoting requests are POST
- final String cookieHeader = cookieClientSession.getCookieHeader(connectUrl.getHost(), connectUrl.getPath(), false);
- if (cookieHeader != null) {
- httpConnection.setRequestProperty("Cookie", cookieHeader);
- }
- return httpConnection;
- }
-}
Deleted: remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/HttpUrlChannel.java
===================================================================
--- remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/HttpUrlChannel.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/HttpUrlChannel.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,16 +0,0 @@
-package org.jboss.cx.remoting.http.urlconnection;
-
-/**
- *
- */
-public final class HttpUrlChannel extends AbstractHttpUrlChannel {
-
- // lifecycle
-
- public void create() {
- final String protocol = getConnectUrl().getProtocol();
- if (! "http".equals(protocol)) {
- throw new IllegalArgumentException("Cannot use " + HttpUrlChannel.class.getName() + " for protocol \"" + protocol + "\"");
- }
- }
-}
Deleted: remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/HttpsUrlChannel.java
===================================================================
--- remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/HttpsUrlChannel.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/http-urlconnection/src/main/java/org/jboss/cx/remoting/http/urlconnection/HttpsUrlChannel.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,81 +0,0 @@
-package org.jboss.cx.remoting.http.urlconnection;
-
-import java.io.IOException;
-import java.net.URL;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSocketFactory;
-
-/**
- *
- */
-public final class HttpsUrlChannel extends AbstractHttpUrlChannel {
-
- // Configuration
-
- private HostnameVerifier hostnameVerifier;
- private SSLSocketFactory sslSocketFactory;
-
- public HostnameVerifier getHostnameVerifier() {
- return hostnameVerifier;
- }
-
- public void setHostnameVerifier(final HostnameVerifier hostnameVerifier) {
- this.hostnameVerifier = hostnameVerifier;
- }
-
- public SSLSocketFactory getSslSocketFactory() {
- return sslSocketFactory;
- }
-
- public void setSslSocketFactory(final SSLSocketFactory sslSocketFactory) {
- this.sslSocketFactory = sslSocketFactory;
- }
-
- // Dependencies
-
-
-
- // Lifecycle
-
- public void create() {
- super.create();
- if (hostnameVerifier == null) {
- hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
- }
- if (sslSocketFactory == null) {
- sslSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
- }
- final String protocol = getConnectUrl().getProtocol();
- if (! "https".equals(protocol)) {
- throw new IllegalArgumentException("Cannot use " + HttpsUrlChannel.class.getName() + " for protocol \"" + protocol + "\"");
- }
- }
-
- public void start() {
- super.start();
- }
-
- public void stop() {
- super.stop();
- }
-
- public void destroy() {
- try {
- super.destroy();
- } finally {
- hostnameVerifier = null;
- sslSocketFactory = null;
- }
- }
-
- // Interface
-
- protected HttpsURLConnection intializeConnection(final URL connectUrl) throws IOException {
- final HttpsURLConnection httpsURLConnection = (HttpsURLConnection) super.intializeConnection(connectUrl);
- httpsURLConnection.setHostnameVerifier(hostnameVerifier);
- httpsURLConnection.setSSLSocketFactory(sslSocketFactory);
- return httpsURLConnection;
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AbstractOutputStreamByteMessageOutput.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AbstractOutputStreamByteMessageOutput.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/AbstractOutputStreamByteMessageOutput.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,46 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.io.OutputStream;
-import java.io.IOException;
-
-/**
- *
- */
-public abstract class AbstractOutputStreamByteMessageOutput implements ByteMessageOutput {
- private final OutputStream outputStream;
- private int count;
-
- protected AbstractOutputStreamByteMessageOutput(final OutputStream outputStream) {
- if (outputStream == null) {
- throw new NullPointerException("outputStream is null");
- }
- this.outputStream = outputStream;
- }
-
- public void write(final int b) throws IOException {
- outputStream.write(b);
- count ++;
- }
-
- public void write(final byte[] b) throws IOException {
- outputStream.write(b);
- count += b.length;
- }
-
- public void write(final byte[] b, final int offs, final int len) throws IOException {
- outputStream.write(b, offs, len);
- count += len;
- }
-
- public int getBytesWritten() throws IOException {
- return count;
- }
-
- public void close() throws IOException {
- outputStream.close();
- }
-
- public void flush() throws IOException {
- outputStream.flush();
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ByteMessageInput.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ByteMessageInput.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ByteMessageInput.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,44 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.io.Closeable;
-import java.io.IOException;
-
-/**
- * A readable source of byte data.
- */
-public interface ByteMessageInput extends Closeable {
- /**
- * Read one byte.
- *
- * @return the byte, or -1 if the end of the stream has been reached.
- * @throws IOException if an I/O error occurs
- */
- int read() throws IOException;
-
- /**
- * Read a series of bytes into an array.
- *
- * @param data the array into which data is to be read
- * @return the total number of bytes read, or -1 if there are no bytes remaining to read
- * @throws IOException if an I/O error occurs
- */
- int read(byte[] data) throws IOException;
-
- /**
- * Read a series of bytes into an array.
- *
- * @param data the array into which data is to be read
- * @param offs the start offset in the {@code data} array at which the data is written
- * @param len the maximum number of bytes to read
- * @return the total number of bytes read, or -1 if there are no bytes remaining to read
- * @throws IOException if an I/O error occurs
- */
- int read(byte[] data, int offs, int len) throws IOException;
-
- /**
- * Return the number of bytes remaining.
- *
- * @return the number of bytes, or -1 if the byte count cannot be determined
- */
- int remaining();
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ByteMessageOutput.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ByteMessageOutput.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ByteMessageOutput.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,52 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.io.Closeable;
-import java.io.Flushable;
-import java.io.IOException;
-
-/**
- * A writable destination for byte data.
- */
-public interface ByteMessageOutput extends Closeable, Flushable {
- /**
- * Write a single byte of data. The input argument is truncated to 8 bits.
- *
- * @param b the byte to write
- * @throws IOException if an I/O error occurs
- */
- void write(int b) throws IOException;
-
- /**
- * Write many bytes of data.
- *
- * @param b the bytes to write
- * @throws IOException if an I/O error occurs
- */
- void write(byte[] b) throws IOException;
-
- /**
- * Write many bytes of data.
- *
- * @param b the bytes to write
- * @param offs the offset in {@code b} to start reading bytes from
- * @param len the number of bytes to write
- * @throws IOException if an I/O error occurs
- */
- void write(byte[] b, int offs, int len) throws IOException;
-
- /**
- * Commit the written data. This causes the accumulated data to be sent as a message on the underlying
- * channel.
- *
- * @throws IOException if an I/O error occurs
- */
- void commit() throws IOException;
-
- /**
- * Get a count of the number of bytes written to this message.
- *
- * @return the count
- * @throws IOException if an I/O error occurs
- */
- int getBytesWritten() throws IOException;
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/DataMessageInput.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/DataMessageInput.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/DataMessageInput.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,9 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.io.DataInput;
-
-/**
- *
- */
-public interface DataMessageInput extends ByteMessageInput, DataInput {
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/DataMessageOutput.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/DataMessageOutput.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/DataMessageOutput.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,9 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.io.DataOutput;
-
-/**
- *
- */
-public interface DataMessageOutput extends ByteMessageOutput, DataOutput {
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/InputStreamByteMessageInput.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/InputStreamByteMessageInput.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/InputStreamByteMessageInput.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,51 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- *
- */
-public class InputStreamByteMessageInput implements ByteMessageInput {
- private final InputStream inputStream;
- private int remaining;
-
- public InputStreamByteMessageInput(final InputStream inputStream, final int size) {
- this.inputStream = inputStream;
- remaining = size;
- }
-
- public int read() throws IOException {
- final int data = inputStream.read();
- if (data != -1 && remaining >= 0) {
- remaining--;
- }
- return data;
- }
-
- public int read(final byte[] data) throws IOException {
- final int cnt = inputStream.read(data);
- if (cnt != -1 && remaining >= 0) {
- remaining -= cnt;
- }
- return cnt;
- }
-
- public int read(final byte[] data, final int offs, final int len) throws IOException {
- final int cnt = inputStream.read(data, offs, len);
- if (cnt != -1 && remaining >= 0) {
- remaining -= cnt;
- }
- return cnt;
- }
-
- public int remaining() {
- final int remaining = this.remaining;
- return remaining < 0 ? -1 : remaining;
- }
-
- public void close() throws IOException {
- remaining = -1;
- inputStream.close();
- }
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ObjectMessageInput.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ObjectMessageInput.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ObjectMessageInput.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,19 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-
-/**
- * A readable message.
- */
-public interface ObjectMessageInput extends DataMessageInput, ObjectInput {
- /**
- * Read an object using the current context classloader, or, if there is no such classloader, the classloader
- * which loaded this interface.
- *
- * @return the object from the message
- * @throws ClassNotFoundException if the class of the object could not be resolved by the classloader
- * @throws IOException if an I/O error occurs
- */
- Object readObject() throws ClassNotFoundException, IOException;
-}
Deleted: remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ObjectMessageOutput.java
===================================================================
--- remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ObjectMessageOutput.java 2008-07-03 05:00:21 UTC (rev 4346)
+++ remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/ObjectMessageOutput.java 2008-07-03 14:16:42 UTC (rev 4347)
@@ -1,9 +0,0 @@
-package org.jboss.cx.remoting.util;
-
-import java.io.ObjectOutput;
-
-/**
- * A writable message.
- */
-public interface ObjectMessageOutput extends DataMessageOutput, ObjectOutput {
-}
16 years, 6 months
JBoss Remoting SVN: r4346 - remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 01:00:21 -0400 (Thu, 03 Jul 2008)
New Revision: 4346
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
Log:
Add one more missing notify
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-03 04:58:51 UTC (rev 4345)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-03 05:00:21 UTC (rev 4346)
@@ -74,6 +74,7 @@
}
state = State.WAITING;
this.remoteRequestContext = remoteRequestContext;
+ lock.notifyAll();
}
}
16 years, 6 months
JBoss Remoting SVN: r4345 - remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 00:58:51 -0400 (Thu, 03 Jul 2008)
New Revision: 4345
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
Log:
Add missing notifies
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-03 04:56:02 UTC (rev 4344)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-03 04:58:51 UTC (rev 4345)
@@ -305,6 +305,7 @@
state = State.DONE;
result = reply;
runCompletionHandlers();
+ lock.notifyAll();
}
}
}
@@ -330,6 +331,7 @@
msg = exMsg;
cause = exCause;
runCompletionHandlers();
+ lock.notifyAll();
}
}
}
@@ -353,6 +355,7 @@
if (state == State.WAITING) {
state = State.CANCELLED;
runCompletionHandlers();
+ lock.notifyAll();
}
}
}
16 years, 6 months
JBoss Remoting SVN: r4344 - in remoting3/trunk: standalone/src/main/java/org/jboss/cx/remoting and 1 other directory.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2008-07-03 00:56:02 -0400 (Thu, 03 Jul 2008)
New Revision: 4344
Modified:
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
Log:
Minor bugfixes
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java 2008-07-03 04:48:51 UTC (rev 4343)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/AbstractCloseable.java 2008-07-03 04:56:02 UTC (rev 4344)
@@ -42,6 +42,9 @@
private Set<CloseHandler<T>> closeHandlers;
protected AbstractCloseable(final Executor executor) {
+ if (executor == null) {
+ throw new NullPointerException("executor is null");
+ }
this.executor = executor;
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/EndpointImpl.java 2008-07-03 04:56:02 UTC (rev 4344)
@@ -88,7 +88,7 @@
public void start() {
// todo security check
if (executor == null) {
- executorService = Executors.newCachedThreadPool(new NamingThreadFactory(Executors.defaultThreadFactory(), "Remoting endpoint %s"));
+ executor = executorService = Executors.newCachedThreadPool(new NamingThreadFactory(Executors.defaultThreadFactory(), "Remoting endpoint %s"));
setExecutor(executorService);
}
state.requireTransition(State.INITIAL, State.UP);
@@ -99,6 +99,7 @@
if (executorService != null) {
executorService.shutdown();
executorService = null;
+ executor = null;
}
// todo
}
Modified: remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java
===================================================================
--- remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-03 04:48:51 UTC (rev 4343)
+++ remoting3/trunk/core/src/main/java/org/jboss/cx/remoting/core/FutureReplyImpl.java 2008-07-03 04:56:02 UTC (rev 4344)
@@ -43,7 +43,7 @@
private final ReplyHandler<O> replyHandler = new Handler();
private final Object lock = new Object();
// @protectedby lock
- private State state = State.WAITING;
+ private State state = State.NEW;
// @protectedby lock
private RemoteRequestContext remoteRequestContext;
// @protectedby lock
Modified: remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java
===================================================================
--- remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03 04:48:51 UTC (rev 4343)
+++ remoting3/trunk/standalone/src/main/java/org/jboss/cx/remoting/Remoting.java 2008-07-03 04:56:02 UTC (rev 4344)
@@ -19,6 +19,7 @@
endpointImpl.create();
try {
endpointImpl.start();
+ ok = true;
return endpointImpl;
} finally {
if (! ok) {
16 years, 6 months