Author: philharveyonline Date: Fri Jan 18 17:33:29 2013 New Revision: 1435261
URL: http://svn.apache.org/viewvc?rev=1435261&view=rev Log: PROTON-192: WIP modified Java proton.py to use factories, allowing JNI implementation to be used in place of the pure Java one Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/JNIFactory.java - copied, changed from r1435260, qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/JNIMessageFactory.java qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/resources/META-INF/services/org.apache.qpid.proton.message.MessageFactory qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonFactoryLoader.java qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/message/MessageFactory.java qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/message/impl/MessageFactoryImpl.java qpid/proton/branches/jni-binding/proton-j/proton/src/main/resources/META-INF/services/org.apache.qpid.proton.message.MessageFactory qpid/proton/branches/jni-binding/tests/src/test/java/org/apache/qpid/proton/systemtests/FactoryTest.java - copied, changed from r1435260, qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java Modified: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/scripts/proton.py qpid/proton/branches/jni-binding/tests/src/test/java/org/apache/qpid/proton/systemtests/SimpleTest.java Modified: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java?rev=1435261&r1=1435260&r2=1435261&view=diff ============================================================================== --- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java (original) +++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java Fri Jan 18 17:33:29 2013 @@ -24,27 +24,22 @@ import org.apache.qpid.proton.ProtonCEqu import org.apache.qpid.proton.engine.Connection; import org.apache.qpid.proton.engine.EngineFactory; import org.apache.qpid.proton.engine.Transport; +import org.apache.qpid.proton.jni.JNIFactory; -public class JNIEngineFactory implements EngineFactory +public class JNIEngineFactory extends JNIFactory implements EngineFactory { private static final Logger LOGGER = Logger.getLogger(JNIEngineFactory.class.getName()); - public JNIEngineFactory() - { - String libname = "proton-swig"; - - LOGGER.info("About to load library " + libname); - - System.loadLibrary(libname); - - LOGGER.info("Successfully loaded library " + libname); - } - @Override @ProtonCEquivalent("pn_connection") public Connection createConnection() { - return new JNIConnection(); + LOGGER.info("PHDEBUG about to create JNIConnection"); + + JNIConnection jniConnection = new JNIConnection(); + LOGGER.info("PHDEBUG created JNIConnection"); + + return jniConnection; } @Override Copied: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/JNIFactory.java (from r1435260, qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java) URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/JNIFactory.java?p2=qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/JNIFactory.java&p1=qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java&r1=1435260&r2=1435261&rev=1435261&view=diff ============================================================================== --- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java (original) +++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/JNIFactory.java Fri Jan 18 17:33:29 2013 @@ -16,20 +16,15 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.qpid.proton.engine.jni; +package org.apache.qpid.proton.jni; import java.util.logging.Logger; -import org.apache.qpid.proton.ProtonCEquivalent; -import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.EngineFactory; -import org.apache.qpid.proton.engine.Transport; - -public class JNIEngineFactory implements EngineFactory +public abstract class JNIFactory { - private static final Logger LOGGER = Logger.getLogger(JNIEngineFactory.class.getName()); + private static final Logger LOGGER = Logger.getLogger(JNIFactory.class.getName()); - public JNIEngineFactory() + static { String libname = "proton-swig"; @@ -40,17 +35,4 @@ public class JNIEngineFactory implements LOGGER.info("Successfully loaded library " + libname); } - @Override - @ProtonCEquivalent("pn_connection") - public Connection createConnection() - { - return new JNIConnection(); - } - - @Override - public Transport createTransport() - { - return new JNITransport(); - } - } Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/JNIMessageFactory.java URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/JNIMessageFactory.java?rev=1435261&view=auto ============================================================================== --- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/JNIMessageFactory.java (added) +++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/message/jni/JNIMessageFactory.java Fri Jan 18 17:33:29 2013 @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.proton.message.jni; + +import org.apache.qpid.proton.jni.JNIFactory; +import org.apache.qpid.proton.message.Message; +import org.apache.qpid.proton.message.MessageFactory; + +public class JNIMessageFactory extends JNIFactory implements MessageFactory +{ + + @Override + public Message createMessage() + { + throw new UnsupportedOperationException("PHTODO not implemented yet"); + } + +} Added: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/resources/META-INF/services/org.apache.qpid.proton.message.MessageFactory URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/resources/META-INF/services/org.apache.qpid.proton.message.MessageFactory?rev=1435261&view=auto ============================================================================== --- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/resources/META-INF/services/org.apache.qpid.proton.message.MessageFactory (added) +++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/resources/META-INF/services/org.apache.qpid.proton.message.MessageFactory Fri Jan 18 17:33:29 2013 @@ -0,0 +1 @@ +org.apache.qpid.proton.message.jni.JNIMessageFactory \ No newline at end of file Added: qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonFactoryLoader.java URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonFactoryLoader.java?rev=1435261&view=auto ============================================================================== --- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonFactoryLoader.java (added) +++ qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonFactoryLoader.java Fri Jan 18 17:33:29 2013 @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.proton; + +import java.util.Iterator; +import java.util.ServiceLoader; +import java.util.logging.Logger; + +public class ProtonFactoryLoader<C> +{ + private static final Logger LOGGER = Logger.getLogger(ProtonFactoryLoader.class.getName()); + + public C loadFactory(Class<C> factoryInterface) + { + ServiceLoader<C> serviceLoader = ServiceLoader.load(factoryInterface); + Iterator<C> serviceLoaderIterator = serviceLoader.iterator(); + if(!serviceLoaderIterator.hasNext()) + { + throw new IllegalStateException("Can't find service loader for " + factoryInterface.getName()); + } + C factory = serviceLoaderIterator.next(); + LOGGER.info("loadFactory returning " + factory); + return factory; + } + +} Added: qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/message/MessageFactory.java URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/message/MessageFactory.java?rev=1435261&view=auto ============================================================================== --- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/message/MessageFactory.java (added) +++ qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/message/MessageFactory.java Fri Jan 18 17:33:29 2013 @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.proton.message; + +public interface MessageFactory +{ + Message createMessage(); +} Modified: qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/scripts/proton.py URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/scripts/proton.py?rev=1435261&r1=1435260&r2=1435261&view=diff ============================================================================== --- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/scripts/proton.py (original) +++ qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/scripts/proton.py Fri Jan 18 17:33:29 2013 @@ -18,14 +18,13 @@ from uuid import UUID -from org.apache.qpid.proton.engine import EndpointState, TransportException, Sasl, SslDomain -from org.apache.qpid.proton.engine.impl import ConnectionImpl, SessionImpl, \ - SenderImpl, ReceiverImpl, TransportImpl -from org.apache.qpid.proton.engine.impl.ssl import SslDomainImpl, SslPeerDetailsImpl -from org.apache.qpid.proton.message import MessageFormat -from org.apache.qpid.proton.message.impl import MessageImpl +from org.apache.qpid.proton import ProtonFactoryLoader +from org.apache.qpid.proton.engine import EndpointState, TransportException, Sasl, SslDomain, EngineFactory +#from org.apache.qpid.proton.engine.impl.ssl import SslDomainImpl, SslPeerDetailsImpl +from org.apache.qpid.proton.message import MessageFormat, MessageFactory +#from org.apache.qpid.proton.message.impl import MessageImpl from org.apache.qpid.proton.messenger import MessengerException, Status -from org.apache.qpid.proton.messenger.impl import MessengerImpl +#from org.apache.qpid.proton.messenger.impl import MessengerImpl from org.apache.qpid.proton.amqp.messaging import Source, Target, Accepted, AmqpValue from org.apache.qpid.proton.amqp import UnsignedInteger from jarray import zeros @@ -36,7 +35,9 @@ LANGUAGE = "Java" class Skipped(Exception): skipped = True -PN_SESSION_WINDOW = TransportImpl.SESSION_WINDOW +# PHTODO resolve hardcoding +#PN_SESSION_WINDOW = TransportImpl.SESSION_WINDOW +PN_SESSION_WINDOW = 1024 PENDING = "PENDING" ACCEPTED = "ACCEPTED" @@ -52,6 +53,12 @@ STATUSES = { MANUAL = "MANUAL" AUTOMATIC = "AUTOMATIC" +print "PHDEBUG about to load factories" +protonFactoryLoader = ProtonFactoryLoader() +engineFactory = protonFactoryLoader.loadFactory(EngineFactory) +messageFactory = protonFactoryLoader.loadFactory(MessageFactory) +print "PHDEBUG engineFactory = %s " % engineFactory + class Endpoint(object): LOCAL_UNINIT = 1 @@ -141,7 +148,7 @@ def wrap_connection(impl): class Connection(Endpoint): def __init__(self, _impl=None): - self.impl = _impl or ConnectionImpl() + self.impl = _impl or engineFactory.createConnection() @property def writable(self): @@ -417,7 +424,7 @@ class Transport(object): TRACE_DRV = 4 def __init__(self): - self.impl = TransportImpl() + self.impl = engineFactory.createTransport() def trace(self, mask): # XXX: self.impl.trace(mask) @@ -433,7 +440,7 @@ class Transport(object): n = self.impl.output(output, 0, size) if n >= 0: return output.tostring()[:n] - elif n == TransportImpl.END_OF_STREAM: + elif n == Transport.END_OF_STREAM: return None else: raise Exception("XXX: %s" % n) @@ -597,10 +604,12 @@ class Message(object): DATA = MessageFormat.DATA JSON = MessageFormat.JSON - DEFAULT_PRIORITY = MessageImpl.DEFAULT_PRIORITY + # PHTODO remove hardcoding + #DEFAULT_PRIORITY = MessageImpl.DEFAULT_PRIORITY + DEFAULT_PRIORITY = 4 def __init__(self): - self.impl = MessageImpl() + self.impl = messageFactory.createMessage() def clear(self): self.impl.clear() @@ -793,7 +802,7 @@ class SASL(object): n = self._sasl.recv(output, 0, size) if n >= 0: return output.tostring()[:n] - elif n == TransportImpl.END_OF_STREAM: + elif n == Transport.END_OF_STREAM: return None else: raise Exception(n) Added: qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/message/impl/MessageFactoryImpl.java URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/message/impl/MessageFactoryImpl.java?rev=1435261&view=auto ============================================================================== --- qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/message/impl/MessageFactoryImpl.java (added) +++ qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/message/impl/MessageFactoryImpl.java Fri Jan 18 17:33:29 2013 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.qpid.proton.message.impl; + +import org.apache.qpid.proton.message.Message; +import org.apache.qpid.proton.message.MessageFactory; + +public class MessageFactoryImpl implements MessageFactory +{ + + @Override + public Message createMessage() + { + return new MessageImpl(); + } +} Added: qpid/proton/branches/jni-binding/proton-j/proton/src/main/resources/META-INF/services/org.apache.qpid.proton.message.MessageFactory URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton/src/main/resources/META-INF/services/org.apache.qpid.proton.message.MessageFactory?rev=1435261&view=auto ============================================================================== --- qpid/proton/branches/jni-binding/proton-j/proton/src/main/resources/META-INF/services/org.apache.qpid.proton.message.MessageFactory (added) +++ qpid/proton/branches/jni-binding/proton-j/proton/src/main/resources/META-INF/services/org.apache.qpid.proton.message.MessageFactory Fri Jan 18 17:33:29 2013 @@ -0,0 +1 @@ +org.apache.qpid.proton.message.impl.MessageFactoryImpl \ No newline at end of file Copied: qpid/proton/branches/jni-binding/tests/src/test/java/org/apache/qpid/proton/systemtests/FactoryTest.java (from r1435260, qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java) URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/tests/src/test/java/org/apache/qpid/proton/systemtests/FactoryTest.java?p2=qpid/proton/branches/jni-binding/tests/src/test/java/org/apache/qpid/proton/systemtests/FactoryTest.java&p1=qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java&r1=1435260&r2=1435261&rev=1435261&view=diff ============================================================================== --- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNIEngineFactory.java (original) +++ qpid/proton/branches/jni-binding/tests/src/test/java/org/apache/qpid/proton/systemtests/FactoryTest.java Fri Jan 18 17:33:29 2013 @@ -16,41 +16,24 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.qpid.proton.engine.jni; +package org.apache.qpid.proton.systemtests; -import java.util.logging.Logger; +import static org.junit.Assert.*; -import org.apache.qpid.proton.ProtonCEquivalent; -import org.apache.qpid.proton.engine.Connection; + +import org.apache.qpid.proton.ProtonFactoryLoader; import org.apache.qpid.proton.engine.EngineFactory; -import org.apache.qpid.proton.engine.Transport; +import org.apache.qpid.proton.message.MessageFactory; +import org.junit.Test; -public class JNIEngineFactory implements EngineFactory +public class FactoryTest { - private static final Logger LOGGER = Logger.getLogger(JNIEngineFactory.class.getName()); - - public JNIEngineFactory() - { - String libname = "proton-swig"; - - LOGGER.info("About to load library " + libname); - - System.loadLibrary(libname); - - LOGGER.info("Successfully loaded library " + libname); - } - - @Override - @ProtonCEquivalent("pn_connection") - public Connection createConnection() - { - return new JNIConnection(); - } - @Override - public Transport createTransport() + @Test + public void testMessageFactory() { - return new JNITransport(); + MessageFactory messageFactory = new ProtonFactoryLoader<MessageFactory>().loadFactory(MessageFactory.class); + assertNotNull(messageFactory); } } Modified: qpid/proton/branches/jni-binding/tests/src/test/java/org/apache/qpid/proton/systemtests/SimpleTest.java URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/tests/src/test/java/org/apache/qpid/proton/systemtests/SimpleTest.java?rev=1435261&r1=1435260&r2=1435261&view=diff ============================================================================== --- qpid/proton/branches/jni-binding/tests/src/test/java/org/apache/qpid/proton/systemtests/SimpleTest.java (original) +++ qpid/proton/branches/jni-binding/tests/src/test/java/org/apache/qpid/proton/systemtests/SimpleTest.java Fri Jan 18 17:33:29 2013 @@ -18,13 +18,10 @@ */ package org.apache.qpid.proton.systemtests; -import static org.junit.Assert.*; - -import java.util.Iterator; -import java.util.ServiceLoader; +import static org.junit.Assert.assertEquals; +import org.apache.qpid.proton.ProtonFactoryLoader; import org.apache.qpid.proton.engine.Connection; -import org.apache.qpid.proton.engine.Endpoint; import org.apache.qpid.proton.engine.EndpointState; import org.apache.qpid.proton.engine.EngineFactory; import org.apache.qpid.proton.engine.Transport; @@ -36,7 +33,7 @@ public class SimpleTest @Test public void test() { - EngineFactory engineFactory = createEngineFactory(); + EngineFactory engineFactory = new ProtonFactoryLoader<EngineFactory>().loadFactory(EngineFactory.class); Connection connection1 = engineFactory.createConnection(); Connection connection2 = engineFactory.createConnection();; @@ -53,13 +50,5 @@ public class SimpleTest connection2.open(); } - private EngineFactory createEngineFactory() - { - ServiceLoader<EngineFactory> engineFactoryServiceLoader = ServiceLoader.load(EngineFactory.class); - Iterator<EngineFactory> serviceLoaderIterator = engineFactoryServiceLoader.iterator(); - assertTrue("Can't find service loader for engineFactory", serviceLoaderIterator.hasNext()); - EngineFactory engineFactory = serviceLoaderIterator.next(); - return engineFactory; - } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
