From f860c2f35b2f94e379d2ff7d5c13f54cd4a3132a Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:06:42 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835119 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca-java-0.90/modules/core/.checkstyle | 24 + .../branches/sca-java-0.90/modules/core/.pmd | 20 + .../branches/sca-java-0.90/modules/core/.ruleset | 190 +++++++ .../branches/sca-java-0.90/modules/core/DISCLAIMER | 8 + .../branches/sca-java-0.90/modules/core/LICENSE | 205 +++++++ .../branches/sca-java-0.90/modules/core/NOTICE | 6 + .../branches/sca-java-0.90/modules/core/pom.xml | 64 +++ .../sca/core/component/CallableReferenceImpl.java | 59 ++ .../sca/core/component/CallbackReferenceImpl.java | 33 ++ .../sca/core/component/ComponentContextImpl.java | 93 ++++ .../core/component/ComponentContextProvider.java | 44 ++ .../sca/core/component/RequestContextImpl.java | 54 ++ .../sca/core/component/ServiceReferenceImpl.java | 51 ++ .../tuscany/sca/core/event/BaseEventPublisher.java | 89 +++ .../tuscany/sca/core/event/ComponentStart.java | 54 ++ .../tuscany/sca/core/event/ComponentStop.java | 53 ++ .../tuscany/sca/core/event/ConversationEnd.java | 53 ++ .../tuscany/sca/core/event/ConversationStart.java | 52 ++ .../tuscany/sca/core/event/HttpSessionEnd.java | 53 ++ .../tuscany/sca/core/event/HttpSessionStart.java | 52 ++ .../apache/tuscany/sca/core/event/RequestEnd.java | 45 ++ .../tuscany/sca/core/event/RequestStart.java | 45 ++ .../core/invocation/AbstractInvocationHandler.java | 104 ++++ .../invocation/CallbackInterfaceInterceptor.java | 57 ++ .../core/invocation/CallbackWireObjectFactory.java | 47 ++ .../core/invocation/ExtensibleWireProcessor.java | 44 ++ .../sca/core/invocation/InvocationChainImpl.java | 126 +++++ .../invocation/JDKCallbackInvocationHandler.java | 95 ++++ .../sca/core/invocation/JDKInvocationHandler.java | 112 ++++ .../sca/core/invocation/JDKProxyService.java | 78 +++ .../sca/core/invocation/MessageFactoryImpl.java | 36 ++ .../tuscany/sca/core/invocation/MessageImpl.java | 117 ++++ .../invocation/NoMethodForOperationException.java | 43 ++ .../core/invocation/NonBlockingInterceptor.java | 174 ++++++ .../core/invocation/ProxyCreationException.java | 48 ++ .../tuscany/sca/core/invocation/ProxyFactory.java | 61 +++ .../sca/core/invocation/ThreadMessageContext.java | 68 +++ .../sca/core/invocation/WireObjectFactory.java | 55 ++ .../sca/core/runtime/ActivationException.java | 37 ++ .../sca/core/runtime/CompositeActivator.java | 55 ++ .../sca/core/runtime/CompositeActivatorImpl.java | 597 +++++++++++++++++++++ .../sca/core/runtime/EndpointReferenceImpl.java | 128 +++++ .../sca/core/runtime/RuntimeAssemblyFactory.java | 61 +++ .../sca/core/runtime/RuntimeComponentImpl.java | 128 +++++ .../runtime/RuntimeComponentReferenceImpl.java | 86 +++ .../core/runtime/RuntimeComponentServiceImpl.java | 109 ++++ .../core/runtime/RuntimeSCABindingProvider.java | 55 ++ .../runtime/RuntimeSCABindingProviderFactory.java | 51 ++ .../tuscany/sca/core/runtime/RuntimeWireImpl.java | 66 +++ .../sca/core/scope/AbstractScopeContainer.java | 146 +++++ .../sca/core/scope/CompositeScopeContainer.java | 70 +++ .../core/scope/CompositeScopeContainerFactory.java | 40 ++ .../core/scope/ConversationalScopeContainer.java | 182 +++++++ .../scope/ConversationalScopeContainerFactory.java | 47 ++ .../sca/core/scope/HttpSessionScopeContainer.java | 81 +++ .../scope/HttpSessionScopeContainerFactory.java | 44 ++ .../sca/core/scope/RequestScopeContainer.java | 85 +++ .../core/scope/RequestScopeContainerFactory.java | 40 ++ .../tuscany/sca/core/scope/ScopeRegistryImpl.java | 68 +++ .../sca/core/scope/StatelessScopeContainer.java | 54 ++ .../core/scope/StatelessScopeContainerFactory.java | 40 ++ .../apache/tuscany/sca/core/store/MemoryStore.java | 195 +++++++ .../org/apache/tuscany/sca/core/util/IOHelper.java | 182 +++++++ .../apache/tuscany/sca/core/work/Jsr237Work.java | 63 +++ .../tuscany/sca/core/work/Jsr237WorkScheduler.java | 167 ++++++ .../sca/core/work/ThreadPoolWorkManager.java | 220 ++++++++ .../tuscany/sca/core/work/WorkEventImpl.java | 74 +++ .../apache/tuscany/sca/core/work/WorkItemImpl.java | 166 ++++++ .../sca/factory/ObjectCreationException.java | 47 ++ .../apache/tuscany/sca/factory/ObjectFactory.java | 35 ++ .../sca/factory/SingletonObjectFactory.java | 38 ++ .../tuscany/sca/scope/AbstractLifecycle.java | 77 +++ .../tuscany/sca/scope/CoreRuntimeException.java | 45 ++ .../apache/tuscany/sca/scope/InstanceWrapper.java | 45 ++ .../org/apache/tuscany/sca/scope/Lifecycle.java | 69 +++ .../tuscany/sca/scope/PersistenceException.java | 43 ++ .../java/org/apache/tuscany/sca/scope/Scope.java | 63 +++ .../apache/tuscany/sca/scope/ScopeContainer.java | 93 ++++ .../tuscany/sca/scope/ScopeContainerFactory.java | 32 ++ .../apache/tuscany/sca/scope/ScopeIdentifier.java | 35 ++ .../tuscany/sca/scope/ScopeNotFoundException.java | 31 ++ .../apache/tuscany/sca/scope/ScopeRegistry.java | 43 ++ .../sca/scope/ScopedImplementationProvider.java | 64 +++ .../tuscany/sca/scope/ScopedRuntimeComponent.java | 40 ++ .../sca/scope/TargetDestructionException.java | 44 ++ .../sca/scope/TargetInitializationException.java | 44 ++ .../sca/scope/TargetInvocationException.java | 45 ++ .../sca/scope/TargetInvokerCreationException.java | 44 ++ .../tuscany/sca/scope/TargetNotFoundException.java | 44 ++ .../sca/scope/TargetResolutionException.java | 44 ++ .../DefaultExtensionPointRegistryTestCase.java | 51 ++ .../sca/core/event/BaseEventPublisherTestCase.java | 98 ++++ .../tuscany/sca/core/event/EventTestCase.java | 69 +++ .../sca/core/mock/component/AsyncTarget.java | 31 ++ .../sca/core/mock/component/BadContextPojo.java | 28 + .../sca/core/mock/component/BadNamePojo.java | 26 + .../sca/core/mock/component/BasicInterface.java | 30 ++ .../core/mock/component/BasicInterfaceImpl.java | 66 +++ .../mock/component/CompositeScopeComponent.java | 31 ++ .../component/CompositeScopeComponentImpl.java | 40 ++ .../CompositeScopeDestroyOnlyComponent.java | 36 ++ .../CompositeScopeInitDestroyComponent.java | 39 ++ .../component/CompositeScopeInitOnlyComponent.java | 42 ++ .../component/ConversationalScopeComponent.java | 29 + .../ConversationalScopeComponentImpl.java | 29 + .../ConversationalScopeDestroyOnlyComponent.java | 37 ++ .../ConversationalScopeInitDestroyComponent.java | 38 ++ .../ConversationalScopeInitOnlyComponent.java | 38 ++ .../sca/core/mock/component/OrderException.java | 40 ++ .../core/mock/component/OrderedDependentPojo.java | 29 + .../mock/component/OrderedDependentPojoImpl.java | 36 ++ .../core/mock/component/OrderedEagerInitPojo.java | 60 +++ .../sca/core/mock/component/OrderedInitPojo.java | 28 + .../core/mock/component/OrderedInitPojoImpl.java | 61 +++ .../sca/core/mock/component/OtherTarget.java | 31 ++ .../sca/core/mock/component/OtherTargetImpl.java | 39 ++ .../core/mock/component/RequestScopeComponent.java | 30 ++ .../RequestScopeDestroyOnlyComponent.java | 38 ++ .../RequestScopeInitDestroyComponent.java | 38 ++ .../component/RequestScopeInitOnlyComponent.java | 39 ++ .../core/mock/component/SessionScopeComponent.java | 30 ++ .../mock/component/SessionScopeComponentImpl.java | 30 ++ .../SessionScopeInitDestroyComponent.java | 36 ++ .../component/SessionScopeInitOnlyComponent.java | 37 ++ .../sca/core/mock/component/SimpleTarget.java | 30 ++ .../sca/core/mock/component/SimpleTargetImpl.java | 41 ++ .../tuscany/sca/core/mock/component/Source.java | 37 ++ .../sca/core/mock/component/SourceImpl.java | 63 +++ .../core/mock/component/StatelessComponent.java | 30 ++ .../mock/component/StatelessComponentImpl.java | 27 + .../tuscany/sca/core/mock/component/Target.java | 32 ++ .../sca/core/mock/component/TargetImpl.java | 38 ++ .../core/scope/AbstractScopeContainerTestCase.java | 70 +++ .../sca/core/store/MemoryStoreTestCase.java | 165 ++++++ .../wire/CallbackInterfaceInterceptorTestCase.java | 55 ++ .../sca/core/wire/InvocationChainImplTestCase.java | 66 +++ .../core/wire/NonBlockingInterceptorTestCase.java | 72 +++ .../tuscany/sca/factory/AssertionTestCase.java | 38 ++ .../factory/SingletonObjectFactoryTestCase.java | 33 ++ .../apache/tuscany/sca/scope/ScopeTestCase.java | 61 +++ 140 files changed, 9232 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallableReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallbackReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/RequestContextImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ServiceReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AbstractInvocationHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyService.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/ActivationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeAssemblyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/util/IOHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectCreationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/SingletonObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/AbstractLifecycle.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/CoreRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/InstanceWrapper.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/Lifecycle.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/PersistenceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/Scope.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeIdentifier.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedRuntimeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetDestructionException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInitializationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvocationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvokerCreationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetResolutionException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/AsyncTarget.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadContextPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadNamePojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterface.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderException.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojoImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedEagerInitPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojoImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTarget.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTargetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTarget.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTargetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Source.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SourceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Target.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/TargetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/factory/AssertionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/factory/SingletonObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java (limited to 'sca-java-1.x/branches/sca-java-0.90/modules/core') diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/.checkstyle b/sca-java-1.x/branches/sca-java-0.90/modules/core/.checkstyle new file mode 100644 index 0000000000..3e57539570 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/.pmd b/sca-java-1.x/branches/sca-java-0.90/modules/core/.pmd new file mode 100644 index 0000000000..ffc4fe2bbb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/.pmd @@ -0,0 +1,20 @@ + + +true diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/.ruleset b/sca-java-1.x/branches/sca-java-0.90/modules/core/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.90/modules/core/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/LICENSE b/sca-java-1.x/branches/sca-java-0.90/modules/core/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/NOTICE b/sca-java-1.x/branches/sca-java-0.90/modules/core/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/pom.xml b/sca-java-1.x/branches/sca-java-0.90/modules/core/pom.xml new file mode 100644 index 0000000000..0db49e7726 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.90-incubating-SNAPSHOT + ../pom.xml + + tuscany-core + Apache Tuscany SCA Core Runtime + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.90-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution + 0.90-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 0.90-incubating-SNAPSHOT + + + + org.apache.tuscany + commonj-api + 0.90-incubating-SNAPSHOT + + + + org.codehaus.woodstox + wstx-asl + 3.2.0 + runtime + + + + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallableReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallableReferenceImpl.java new file mode 100644 index 0000000000..f0f0049056 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallableReferenceImpl.java @@ -0,0 +1,59 @@ +/* + * 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.tuscany.sca.core.component; + +import org.apache.tuscany.sca.factory.ObjectFactory; +import org.osoa.sca.CallableReference; +import org.osoa.sca.Conversation; + +/** + * Base class for implementations of service and callback references. + * + * @version $Rev$ $Date$ + * @param the type of the business interface + */ +public abstract class CallableReferenceImpl implements CallableReference { + private final Class businessInterface; + private final ObjectFactory factory; + + protected CallableReferenceImpl(Class businessInterface, ObjectFactory factory) { + this.businessInterface = businessInterface; + this.factory = factory; + } + + public B getService() { + return factory.getInstance(); + } + + public Class getBusinessInterface() { + return businessInterface; + } + + public boolean isConversational() { + return false; + } + + public Conversation getConversation() { + return null; + } + + public Object getCallbackID() { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallbackReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallbackReferenceImpl.java new file mode 100644 index 0000000000..45a48730d3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallbackReferenceImpl.java @@ -0,0 +1,33 @@ +/* + * 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.tuscany.sca.core.component; + +import org.apache.tuscany.sca.factory.ObjectFactory; + +/** + * Default implementation of a callback reference. + * + * @version $Rev$ $Date$ + * @param the type of the business interface + */ +public class CallbackReferenceImpl extends CallableReferenceImpl { + public CallbackReferenceImpl(Class businessInterface, ObjectFactory factory) { + super(businessInterface, factory); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextImpl.java new file mode 100644 index 0000000000..abcd17f505 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextImpl.java @@ -0,0 +1,93 @@ +/* + * 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.tuscany.sca.core.component; + +import org.osoa.sca.CallableReference; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Implementation of ComponentContext that delegates to a ComponentContextProvider. + * + * @version $Rev$ $Date$ + */ +public class ComponentContextImpl implements ComponentContext { + private final ComponentContextProvider component; + + public ComponentContextImpl(ComponentContextProvider component) { + this.component = component; + } + + public String getURI() { + try { + return component.getUri().toString(); + } catch (RuntimeException e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public > R cast(B target) throws IllegalArgumentException { + try { + return (R) component.cast(target); + } catch (RuntimeException e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public B getService(Class businessInterface, String referenceName) { + try { + return component.getService(businessInterface, referenceName); + } catch (RuntimeException e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public ServiceReference getServiceReference(Class businessInterface, String referenceName) { + try { + return component.getServiceReference(businessInterface, referenceName); + } catch (RuntimeException e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public B getProperty(Class type, String propertyName) { + try { + return component.getProperty(type, propertyName); + } catch (RuntimeException e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public ServiceReference createSelfReference(Class businessInterface) { + return getServiceReference(businessInterface, "$self$."); + // FIXME: How to get the ObjectFactory? + // ObjectFactory factory = ((AtomicComponent) component).createObjectFactory(); + // return new ServiceReferenceImpl(businessInterface, factory); + } + + public ServiceReference createSelfReference(Class businessInterface, String serviceName) { + return getServiceReference(businessInterface, "$self$."+serviceName); + } + + public RequestContext getRequestContext() { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextProvider.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextProvider.java new file mode 100644 index 0000000000..3999d0d5b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextProvider.java @@ -0,0 +1,44 @@ +/* + * 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.tuscany.sca.core.component; + +import java.net.URI; + +import org.osoa.sca.CallableReference; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.ServiceReference; + +/** + * Interface implemented by Component's that want to expose a ComponentContext. + * + * @version $Rev$ $Date$ + */ +public interface ComponentContextProvider { + ComponentContext getComponentContext(); + + URI getUri(); + + B getService(Class businessInterface, String referenceName); + + ServiceReference getServiceReference(Class businessInterface, String referenceName); + + B getProperty(Class type, String propertyName); + + > R cast(B target); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/RequestContextImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/RequestContextImpl.java new file mode 100644 index 0000000000..3a219b9cd9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/RequestContextImpl.java @@ -0,0 +1,54 @@ +/* + * 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.tuscany.sca.core.component; + +import javax.security.auth.Subject; + +import org.osoa.sca.CallableReference; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; + +/** + * @version $Rev$ $Date$ + */ +public class RequestContextImpl implements RequestContext { + + public RequestContextImpl() { + } + + public Subject getSecuritySubject() { + throw new UnsupportedOperationException(); + } + + public String getServiceName() { + throw new UnsupportedOperationException(); + } + + public ServiceReference getServiceReference() { + throw new UnsupportedOperationException(); + } + + public CB getCallback() { + throw new UnsupportedOperationException(); + } + + public CallableReference getCallbackReference() { + throw new UnsupportedOperationException(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ServiceReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ServiceReferenceImpl.java new file mode 100644 index 0000000000..e268f5750f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ServiceReferenceImpl.java @@ -0,0 +1,51 @@ +/* + * 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.tuscany.sca.core.component; + +import org.apache.tuscany.sca.factory.ObjectFactory; +import org.osoa.sca.ServiceReference; + +/** + * Default implementation of a ServiceReference. + * + * @version $Rev$ $Date$ + * @param the type of the business interface + */ +public class ServiceReferenceImpl extends CallableReferenceImpl implements ServiceReference { + public ServiceReferenceImpl(Class businessInterface, ObjectFactory factory) { + super(businessInterface, factory); + } + + public Object getConversationID() { + return null; + } + + public void setConversationID(Object conversationId) throws IllegalStateException { + } + + public void setCallbackID(Object callbackID) { + } + + public Object getCallback() { + return null; + } + + public void setCallback(Object callback) { + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java new file mode 100644 index 0000000000..517e5579a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java @@ -0,0 +1,89 @@ +/* + * 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.tuscany.sca.core.event; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.event.EventFilter; +import org.apache.tuscany.sca.event.EventPublisher; +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.event.TrueFilter; + +/** + * Base implementation of an EventPublisher + * + * @version $Rev$ $Date$ + */ +public abstract class BaseEventPublisher implements EventPublisher { + protected static final EventFilter TRUE_FILTER = new TrueFilter(); + protected Map> listeners; + + public void addListener(RuntimeEventListener listener) { + addListener(TRUE_FILTER, listener); + } + + public void removeListener(RuntimeEventListener listener) { + assert listener != null : "Listener cannot be null"; + synchronized (getListeners()) { + for (List currentList : getListeners().values()) { + for (RuntimeEventListener current : currentList) { + if (current == listener) { + currentList.remove(current); + return; + } + } + } + } + } + + public void addListener(EventFilter filter, RuntimeEventListener listener) { + assert listener != null : "Listener cannot be null"; + synchronized (getListeners()) { + List list = getListeners().get(filter); + if (list == null) { + list = new CopyOnWriteArrayList(); + listeners.put(filter, list); + } + list.add(listener); + } + } + + public void publish(Event event) { + assert event != null : "Event object was null"; + for (Map.Entry> entry : getListeners().entrySet()) { + if (entry.getKey().match(event)) { + for (RuntimeEventListener listener : entry.getValue()) { + listener.onEvent(event); + } + } + } + } + + protected Map> getListeners() { + if (listeners == null) { + listeners = new ConcurrentHashMap>(); + } + return listeners; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java new file mode 100644 index 0000000000..8e90c953e5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java @@ -0,0 +1,54 @@ +/* + * 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.tuscany.sca.core.event; + +import java.net.URI; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a component starts + * + * @version $$Rev$$ $$Date$$ + */ +public class ComponentStart implements Event { + + private Object source; + private URI uri; + + /** + * Creates a component start event + * + * @param source the source of the event + * @param componentURI the uri of the component being started + */ + public ComponentStart(Object source, URI componentURI) { + this.source = source; + this.uri = componentURI; + } + + public URI getComponentURI() { + return uri; + } + + public Object getSource() { + return source; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java new file mode 100644 index 0000000000..d879182e14 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java @@ -0,0 +1,53 @@ +/* + * 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.tuscany.sca.core.event; + +import java.net.URI; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a component stops + * + * @version $$Rev$$ $$Date$$ + */ +public class ComponentStop implements Event { + + private Object source; + private URI uri; + + /** + * Creates a component stop event + * + * @param source the source of the event + * @param componentUri the composite component associated the component being stopped + */ + public ComponentStop(Object source, URI componentUri) { + this.source = source; + this.uri = componentUri; + } + + public URI getComponentURI() { + return uri; + } + + public Object getSource() { + return source; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java new file mode 100644 index 0000000000..cd14710880 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java @@ -0,0 +1,53 @@ +/* + * 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.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + + +/** + * Propagated when a conversation is expired + * + * @version $$Rev$$ $$Date$$ + */ +public class ConversationEnd implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the conversation being ended + */ + public ConversationEnd(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getConversationID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java new file mode 100644 index 0000000000..a4cc49204e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java @@ -0,0 +1,52 @@ +/* + * 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.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + +/** + * Propagated when a conversation has started + * + * @version $$Rev$$ $$Date$$ + */ +public class ConversationStart implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the conversation being started + */ + public ConversationStart(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getConversationID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java new file mode 100644 index 0000000000..4c3fd8b397 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java @@ -0,0 +1,53 @@ +/* + * 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.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + + +/** + * Propagated when an HTTP-based session is expired + * + * @version $$Rev$$ $$Date$$ + */ +public class HttpSessionEnd implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the HTTP session being ended + */ + public HttpSessionEnd(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getSessionID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java new file mode 100644 index 0000000000..67b922b99c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java @@ -0,0 +1,52 @@ +/* + * 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.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + +/** + * Propagated when an HTTP-based session has started + * + * @version $$Rev$$ $$Date$$ + */ +public class HttpSessionStart implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the HTTP session being started + */ + public HttpSessionStart(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getSessionID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java new file mode 100644 index 0000000000..8b5c512cf2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java @@ -0,0 +1,45 @@ +/* + * 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.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a request completes or is ended + * + * @version $$Rev$$ $$Date$$ + */ +public class RequestEnd implements Event { + + private Object source; + + /** + * Creates a new event + * + * @param source the source of the event + */ + public RequestEnd(Object source) { + this.source = source; + } + + public Object getSource() { + return source; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java new file mode 100644 index 0000000000..974563b57c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java @@ -0,0 +1,45 @@ +/* + * 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.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a request is started in the runtime + * + * @version $$Rev$$ $$Date$$ + */ +public class RequestStart implements Event { + + private Object source; + + /** + * Creates a new event + * + * @param source the source of the event + */ + public RequestStart(Object source) { + this.source = source; + } + + public Object getSource() { + return source; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AbstractInvocationHandler.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AbstractInvocationHandler.java new file mode 100644 index 0000000000..6c1f38e4c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AbstractInvocationHandler.java @@ -0,0 +1,104 @@ +/* + * 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.tuscany.sca.core.invocation; + +import java.util.UUID; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Base class for performing invocations on a wire. Subclasses are responsible for retrieving and supplying the + * appropriate chain, target invoker, and invocation arguments. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractInvocationHandler { + protected boolean conversational; + private boolean conversationStarted; + private MessageFactory messageFactory; + + protected AbstractInvocationHandler(MessageFactory messageFactory, boolean conversational) { + this.conversational = conversational; + this.messageFactory = messageFactory; + } + + protected Object invoke(InvocationChain chain, Object[] args, RuntimeWire wire) throws Throwable { + + Message msgContext = ThreadMessageContext.getMessageContext(); + Message msg = messageFactory.createMessage(); + if (conversational) { + Object id = msgContext.getConversationID(); + if (id == null) { + String convIdFromThread = createConversationID(); + msg.setConversationID(convIdFromThread); + } + } + + Invoker headInvoker = chain.getHeadInvoker(); + msg.setCorrelationID(msgContext.getCorrelationID()); + Operation operation = chain.getTargetOperation(); + Interface contract = operation.getInterface(); + if (contract != null && contract.isConversational()) { + ConversationSequence sequence = chain.getTargetOperation().getConversationSequence(); + if (sequence == ConversationSequence.CONVERSATION_END) { + msg.setConversationSequence(ConversationSequence.CONVERSATION_END); + conversationStarted = false; + } else if (sequence == ConversationSequence.CONVERSATION_CONTINUE) { + if (conversationStarted) { + msg.setConversationSequence(ConversationSequence.CONVERSATION_CONTINUE); + } else { + conversationStarted = true; + msg.setConversationSequence(ConversationSequence.CONVERSATION_START); + } + } + } + msg.setBody(args); + msg.setFrom(wire.getSource()); + msg.setTo(wire.getTarget()); + ThreadMessageContext.setMessageContext(msg); + try { + // dispatch the wire down the chain and get the response + Message resp = headInvoker.invoke(msg); + Object body = resp.getBody(); + if (resp.isFault()) { + throw (Throwable)body; + } + return body; + } finally { + ThreadMessageContext.setMessageContext(msgContext); + } + } + + /** + * Creates a new conversational id + * + * @return the conversational id + */ + private String createConversationID() { + return UUID.randomUUID().toString(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java new file mode 100644 index 0000000000..219dc55536 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java @@ -0,0 +1,57 @@ +/* + * 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.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.osoa.sca.NoRegisteredCallbackException; + +/** + * An interceptor applied to the forward direction of a wire that ensures the callback target implements the required + * service contract. This is required as callback targets may be set dynamically by service implementations. + * + * @version $Rev$ $Date$ + */ +public class CallbackInterfaceInterceptor implements Interceptor { + private boolean invokingServiceImplements; + private Invoker next; + + public CallbackInterfaceInterceptor(boolean invokingServiceImplements) { + this.invokingServiceImplements = invokingServiceImplements; + } + + public Message invoke(Message msg) { + // TODO check in the context if a callback object is set, if so invoke next since the setCallback will + // perform the check + if (!invokingServiceImplements) { + throw new NoRegisteredCallbackException("Callback target does not implement the callback interface"); + } + return next.invoke(msg); + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Invoker getNext() { + return next; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java new file mode 100644 index 0000000000..dae4ed708b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java @@ -0,0 +1,47 @@ +/* + * 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.tuscany.sca.core.invocation; + +import java.util.List; + +import org.apache.tuscany.sca.factory.ObjectCreationException; +import org.apache.tuscany.sca.factory.ObjectFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Returns proxy instance for a wire callback + * + * @version $Rev$ $Date$ + */ +public class CallbackWireObjectFactory implements ObjectFactory { + private ProxyFactory proxyFactory; + private Class interfaze; + private List wires; + + public CallbackWireObjectFactory(Class interfaze, ProxyFactory proxyService, List wires) { + this.interfaze = interfaze; + this.proxyFactory = proxyService; + this.wires = wires; + } + + public Object getInstance() throws ObjectCreationException { + return proxyFactory.createCallbackProxy(interfaze, wires); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java new file mode 100644 index 0000000000..934f2f7aa0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java @@ -0,0 +1,44 @@ +/* + * 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.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; + +/** + * The default implementation of an extensible WireProcessor + * + * @version $Rev$ $Date$ + */ +public class ExtensibleWireProcessor implements RuntimeWireProcessor { + + private RuntimeWireProcessorExtensionPoint processors; + + public ExtensibleWireProcessor(RuntimeWireProcessorExtensionPoint processors) { + this.processors = processors; + } + + public void process(RuntimeWire wire) { + for (RuntimeWireProcessor processor : processors.getWireProcessors()) { + processor.process(wire); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java new file mode 100644 index 0000000000..e04148e374 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java @@ -0,0 +1,126 @@ +/* + * 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.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; + +/** + * Default implementation of an invocation chain + * + * @version $Rev$ $Date$ + */ +public class InvocationChainImpl implements InvocationChain { + private Operation sourceOperation; + private Operation targetOperation; + private Invoker invokerChainHead; + private Invoker invokerChainTail; + + public InvocationChainImpl(Operation operation) { + assert operation != null; + this.targetOperation = operation; + this.sourceOperation = operation; + } + + public InvocationChainImpl(Operation sourceOperation, Operation targetOperation) { + assert sourceOperation != null; + assert targetOperation != null; + this.targetOperation = targetOperation; + this.sourceOperation = sourceOperation; + } + + public Operation getTargetOperation() { + return targetOperation; + } + + public void addInterceptor(Interceptor interceptor) { + if (invokerChainHead == null) { + invokerChainHead = interceptor; + } else { + if (invokerChainHead instanceof Interceptor) { + ((Interceptor)invokerChainTail).setNext(interceptor); + } + } + invokerChainTail = interceptor; + } + + public void addInvoker(Invoker invoker) { + if (invokerChainHead == null) { + invokerChainHead = invoker; + } else { + if (invokerChainTail instanceof Interceptor) { + ((Interceptor)invokerChainTail).setNext(invoker); + } + } + invokerChainTail = invoker; + } + + public Invoker getHeadInvoker() { + return invokerChainHead; + } + + public Invoker getTailInvoker() { + return invokerChainTail; + } + + /** + * @return the sourceOperation + */ + public Operation getSourceOperation() { + return sourceOperation; + } + + /** + * @param sourceOperation the sourceOperation to set + */ + public void setSourceOperation(Operation sourceOperation) { + this.sourceOperation = sourceOperation; + } + + public void addInterceptor(int index, Interceptor interceptor) { + int i = 0; + Invoker next = invokerChainHead; + Invoker prev = null; + while (next != null && i < index) { + prev = next; + if (next instanceof Interceptor) { + next = ((Interceptor)next).getNext(); + i++; + } else { + throw new ArrayIndexOutOfBoundsException(index); + } + } + if (i == index) { + if (prev != null) { + ((Interceptor)prev).setNext(interceptor); + } else { + invokerChainHead = interceptor; + } + interceptor.setNext(next); + if (next == null) { + invokerChainTail = interceptor; + } + } else { + throw new ArrayIndexOutOfBoundsException(index); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java new file mode 100644 index 0000000000..5a028e6e22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java @@ -0,0 +1,95 @@ +/* + * 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.tuscany.sca.core.invocation; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.NoRegisteredCallbackException; + +/** + * Responsible for dispatching to a callback through a wire.

TODO cache + * target invoker + * + * @version $Rev$ $Date$ + */ +public class JDKCallbackInvocationHandler extends AbstractInvocationHandler implements InvocationHandler { + private static final long serialVersionUID = -3350283555825935609L; + private transient Map wires; + + /** + * Constructor used for deserialization only + */ + public JDKCallbackInvocationHandler(MessageFactory messageFactory) { + super(messageFactory, false); + wires = new HashMap(); + } + + public JDKCallbackInvocationHandler(MessageFactory messageFactory, List wireList) { + super(messageFactory, false); + this.wires = new HashMap(); + for (RuntimeWire wire : wireList) { + wires.put(wire.getSource().getURI(), wire); + } + } + + @SuppressWarnings( {"unchecked"}) + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if (method.getParameterTypes().length == 0 && "toString".equals(method.getName())) { + return "[Proxy - " + Integer.toHexString(hashCode()) + "]"; + } else if (method.getDeclaringClass().equals(Object.class) && "equals".equals(method.getName())) { + // TODO implement + throw new UnsupportedOperationException(); + } else if (Object.class.equals(method.getDeclaringClass()) && "hashCode".equals(method.getName())) { + return hashCode(); + // TODO beter hash algorithm + } + EndpointReference from = ThreadMessageContext.getMessageContext().getFrom(); + RuntimeWire wire = wires.get(from.getURI()); + assert wire != null; + List chains = wire.getCallbackInvocationChains(); + IdentityHashMap map = new IdentityHashMap(); + for (InvocationChain chain : chains) { + map.put(chain.getTargetOperation(), chain); + } + Operation operation = JavaInterfaceUtil.findOperation(method, map.keySet()); + InvocationChain chain = map.get(operation); + try { + return invoke(chain, args, wire); + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof NoRegisteredCallbackException) { + throw t; + } + throw e; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java new file mode 100644 index 0000000000..c22481cb73 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java @@ -0,0 +1,112 @@ +/* + * 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.tuscany.sca.core.invocation; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * @version $Rev$ $Date$ + */ +public class JDKInvocationHandler extends AbstractInvocationHandler implements InvocationHandler { + // private Class proxyInterface; + private RuntimeWire wire; + + public JDKInvocationHandler(MessageFactory messageFactory, Class proxyInterface, RuntimeWire wire) { + super(messageFactory, false); + this.wire = wire; + init(proxyInterface, wire); + } + + private void init(Class interfaze, RuntimeWire wire) { + InterfaceContract contract = wire.getSource().getInterfaceContract(); + this.conversational = contract.getInterface().isConversational(); + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if (method.getParameterTypes().length == 0 && "toString".equals(method.getName())) { + return "[Proxy - " + Integer.toHexString(hashCode()) + "]"; + } else if (method.getDeclaringClass().equals(Object.class) && "equals".equals(method.getName())) { + Object obj = args[0]; + if (obj == null) { + return false; + } + if (!Proxy.isProxyClass(obj.getClass())) { + return false; + } + return equals(Proxy.getInvocationHandler(obj)); + } else if (Object.class.equals(method.getDeclaringClass()) && "hashCode".equals(method.getName())) { + return hashCode(); + } + InvocationChain chain = getInvocationChain(method); + if (chain == null) { + throw new IllegalArgumentException("No matching opeeration is found: " + method); + } + + // send the invocation down the wire + Object result = invoke(chain, args, wire); + + return result; + } + + /** + * Determines if the given operation matches the given method + * + * @return true if the operation matches, false if does not + */ + private static boolean match(Operation operation, Method method) { + Class[] params = method.getParameterTypes(); + DataType> inputType = operation.getInputType(); + List types = inputType.getLogical(); + boolean matched = true; + if (types.size() == params.length && method.getName().equals(operation.getName())) { + for (int i = 0; i < params.length; i++) { + Class clazz = params[i]; + if (!clazz.equals(operation.getInputType().getLogical().get(i).getPhysical())) { + matched = false; + } + } + } else { + matched = false; + } + return matched; + + } + + private InvocationChain getInvocationChain(Method method) { + for (InvocationChain chain : wire.getInvocationChains()) { + Operation operation = chain.getSourceOperation(); + if (match(operation, method)) { + return chain; + } + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyService.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyService.java new file mode 100644 index 0000000000..371f9bedb8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyService.java @@ -0,0 +1,78 @@ +/* + * 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.tuscany.sca.core.invocation; + +import java.lang.reflect.Proxy; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; + +/** + * the default implementation of a wire service that uses JDK dynamic proxies + * + * @version $$Rev$$ $$Date: 2007-04-11 18:59:43 -0700 (Wed, 11 Apr + * 2007) $$ + */ +public class JDKProxyService implements ProxyFactory { + protected InterfaceContractMapper contractMapper; + private MessageFactory messageFactory; + + public JDKProxyService() { + this(new MessageFactoryImpl(), new InterfaceContractMapperImpl()); + } + + public JDKProxyService(MessageFactory messageFactory, InterfaceContractMapper mapper) { + this.contractMapper = mapper; + this.messageFactory = messageFactory; + } + + public T createProxy(Class interfaze, RuntimeWire wire) throws ProxyCreationException { + assert interfaze != null; + assert wire != null; + JDKInvocationHandler handler = new JDKInvocationHandler(messageFactory, interfaze, wire); + ClassLoader cl = interfaze.getClassLoader(); + return interfaze.cast(Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler)); + } + + public Object createCallbackProxy(Class interfaze, List wires) throws ProxyCreationException { + ClassLoader cl = interfaze.getClassLoader(); + JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(messageFactory, wires); + return interfaze.cast(Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler)); + } + + public > R cast(B target) throws IllegalArgumentException { + throw new UnsupportedOperationException(); + + // InvocationHandler handler = Proxy.getInvocationHandler(target); + // if (handler instanceof JDKInvocationHandler) { + // // TODO return a ServiceReference + // throw new UnsupportedOperationException(); + // } else if (handler instanceof JDKCallbackInvocationHandler) { + // // TODO return a CallbackReference + // throw new UnsupportedOperationException(); + // } else { + // throw new IllegalArgumentException("Not a Tuscany SCA proxy"); + // } + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java new file mode 100644 index 0000000000..6e182a6a14 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java @@ -0,0 +1,36 @@ +/* + * 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.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; + +/** + * Implementation of MessageFactory. + * + * @version $Rev$ $Date$ + */ +public class MessageFactoryImpl implements MessageFactory { + + public Message createMessage() { + return new MessageImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java new file mode 100644 index 0000000000..a1b2963cf5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java @@ -0,0 +1,117 @@ +/* + * 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.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; + +/** + * The default implementation of a message flowed through a wire during an invocation + * + * @version $Rev $Date + */ +public class MessageImpl implements Message { + private Object body; + private Object messageID; + private Object correlationID; + private boolean isFault; + private ConversationSequence conversationSequence; + private String conversationId; + + private EndpointReference from; + private EndpointReference to; + + public MessageImpl(String conversationId, ConversationSequence conversationSequence, Object body) { + this.conversationId = conversationId; + this.conversationSequence = conversationSequence; + this.body = body; + } + + public MessageImpl() { + } + + @SuppressWarnings("unchecked") + public T getBody() { + return (T) body; + } + + public void setBody(T body) { + this.isFault = false; + this.body = body; + } + + public String getConversationID() { + return conversationId; + } + + public void setConversationID(String conversationId) { + this.conversationId = conversationId; + } + + public ConversationSequence getConversationSequence() { + return conversationSequence; + } + + public void setConversationSequence(ConversationSequence conversationSequence) { + this.conversationSequence = conversationSequence; + } + + public Object getMessageID() { + return messageID; + } + + public void setMessageID(Object messageId) { + this.messageID = messageId; + } + + public Object getCorrelationID() { + return correlationID; + } + + public void setCorrelationID(Object correlationId) { + this.correlationID = correlationId; + } + + public boolean isFault() { + return isFault; + } + + public void setFaultBody(Object fault) { + this.isFault = true; + this.body = fault; + } + + public EndpointReference getFrom() { + return from; + } + + public void setFrom(EndpointReference from) { + this.from = from; + } + + public EndpointReference getTo() { + return to; + } + + public void setTo(EndpointReference to) { + this.to = to; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java new file mode 100644 index 0000000000..cbeedc086d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java @@ -0,0 +1,43 @@ +/* + * 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.tuscany.sca.core.invocation; + + +/** + * Thrown when an {@link org.apache.tuscany.sca.factory.model.Operation} cannot be mapped to a method on an interface + * @version $Rev$ $Date$ + */ +public class NoMethodForOperationException extends ProxyCreationException { + private static final long serialVersionUID = 5116536602309483679L; + + public NoMethodForOperationException() { + } + + public NoMethodForOperationException(String message) { + super(message); + } + + public NoMethodForOperationException(String message, Throwable cause) { + super(message, cause); + } + + public NoMethodForOperationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java new file mode 100644 index 0000000000..be6f364271 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java @@ -0,0 +1,174 @@ +/* + * 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.tuscany.sca.core.invocation; + +import java.util.LinkedList; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Adds non-blocking behavior to an invocation chain + * + * @version $$Rev$$ $$Date$$ + */ +public class NonBlockingInterceptor implements Interceptor { + + private static final Message RESPONSE = new ImmutableMessage(); + + private WorkScheduler workScheduler; + private Invoker next; + + public NonBlockingInterceptor(WorkScheduler workScheduler) { + this.workScheduler = workScheduler; + } + + public NonBlockingInterceptor(WorkScheduler workScheduler, Interceptor next) { + this.workScheduler = workScheduler; + this.next = next; + } + + public Message invoke(final Message msg) { + // Retrieve conversation id to transfer to new thread + // Notice that we cannot clear the conversation id from the current thread + final String conversationID = ThreadMessageContext.getMessageContext().getConversationID(); + // Schedule the invocation of the next interceptor in a new Work instance + try { + workScheduler.scheduleWork(new Runnable() { + public void run() { + msg.setCorrelationID(null); + // if we got a conversation id, transfer it to new thread + if (conversationID != null) { + msg.setConversationID(conversationID); + } + Message context = ThreadMessageContext.setMessageContext(msg); + try { + next.invoke(msg); + } finally { + ThreadMessageContext.setMessageContext(context); + } + } + }); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + return RESPONSE; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + /** + * A dummy message passed back on an invocation + */ + private static class ImmutableMessage implements Message { + + public String getConversationID() { + return null; + } + + public RuntimeWire getWire() { + return null; + } + + public void setConversationID(String conversationId) { + throw new UnsupportedOperationException(); + } + + public void setWire(RuntimeWire wire) { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("unchecked") + public Object getBody() { + return null; + } + + public void setBody(Object body) { + if (body != null) { + throw new UnsupportedOperationException(); + } + } + + public void setCallbackWires(LinkedList wires) { + + } + + public Object getMessageID() { + return null; + } + + public void setMessageID(Object messageId) { + throw new UnsupportedOperationException(); + } + + public Object getCorrelationID() { + return null; + } + + public void setCorrelationID(Object correlationId) { + throw new UnsupportedOperationException(); + } + + public boolean isFault() { + return false; + } + + public void setFaultBody(Object fault) { + throw new UnsupportedOperationException(); + } + + public void setConversationSequence(ConversationSequence sequence) { + throw new UnsupportedOperationException(); + } + + public ConversationSequence getConversationSequence() { + return null; + } + + public EndpointReference getFrom() { + return null; + } + + public EndpointReference getTo() { + return null; + } + + public void setFrom(EndpointReference from) { + throw new UnsupportedOperationException(); + } + + public void setTo(EndpointReference to) { + throw new UnsupportedOperationException(); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java new file mode 100644 index 0000000000..4900ae9a7e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java @@ -0,0 +1,48 @@ +/* + * 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.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.factory.ObjectCreationException; + + +/** + * Denotes an error creating a proxy + * + * @version $$Rev$$ $$Date$$ + */ +public class ProxyCreationException extends ObjectCreationException { + private static final long serialVersionUID = 8002454344828513781L; + + public ProxyCreationException() { + super(); + } + + public ProxyCreationException(String message, Throwable cause) { + super(message, cause); + } + + public ProxyCreationException(String message) { + super(message); + } + + public ProxyCreationException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java new file mode 100644 index 0000000000..381844ffc5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java @@ -0,0 +1,61 @@ +/* + * 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.tuscany.sca.core.invocation; + +import java.util.List; + +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; + +/** + * Creates proxies that implement Java interfaces and invocation handlers for fronting wires + * + * @version $$Rev$$ $$Date$$ + */ + +public interface ProxyFactory { + + /** + * Creates a Java proxy for the given wire + * + * @param interfaze the interface the proxy implements + * @param wire the wire to proxy @return the proxy + * @throws ProxyCreationException + */ + T createProxy(Class interfaze, RuntimeWire wire) throws ProxyCreationException; + + /** + * Creates a Java proxy for the service contract callback + * + * @param interfaze the interface the proxy should implement + * @return the proxy + * @throws ProxyCreationException + */ + Object createCallbackProxy(Class interfaze, List wires) throws ProxyCreationException; + + /** + * Cast a proxy to a CallableReference. + * + * @param target a proxy generated by this implementation + * @return a CallableReference (or subclass) equivalent to this prozy + * @throws IllegalArgumentException if the object supplied is not a proxy + */ + > R cast(B target) throws IllegalArgumentException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java new file mode 100644 index 0000000000..52bea91341 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java @@ -0,0 +1,68 @@ +/* + * 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.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.invocation.Message; + +/** + * Class for tunneling a WorkContext through the invocation of a user class. + * + * @version $Rev$ $Date$ + */ +public final class ThreadMessageContext { + + private static final ThreadLocal CONTEXT = new ThreadLocal() { + protected synchronized Message initialValue() { + return new MessageImpl(); + } + }; + + private ThreadMessageContext() { + } + + /** + * Set the WorkContext for the current thread. + * The current work context is returned and must be restored after the invocation is complete. + * Typical usage would be: + *

+     *   WorkContext old = PojoWorkContextTunnel.setThreadWorkContext(newContext);
+     *   try {
+     *      ... invoke user code ...
+     *   } finally {
+     *     PojoWorkContextTunnel.setThreadWorkContext(old);
+     *   }
+     * 
+ * @param context + * @return the current work context for the thread; this must be restored after the invocation is made + */ + public static Message setMessageContext(Message context) { + Message old = CONTEXT.get(); + CONTEXT.set(context); + return old; + } + + /** + * Returns the WorkContext for the current thread. + * + * @return the WorkContext for the current thread + */ + public static Message getMessageContext() { + return CONTEXT.get(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java new file mode 100644 index 0000000000..e6e41e8f85 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java @@ -0,0 +1,55 @@ +/* + * 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.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.factory.ObjectCreationException; +import org.apache.tuscany.sca.factory.ObjectFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Uses a wire to return an object instance + * + * @version $Rev$ $Date$ + */ +public class WireObjectFactory implements ObjectFactory { + private Class interfaze; + private RuntimeWire wire; + private ProxyFactory proxyService; + private boolean optimizable; + + /** + * Constructor. + * + * @param interfaze the interface to inject on the client + * @param wire the backing wire + * @param proxyService the wire service to create the proxy + * @throws NoMethodForOperationException + */ + public WireObjectFactory(Class interfaze, RuntimeWire wire, ProxyFactory proxyService) + throws NoMethodForOperationException { + this.interfaze = interfaze; + this.wire = wire; + this.proxyService = proxyService; + } + + public T getInstance() throws ObjectCreationException { + return interfaze.cast(proxyService.createProxy(interfaze, wire)); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/ActivationException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/ActivationException.java new file mode 100644 index 0000000000..987a8288b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/ActivationException.java @@ -0,0 +1,37 @@ +/* + * 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.tuscany.sca.core.runtime; + + +/** + * Denotes an error starting the runtime + * + * @version $Rev$ $Date$ + */ +public class ActivationException extends Exception { + private static final long serialVersionUID = 8612661660934426123L; + + public ActivationException(String message) { + super(message); + } + + public ActivationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivator.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivator.java new file mode 100644 index 0000000000..a390fdebfe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivator.java @@ -0,0 +1,55 @@ +/* + * 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.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.Composite; + +/** + * Start/stop a composite + * + * @version $Rev$ $Date$ + */ +public interface CompositeActivator { + + /** + * Activate a composite + * @param composite + */ + void activate(Composite composite) throws ActivationException; + + /** + * Stop a composite + * @param composite + */ + void deactivate(Composite composite) throws ActivationException; + + /** + * Start a composite + * @param composite + */ + void start(Composite composite) throws ActivationException; + + /** + * Stop a composite + * @param composite + */ + void stop(Composite composite) throws ActivationException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java new file mode 100644 index 0000000000..5308c6e0f9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java @@ -0,0 +1,597 @@ +/* + * 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.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor; +import org.apache.tuscany.sca.assembly.builder.Problem; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.core.invocation.InvocationChainImpl; +import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor; +import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; +import org.apache.tuscany.sca.scope.ScopeRegistry; +import org.apache.tuscany.sca.scope.ScopedRuntimeComponent; +import org.apache.tuscany.sca.work.WorkScheduler; + +/** + * @version $Rev$ $Date$ + */ +public class CompositeActivatorImpl implements CompositeActivator { + + private final AssemblyFactory assemblyFactory; + private final SCABindingFactory scaBindingFactory; + private final InterfaceContractMapper interfaceContractMapper; + private final ScopeRegistry scopeRegistry; + private final WorkScheduler workScheduler; + private final RuntimeWireProcessor wireProcessor; + private final ProviderFactoryExtensionPoint providerFactories; + + /** + * @param assemblyFactory + * @param interfaceContractMapper + * @param workContext + * @param workScheduler + * @param wirePostProcessorRegistry + */ + public CompositeActivatorImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + ScopeRegistry scopeRegistry, + WorkScheduler workScheduler, + RuntimeWireProcessor wireProcessor, + ProviderFactoryExtensionPoint providerFactories) { + super(); + this.assemblyFactory = assemblyFactory; + this.scaBindingFactory = scaBindingFactory; + this.interfaceContractMapper = interfaceContractMapper; + this.scopeRegistry = scopeRegistry; + this.workScheduler = workScheduler; + this.wireProcessor = wireProcessor; + this.providerFactories = providerFactories; + } + + /** + * Configure a composite + * + * @param composite + * @throws IncompatibleInterfaceContractException + */ + @SuppressWarnings("unchecked") + protected void configureComposite(Composite composite) throws IncompatibleInterfaceContractException { + for (Component component : composite.getComponents()) { + + for (ComponentService service : component.getServices()) { + for (Binding binding : service.getBindings()) { + BindingProviderFactory providerFactory = (BindingProviderFactory)providerFactories + .getProviderFactory(binding.getClass()); + if (providerFactory != null) { + ServiceBindingProvider bindingProvider = providerFactory + .createServiceBindingProvider((RuntimeComponent)component, + (RuntimeComponentService)service, + binding); + if (bindingProvider != null) { + ((RuntimeComponentService)service).setBindingProvider(binding, bindingProvider); + } + } else { + throw new IllegalStateException("Provider factory not found for class: " + binding.getClass() + .getName()); + } + } + } + for (ComponentReference reference : component.getReferences()) { + for (Binding binding : reference.getBindings()) { + BindingProviderFactory providerFactory = (BindingProviderFactory)providerFactories + .getProviderFactory(binding.getClass()); + if (providerFactory != null) { + ReferenceBindingProvider bindingProvider = providerFactory + .createReferenceBindingProvider((RuntimeComponent)component, + (RuntimeComponentReference)reference, + binding); + if (bindingProvider != null) { + ((RuntimeComponentReference)reference).setBindingProvider(binding, bindingProvider); + } + } else { + throw new IllegalStateException("Provider factory not found for class: " + binding.getClass() + .getName()); + } + } + } + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + configureComposite((Composite)implementation); + } else if (implementation != null) { + ImplementationProviderFactory providerFactory = (ImplementationProviderFactory)providerFactories + .getProviderFactory(implementation.getClass()); + if (providerFactory != null) { + ImplementationProvider implementationProvider = providerFactory + .createImplementationProvider((RuntimeComponent)component, implementation); + if (implementationProvider != null) { + ((RuntimeComponent)component).setImplementationProvider(implementationProvider); + } + } else { + throw new IllegalStateException("Provider factory not found for class: " + implementation + .getClass().getName()); + } + setScopeContainer(component); + } + } + } + + /** + * Start a composite + */ + protected void startComposite(Composite composite) { + for (Component component : composite.getComponents()) { + + for (ComponentService service : component.getServices()) { + for (Binding binding : service.getBindings()) { + ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service) + .getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.start(); + } + } + } + for (ComponentReference reference : component.getReferences()) { + for (Binding binding : reference.getBindings()) { + ReferenceBindingProvider bindingProvider = ((RuntimeComponentReference)reference) + .getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.start(); + } + } + } + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + startComposite((Composite)implementation); + } else { + ImplementationProvider implementationProvider = ((RuntimeComponent)component) + .getImplementationProvider(); + if (implementationProvider != null) { + implementationProvider.start(); + } + } + + if (component instanceof ScopedRuntimeComponent) { + ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; + if (runtimeComponent.getScopeContainer() != null) { + runtimeComponent.getScopeContainer().start(); + } + } + + } + } + + public void stop(Composite composite) { + for (Component component : composite.getComponents()) { + + for (ComponentService service : component.getServices()) { + for (Binding binding : service.getBindings()) { + ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service) + .getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.stop(); + } + } + } + for (ComponentReference reference : component.getReferences()) { + for (Binding binding : reference.getBindings()) { + ReferenceBindingProvider bindingProvider = ((RuntimeComponentReference)reference) + .getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.stop(); + } + } + } + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + stop((Composite)implementation); + } else { + ImplementationProvider implementationProvider = ((RuntimeComponent)component) + .getImplementationProvider(); + if (implementationProvider != null) { + implementationProvider.stop(); + } + } + + if (component instanceof ScopedRuntimeComponent) { + ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; + if (runtimeComponent.getScopeContainer() != null) { + runtimeComponent.getScopeContainer().stop(); + } + } + + } + + } + + /** + * Create runtime wires for the composite + * + * @param composite + * @throws IncompatibleInterfaceContractException + */ + protected void createRuntimeWires(Composite composite) throws IncompatibleInterfaceContractException { + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + // Recursively create runtime wires + createRuntimeWires((Composite)implementation); + } else { + // Create outbound wires for the component references + for (ComponentReference reference : component.getReferences()) { + for (Binding binding : reference.getBindings()) { + createWires(component, reference, binding); + } + } + // Create inbound wires for the component services + for (ComponentService service : component.getServices()) { + for (Binding binding : service.getBindings()) { + createWires(component, service, binding); + } + } + } + } + } + + /** + * Get the effective interface contract for a reference binding + * + * @param reference + * @param binding + * @return + */ + private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) { + InterfaceContract interfaceContract = reference.getInterfaceContract(); + ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); + if (provider != null) { + InterfaceContract bindingContract = provider.getBindingInterfaceContract(); + if (bindingContract != null) { + interfaceContract = bindingContract; + } + } + return interfaceContract; + } + + /** + * Create the runtime wires for a reference binding + * + * @param component + * @param reference + * @param binding + */ + private void createWires(Component component, ComponentReference reference, Binding binding) { + if (!(reference instanceof RuntimeComponentReference)) { + return; + } + RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference; + InterfaceContract bindingContract = getInterfaceContract(reference, binding); + + if (!(binding instanceof SCABinding)) { + InterfaceContract sourceContract = reference.getInterfaceContract(); + + // Component Reference --> External Service + EndpointReference wireSource = new EndpointReferenceImpl((RuntimeComponent)component, + (RuntimeComponentReference)reference, binding, + sourceContract); + + EndpointReference wireTarget = new EndpointReferenceImpl(null, null, binding, bindingContract); + RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget); + + for (Operation operation : sourceContract.getInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(bindingContract.getInterface(), operation); + InvocationChain chain = new InvocationChainImpl(operation, targetOperation); + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(workScheduler)); + } + addBindingInterceptor(component, reference, binding, chain, operation, false); + wire.getInvocationChains().add(chain); + } + if (sourceContract.getCallbackInterface() != null) { + for (Operation operation : sourceContract.getCallbackInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(bindingContract.getCallbackInterface(), + operation); + InvocationChain chain = new InvocationChainImpl(operation, targetOperation); + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(workScheduler)); + } + addBindingInterceptor(component, reference, binding, chain, operation, true); + wire.getCallbackInvocationChains().add(chain); + } + } + runtimeRef.getRuntimeWires().add(wire); + wireProcessor.process(wire); + } + for (ComponentService service : reference.getTargets()) { + Component target = null; + SCABinding scaBinding = service.getBinding(SCABinding.class); + if (scaBinding != null) { + target = scaBinding.getComponent(); + } + + // FIXME: [rfeng] Ignore unresolved services + if (service.isUnresolved()) { + continue; + } + + // FIXME: [rfeng] We might need a better way to get the impl interface contract + InterfaceContract targetContract = service.getService().getInterfaceContract(); + + EndpointReference wireSource = new EndpointReferenceImpl((RuntimeComponent)component, + (RuntimeComponentReference)reference, binding, + bindingContract); + + EndpointReference wireTarget = new EndpointReferenceImpl((RuntimeComponent)target, + (RuntimeComponentService)service, binding, + targetContract); + + RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget); + + for (Operation operation : bindingContract.getInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation); + InvocationChain chain = new InvocationChainImpl(operation, targetOperation); + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(workScheduler)); + } + addBindingInterceptor(component, reference, binding, chain, operation, false); + if (target != null) { + addImplementationInterceptor(target, service, chain, targetOperation, false); + } + wire.getInvocationChains().add(chain); + } + if (bindingContract.getCallbackInterface() != null) { + if (reference.getName().startsWith("$self$.")) { + // No callback is needed + continue; + } + for (Operation operation : bindingContract.getCallbackInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(targetContract.getCallbackInterface(), + operation); + InvocationChain chain = new InvocationChainImpl(operation, targetOperation); + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(workScheduler)); + } + addBindingInterceptor(component, reference, binding, chain, operation, true); + addImplementationInterceptor(component, null, chain, targetOperation, true); + wire.getCallbackInvocationChains().add(chain); + } + } + + runtimeRef.getRuntimeWires().add(wire); + if (!wire.getCallbackInvocationChains().isEmpty()) { + if (wire.getTarget().getContract() != null) { + ((RuntimeComponentService) wire.getTarget().getContract()).getCallbackWires().add(wire); + } + } + wireProcessor.process(wire); + } + } + + /** + * Get the effective interface contract for the service binding + * + * @param service + * @param binding + * @return + */ + private InterfaceContract getInterfaceContract(ComponentService service, Binding binding) { + InterfaceContract interfaceContract = service.getInterfaceContract(); + + ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding); + if (provider != null) { + InterfaceContract bindingContract = provider.getBindingInterfaceContract(); + if (bindingContract != null) { + interfaceContract = bindingContract; + } + } + return interfaceContract; + } + + /** + * Create runtime wires for a service binding + * + * @param component + * @param service + * @param binding + */ + private void createWires(Component component, ComponentService service, Binding binding) { + if (!(service instanceof RuntimeComponentService)) { + return; + } + RuntimeComponentService runtimeService = (RuntimeComponentService)service; + + // FIXME: [rfeng] We might need a better way to get the impl interface contract + InterfaceContract targetContract = service.getService().getInterfaceContract(); + + InterfaceContract sourceContract = getInterfaceContract(service, binding); + + EndpointReference wireSource = new EndpointReferenceImpl(null, null, binding, sourceContract); + + EndpointReference wireTarget = new EndpointReferenceImpl((RuntimeComponent)component, + (RuntimeComponentService)service, binding, + targetContract); + + RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget); + + for (Operation operation : sourceContract.getInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation); + InvocationChain chain = new InvocationChainImpl(operation, targetOperation); + /* lresende */ + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(workScheduler)); + } + + addImplementationInterceptor(component, service, chain, targetOperation, false); + wire.getInvocationChains().add(chain); + } + // if (sourceContract.getCallbackInterface() != null) { + // for (Operation operation : + // sourceContract.getCallbackInterface().getOperations()) { + // Operation targetOperation = + // interfaceContractMapper.map(targetContract.getCallbackInterface(), + // operation); + // InvocationChain chain = new InvocationChainImpl(operation, + // targetOperation); + // if (operation.isNonBlocking()) { + // chain.addInterceptor(new NonBlockingInterceptor(workScheduler, + // workContext)); + // } + // addImplementationInterceptor(component, service, chain, operation, + // true); + // wire.getCallbackInvocationChains().add(chain); + // } + // } + + runtimeService.getRuntimeWires().add(wire); + wireProcessor.process(wire); + } + + /** + * Add the interceptor for a component implementation + * + * @param component + * @param service + * @param chain + * @param operation + * @param isCallback + */ + private void addImplementationInterceptor(Component component, + ComponentService service, + InvocationChain chain, + Operation operation, + boolean isCallback) { + ImplementationProvider provider = ((RuntimeComponent)component).getImplementationProvider(); + if (provider != null) { + Invoker invoker = null; + if (!isCallback) { + invoker = provider.createInvoker((RuntimeComponentService)service, operation); + } else { + invoker = provider.createCallbackInvoker(operation); + } + chain.addInvoker(invoker); + } + } + + /** + * Add the interceptor for a binding + * + * @param component + * @param reference + * @param binding + * @param chain + * @param operation + * @param isCallback + */ + private void addBindingInterceptor(Component component, + ComponentReference reference, + Binding binding, + InvocationChain chain, + Operation operation, + boolean isCallback) { + ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); + if (provider != null) { + Invoker invoker = provider.createInvoker(operation, isCallback); + if (invoker != null) { + chain.addInvoker(invoker); + } + } + } + + private void setScopeContainer(Component component) { + if (!(component instanceof ScopedRuntimeComponent)) { + return; + } + ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; + runtimeComponent.setScopeContainer(scopeRegistry.getScopeContainer(runtimeComponent)); + } + + protected void buildComposite(Composite composite) throws CompositeBuilderException { + + CompositeBuilderMonitor monitor = new CompositeBuilderMonitor() { + + public void problem(Problem problem) { + // Uncommenting the following two lines can be useful to detect + // and troubleshoot SCA assembly XML composite configuration + // problems. + + System.out.println("Composite assembly problem: " + problem.getMessage()); + } + }; + + CompositeBuilderImpl builder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, monitor); + + builder.build(composite); + + // if (!problems.isEmpty()) { + // throw new VariantRuntimeException(new RuntimeException("Problems in + // the composite...")); + // } + } + + public void activate(Composite composite) throws ActivationException { + try { + buildComposite(composite); + configureComposite(composite); + createRuntimeWires(composite); + } catch (Exception e) { + throw new ActivationException(e); + } + } + + public void deactivate(Composite composite) throws ActivationException { + } + + public void start(Composite composite) throws ActivationException { + try { + startComposite(composite); + } catch (Exception e) { + throw new ActivationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java new file mode 100644 index 0000000000..233f81ccae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java @@ -0,0 +1,128 @@ +/* + * 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.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class EndpointReferenceImpl implements EndpointReference { + private RuntimeComponent component; + private Contract contract; + private Binding binding; + private InterfaceContract interfaceContract; + private String uri; + + /** + * @param component + * @param contract + * @param binding + * @param interfaceContract + */ + public EndpointReferenceImpl(RuntimeComponent component, + Contract contract, + Binding binding, + InterfaceContract interfaceContract) { + super(); + this.component = component; + this.contract = contract; + this.binding = binding; + this.interfaceContract = interfaceContract; + this.uri = binding.getURI(); + } + + /** + * @param uri + */ + public EndpointReferenceImpl(String uri) { + super(); + this.uri = uri; + } + + public Binding getBinding() { + return binding; + } + + public void setBinding(Binding binding) { + this.binding = binding; + } + + public RuntimeComponent getComponent() { + return component; + } + + public void setComponent(RuntimeComponent component) { + this.component = component; + } + + public Contract getContract() { + return contract; + } + + public void setContract(Contract contract) { + this.contract = contract; + } + + public InterfaceContract getInterfaceContract() { + return interfaceContract; + } + + public void setInterfaceContract(InterfaceContract interfaceContract) { + this.interfaceContract = interfaceContract; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + @Override + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((uri == null) ? 0 : uri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final EndpointReferenceImpl other = (EndpointReferenceImpl)obj; + if (uri == null) { + if (other.uri != null) + return false; + } else if (!uri.equals(other.uri)) + return false; + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeAssemblyFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeAssemblyFactory.java new file mode 100644 index 0000000000..ec0cdadde6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeAssemblyFactory.java @@ -0,0 +1,61 @@ +/* + * 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.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements AssemblyFactory { + private final ProxyFactory proxyFactory; + private final InterfaceContractMapper interfaceContractMapper; + + /** + * @param proxyFactory + */ + public RuntimeAssemblyFactory(InterfaceContractMapper interfaceContractMapper, ProxyFactory proxyFactory) { + super(); + this.proxyFactory = proxyFactory; + this.interfaceContractMapper = interfaceContractMapper; + } + + @Override + public Component createComponent() { + return new RuntimeComponentImpl(proxyFactory); + } + + @Override + public ComponentReference createComponentReference() { + return new RuntimeComponentReferenceImpl(interfaceContractMapper); + } + + @Override + public ComponentService createComponentService() { + return new RuntimeComponentServiceImpl(interfaceContractMapper); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java new file mode 100644 index 0000000000..aacce904b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java @@ -0,0 +1,128 @@ +/* + * 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.tuscany.sca.core.runtime; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.impl.ComponentImpl; +import org.apache.tuscany.sca.core.component.ServiceReferenceImpl; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.core.invocation.WireObjectFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopedRuntimeComponent; +import org.osoa.sca.CallableReference; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeComponentImpl extends ComponentImpl implements RuntimeComponent, ScopedRuntimeComponent { + public static final String SELF_REFERENCE_PREFIX = "$self$."; + protected ImplementationProvider implementationProvider; + protected ProxyFactory proxyService; + protected ScopeContainer scopeContainer; + + /** + * @param proxyService + */ + public RuntimeComponentImpl(ProxyFactory proxyService) { + super(); + this.proxyService = proxyService; + } + + public ServiceReference createSelfReference(Class businessInterface) { + return getServiceReference(businessInterface, SELF_REFERENCE_PREFIX); + } + + public ServiceReference createSelfReference(Class businessInterface, String serviceName) { + return getServiceReference(businessInterface, SELF_REFERENCE_PREFIX + serviceName); + } + + public B getProperty(Class type, String propertyName) { + for (Property p : getProperties()) { + if (p.getName().equals(propertyName)) { + // FIXME: Need to use the property object factory to create the + // instance + return null; + } + } + return null; + } + + public RequestContext getRequestContext() { + return null; + } + + public B getService(Class businessInterface, String referenceName) { + List refs = getReferences(); + for (ComponentReference ref : refs) { + if (ref.getName().equals(referenceName)) { + RuntimeComponentReference attachPoint = (RuntimeComponentReference)ref; + RuntimeWire wire = attachPoint.getRuntimeWires().get(0); + return proxyService.createProxy(businessInterface, wire); + } + } + return null; + } + + public ServiceReference getServiceReference(Class businessInterface, String referenceName) { + List references = getReferences(); + for (ComponentReference reference : references) { + if (reference.getName().equals(referenceName) || referenceName.equals("$self$.") + && reference.getName().startsWith(referenceName)) { + RuntimeComponentReference attachPoint = (RuntimeComponentReference)reference; + RuntimeWire wire = attachPoint.getRuntimeWires().get(0); + WireObjectFactory factory = new WireObjectFactory(businessInterface, wire, proxyService); + return new ServiceReferenceImpl(businessInterface, factory); + } + } + return null; + + } + + @SuppressWarnings("unchecked") + public > R cast(B target) throws IllegalArgumentException { + Object ref = proxyService.cast(target); + return (R)ref; + } + + public ImplementationProvider getImplementationProvider() { + return implementationProvider; + } + + public void setImplementationProvider(ImplementationProvider provider) { + this.implementationProvider = provider; + } + + public ScopeContainer getScopeContainer() { + return scopeContainer; + } + + public void setScopeContainer(ScopeContainer scopeContainer) { + this.scopeContainer = scopeContainer; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java new file mode 100644 index 0000000000..128ae29b81 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java @@ -0,0 +1,86 @@ +/* + * 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.tuscany.sca.core.runtime; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implements RuntimeComponentReference { + private List wires = new ArrayList(); + private Map bindingProviders = new HashMap(); + private InterfaceContractMapper mapper; + + public RuntimeComponentReferenceImpl(InterfaceContractMapper mapper) { + super(); + this.mapper = mapper; + } + + public void addRuntimeWire(RuntimeWire wire) { + wires.add(wire); + } + + public List getRuntimeWires() { + return wires; + } + + public RuntimeWire getRuntimeWire(Binding binding) { + for (RuntimeWire wire : wires) { + if (wire.getSource().getBinding() == binding) { + return wire; + } + } + return null; + } + + public ReferenceBindingProvider getBindingProvider(Binding binding) { + return bindingProviders.get(binding); + } + + public void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider) { + bindingProviders.put(binding, bindingProvider); + } + + public Invoker getInvoker(Binding binding, Operation operation) { + RuntimeWire wire = getRuntimeWire(binding); + if (wire == null) { + return null; + } + for (InvocationChain chain : wire.getInvocationChains()) { + Operation op = chain.getSourceOperation(); + if (mapper.isCompatible(operation, op, op.getInterface().isRemotable())) { + return chain.getHeadInvoker(); + } + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java new file mode 100644 index 0000000000..0bb8e2c457 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java @@ -0,0 +1,109 @@ +/* + * 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.tuscany.sca.core.runtime; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements RuntimeComponentService { + private InterfaceContractMapper mapper; + + public RuntimeComponentServiceImpl(InterfaceContractMapper mapper) { + super(); + this.mapper = mapper; + } + + private List wires = new ArrayList(); + private List callbackWires = new ArrayList(); + private Map bindingProviders = new HashMap(); + + public void addRuntimeWire(RuntimeWire wire) { + wires.add(wire); + } + + public List getRuntimeWires() { + return wires; + } + + public RuntimeWire getRuntimeWire(Binding binding) { + for (RuntimeWire wire : wires) { + if (wire.getTarget().getBinding() == binding) { + return wire; + } + } + return null; + } + + public List getCallbackWires() { + return callbackWires; + } + + public void addCallbackWire(RuntimeWire callbackWire) { + this.callbackWires.add(callbackWire); + } + + public ServiceBindingProvider getBindingProvider(Binding binding) { + return bindingProviders.get(binding); + } + + public void setBindingProvider(Binding binding, ServiceBindingProvider bindingProvider) { + bindingProviders.put(binding, bindingProvider); + } + + public Invoker getInvoker(Binding binding, Operation operation) { + RuntimeWire wire = getRuntimeWire(binding); + if (wire == null) { + return null; + } + for (InvocationChain chain : wire.getInvocationChains()) { + Operation op = chain.getTargetOperation(); + if (mapper.isCompatible(operation, op, op.getInterface().isRemotable())) { + return chain.getHeadInvoker(); + } + } + return null; + } + + public Invoker getCallbackInvoker(Binding binding, Operation operation) { + for (RuntimeWire wire : callbackWires) { + if (wire.getTarget().getBinding() == binding) { + for (InvocationChain chain : wire.getCallbackInvocationChains()) { + Operation op = chain.getSourceOperation(); + if (mapper.isCompatible(operation, op, op.getInterface().isRemotable())) { + return chain.getHeadInvoker(); + } + } + } + } + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProvider.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProvider.java new file mode 100644 index 0000000000..ad055731f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProvider.java @@ -0,0 +1,55 @@ +/* + * 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.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeSCABindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + + public RuntimeSCABindingProvider(RuntimeComponent component, RuntimeComponentReference reference, SCABinding binding) { + this.reference = reference; + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public Invoker createInvoker(Operation operation, boolean isCallback) { + return null; + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProviderFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProviderFactory.java new file mode 100644 index 0000000000..06b7b3d40e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProviderFactory.java @@ -0,0 +1,51 @@ +/* + * 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.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeSCABindingProviderFactory implements BindingProviderFactory { + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + SCABinding binding) { + return new RuntimeSCABindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + SCABinding binding) { + return null; + } + + public Class getModelType() { + return SCABinding.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java new file mode 100644 index 0000000000..cdf7ec01c0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java @@ -0,0 +1,66 @@ +/* + * 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.tuscany.sca.core.runtime; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeWireImpl implements RuntimeWire { + private EndpointReference wireSource; + private EndpointReference wireTarget; + + private final List chains = new ArrayList(); + private final List callbackChains = new ArrayList(); + + /** + * @param source + * @param target + */ + public RuntimeWireImpl(EndpointReference source, + EndpointReference target) { + super(); + this.wireSource = source; + this.wireTarget = target; + } + + public List getCallbackInvocationChains() { + return callbackChains; + } + + public List getInvocationChains() { + return chains; + } + + public EndpointReference getSource() { + return wireSource; + } + + public EndpointReference getTarget() { + return wireTarget; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java new file mode 100644 index 0000000000..1d776b729c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java @@ -0,0 +1,146 @@ +/* + * 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.tuscany.sca.core.scope; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.AbstractLifecycle; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.PersistenceException; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopedImplementationProvider; +import org.apache.tuscany.sca.scope.TargetDestructionException; +import org.apache.tuscany.sca.scope.TargetResolutionException; + +/** + * Implements functionality common to scope contexts. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractScopeContainer extends AbstractLifecycle implements ScopeContainer { + protected Map> wrappers = new ConcurrentHashMap>(); + protected final Scope scope; + + protected RuntimeComponent component; + + public AbstractScopeContainer(Scope scope, RuntimeComponent component) { + this.scope = scope; + this.component = component; + } + + protected void checkInit() { + if (getLifecycleState() != RUNNING) { + throw new IllegalStateException("Scope container not running [" + getLifecycleState() + "]"); + } + } + + /** + * Creates a new physical instance of a component, wrapped in an + * InstanceWrapper. + * + * @param component the component whose instance should be created + * @return a wrapped instance that has been injected but not yet started + * @throws TargetResolutionException if there was a problem creating the + * instance + */ + protected InstanceWrapper createInstanceWrapper() throws TargetResolutionException { + ImplementationProvider implementationProvider = component.getImplementationProvider(); + if (implementationProvider instanceof ScopedImplementationProvider) { + return ((ScopedImplementationProvider)implementationProvider).createInstanceWrapper(); + } + return null; + } + + public InstanceWrapper getAssociatedWrapper(KEY contextId) throws TargetResolutionException { + return null; + } + + public Scope getScope() { + return scope; + } + + public InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException { + return wrappers.get(contextId); + } + + public void onEvent(Event event) { + } + + protected boolean isEagerInit() { + ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider(); + if (implementationProvider instanceof ScopedImplementationProvider) { + return ((ScopedImplementationProvider)implementationProvider).isEagerInit(); + } + return false; + } + + public void remove() throws PersistenceException { + throw new UnsupportedOperationException("Scope does not support persistence"); + } + + public void returnWrapper(InstanceWrapper wrapper, KEY contextId) throws TargetDestructionException { + } + + public synchronized void start() { + int lifecycleState = getLifecycleState(); + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + setLifecycleState(RUNNING); + } + + public void startContext(KEY contextId) { + if(isEagerInit()) { + try { + getWrapper(contextId); + } catch (TargetResolutionException e) { + // + } + } + } + + public synchronized void stop() { + int lifecycleState = getLifecycleState(); + if (lifecycleState != RUNNING) { + throw new IllegalStateException("Scope in wrong state [" + lifecycleState + "]"); + } + setLifecycleState(STOPPED); + } + + public void stopContext(KEY contextId) { + wrappers.remove(contextId); + } + + public String toString() { + return "In state [" + super.toString() + ']'; + } + + public RuntimeComponent getComponent() { + return component; + } + + public void setComponent(RuntimeComponent component) { + this.component = component; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java new file mode 100644 index 0000000000..520d3ab48c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java @@ -0,0 +1,70 @@ +/* + * 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.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.TargetNotFoundException; +import org.apache.tuscany.sca.scope.TargetResolutionException; + +/** + * A scope context which manages atomic component instances keyed by composite + * + * @version $Rev$ $Date$ + */ +public class CompositeScopeContainer extends AbstractScopeContainer { + private InstanceWrapper wrapper; + + public CompositeScopeContainer(RuntimeComponent component) { + super(Scope.COMPOSITE, component); + } + + public synchronized void stop() { + super.stop(); + wrapper = null; + } + + public InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException { + if (wrapper == null) { + wrapper = createInstanceWrapper(); + wrapper.start(); + } + return wrapper; + } + + public InstanceWrapper getAssociatedWrapper(KEY contextId) throws TargetResolutionException { + if (wrapper == null) { + throw new TargetNotFoundException(component.getURI()); + } + return wrapper; + } + + @Override + public synchronized void start() { + super.start(); + if(isEagerInit()) { + try { + getWrapper(null); + } catch (TargetResolutionException e) { + throw new IllegalStateException(e); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java new file mode 100644 index 0000000000..7078903b8b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java @@ -0,0 +1,40 @@ +/* + * 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.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; + +/** + * @version $Rev$ $Date$ + */ +public class CompositeScopeContainerFactory implements ScopeContainerFactory { + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new CompositeScopeContainer(component); + } + + public Scope getScope() { + return Scope.COMPOSITE; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java new file mode 100644 index 0000000000..61f7d51c29 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java @@ -0,0 +1,182 @@ +/* + * 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.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.PersistenceException; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.TargetDestructionException; +import org.apache.tuscany.sca.scope.TargetResolutionException; +import org.apache.tuscany.sca.store.Store; +import org.apache.tuscany.sca.store.StoreExpirationEvent; + +/** + * A scope context which manages atomic component instances keyed on a + * conversation session + * + * @version $Rev: 452655 $ $Date: 2006-10-03 18:09:02 -0400 (Tue, 03 Oct 2006) $ + */ +public class ConversationalScopeContainer extends AbstractScopeContainer implements ScopeContainer { + private final Store nonDurableStore; + + public ConversationalScopeContainer(Store store, RuntimeComponent component) { + super(Scope.CONVERSATION, component); + this.nonDurableStore = store; + if (store != null) { + store.addListener(new ExpirationListener()); + } + } + + public void onEvent(Event event) { + checkInit(); + } + + public synchronized void start() { + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + lifecycleState = RUNNING; + } + + public synchronized void stop() { + lifecycleState = STOPPED; + } + + public void persistNew(RuntimeComponent component, String id, Object instance, long expiration) + throws PersistenceException { + // try { + // nonDurableStore.insertRecord(component, id, instance, expiration); + // } catch (StoreWriteException e) { + // throw new PersistenceException(e); + // } + } + + public void persist(RuntimeComponent component, String id, Object instance, long expiration) + throws PersistenceException { + // try { + // nonDurableStore.updateRecord(component, id, instance, expiration); + // } catch (StoreWriteException e) { + // throw new PersistenceException(e); + // } + } + + public void remove(RuntimeComponent component) throws PersistenceException { + // String conversationId = getConversationId(); + // try { + // workContext.setCurrentAtomicComponent(component); + // // FIXME this should be an InstanceWrapper and shouldn't we stop it? + // Object instance = nonDurableStore.readRecord(component, + // conversationId); + // if (instance != null) { + // nonDurableStore.removeRecord(component, conversationId); + // } + // } catch (StoreReadException e) { + // throw new PersistenceException(e); + // } catch (StoreWriteException e) { + // throw new PersistenceException(e); + // } + } + + protected InstanceWrapper getInstanceWrapper(RuntimeComponent component, boolean create) + throws TargetResolutionException { + throw new UnsupportedOperationException("To be implemented"); + // String conversationId = getConversationId(); + // try { + // workContext.setCurrentAtomicComponent(component); + // InstanceWrapper wrapper = (InstanceWrapper) + // nonDurableStore.readRecord(component, conversationId); + // if (wrapper != null) { + // if (component.getMaxIdleTime() > 0) { + // // update expiration + // long expire = System.currentTimeMillis() + + // component.getMaxIdleTime(); + // nonDurableStore.updateRecord(component, conversationId, wrapper, + // expire); + // } + // } else if (create) { + // // FIXME should the store really be persisting the wrappers + // wrapper = component.createInstanceWrapper(); + // wrapper.start(); + // long expire = calculateExpiration(component); + // nonDurableStore.insertRecord(component, conversationId, wrapper, + // expire); + // } + // return wrapper; + // } catch (StoreReadException e) { + // throw new TargetResolutionException("Error retrieving target + // instance", e); + // } catch (StoreWriteException e) { + // throw new TargetResolutionException("Error persisting target + // instance", e); + // } finally { + // workContext.setCurrentAtomicComponent(null); + // } + } + + /** + * Returns the conversation id associated with the current invocation + * context + * + * @return the conversation id + */ + private String getConversationId() { + String conversationId = ThreadMessageContext.getMessageContext().getConversationID(); + assert conversationId != null; + return conversationId; + } + + // private long calculateExpiration(RuntimeComponent component) { + // if (component.getMaxAge() > 0) { + // long now = System.currentTimeMillis(); + // return now + component.getMaxAge(); + // } else if (component.getMaxIdleTime() > 0) { + // long now = System.currentTimeMillis(); + // return now + component.getMaxIdleTime(); + // } else { + // return Store.DEFAULT_EXPIRATION_OFFSET; + // } + // } + + /** + * Receives expiration events from the store and notifies the corresponding + * atomic component + */ + private static class ExpirationListener implements RuntimeEventListener { + + public ExpirationListener() { + } + + public void onEvent(Event event) { + if (event instanceof StoreExpirationEvent) { + StoreExpirationEvent expiration = (StoreExpirationEvent)event; + InstanceWrapper wrapper = (InstanceWrapper)expiration.getInstance(); + try { + wrapper.stop(); + } catch (TargetDestructionException e) { + // monitor.destructionError(e); + } + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java new file mode 100644 index 0000000000..4fdda90bc2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java @@ -0,0 +1,47 @@ +/* + * 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.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; +import org.apache.tuscany.sca.store.Store; + +/** + * @version $Rev$ $Date$ + */ +public class ConversationalScopeContainerFactory implements ScopeContainerFactory { + private Store store; + + public ConversationalScopeContainerFactory(Store store) { + super(); + this.store = store; + } + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new ConversationalScopeContainer(store, component); + } + + public Scope getScope() { + return Scope.CONVERSATION; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java new file mode 100644 index 0000000000..bcbf3cdf3c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java @@ -0,0 +1,81 @@ +/* + * 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.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.core.event.HttpSessionEnd; +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.TargetResolutionException; + +/** + * A scope context which manages atomic component instances keyed on HTTP + * session + * + * @version $Rev$ $Date$ + */ +public class HttpSessionScopeContainer extends AbstractScopeContainer { + + public HttpSessionScopeContainer(RuntimeComponent component) { + super(Scope.SESSION, component); + } + + public void onEvent(Event event) { + checkInit(); + if (event instanceof HttpSessionEnd) { + Object key = ((HttpSessionEnd)event).getSessionID(); + // FIXME: Remove the session id + } + } + + public synchronized void start() { + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + lifecycleState = RUNNING; + } + + public synchronized void stop() { + lifecycleState = STOPPED; + } + + protected InstanceWrapper getInstanceWrapper(boolean create) throws TargetResolutionException { +// Object key = workContext.getIdentifier(Scope.SESSION); + // FIXME: Need to fix this + Object key ="http-session-id"; + assert key != null : "HTTP session key not bound in work context"; + InstanceWrapper ctx = wrappers.get(key); + if (ctx == null && !create) { + return null; + } + if (ctx == null) { + ctx = super.createInstanceWrapper(); + ctx.start(); + wrappers.put(key, ctx); + } + return ctx; + } + + @Override + public InstanceWrapper getWrapper(Object contextId) throws TargetResolutionException { + return getInstanceWrapper(true); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java new file mode 100644 index 0000000000..e275bb56b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java @@ -0,0 +1,44 @@ +/* + * 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.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; + +/** + * @version $Rev$ $Date$ + */ +public class HttpSessionScopeContainerFactory implements ScopeContainerFactory { + + public HttpSessionScopeContainerFactory() { + super(); + } + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new HttpSessionScopeContainer(component); + } + + public Scope getScope() { + return Scope.SESSION; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java new file mode 100644 index 0000000000..aaafb4603c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java @@ -0,0 +1,85 @@ +/* + * 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.tuscany.sca.core.scope; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.core.event.RequestEnd; +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.TargetResolutionException; + +/** + * A scope context which manages atomic component instances keyed on the current + * request context + * + * @version $Rev$ $Date$ + */ +public class RequestScopeContainer extends AbstractScopeContainer { + private final Map contexts; + + public RequestScopeContainer(RuntimeComponent component) { + super(Scope.REQUEST, component); + contexts = new ConcurrentHashMap(); + } + + public void onEvent(Event event) { + checkInit(); + if (event instanceof RequestEnd) { + // shutdownInstances(Thread.currentThread()); + } + } + + public synchronized void start() { + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + lifecycleState = RUNNING; + } + + public synchronized void stop() { + contexts.clear(); + // synchronized (destroyQueues) { + // destroyQueues.clear(); + // } + lifecycleState = STOPPED; + } + + protected InstanceWrapper getInstanceWrapper(boolean create) throws TargetResolutionException { + InstanceWrapper ctx = wrappers.get(Thread.currentThread()); + if (ctx == null && !create) { + return null; + } + if (ctx == null) { + ctx = super.createInstanceWrapper(); + ctx.start(); + wrappers.put(Thread.currentThread(), ctx); + } + return ctx; + } + + @Override + public InstanceWrapper getWrapper(Thread contextId) throws TargetResolutionException { + return getInstanceWrapper(true); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java new file mode 100644 index 0000000000..3851637220 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java @@ -0,0 +1,40 @@ +/* + * 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.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; + +/** + * @version $Rev$ $Date$ + */ +public class RequestScopeContainerFactory implements ScopeContainerFactory { + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new RequestScopeContainer(component); + } + + public Scope getScope() { + return Scope.REQUEST; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java new file mode 100644 index 0000000000..774c1edf37 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java @@ -0,0 +1,68 @@ +/* + * 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.tuscany.sca.core.scope; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; +import org.apache.tuscany.sca.scope.ScopeRegistry; +import org.apache.tuscany.sca.scope.ScopedImplementationProvider; +import org.apache.tuscany.sca.scope.ScopedRuntimeComponent; + +/** + * The default implementation of a scope registry + * + * @version $Rev$ $Date$ + */ +public class ScopeRegistryImpl implements ScopeRegistry { + private final Map scopeCache = new ConcurrentHashMap(); + + public void register(ScopeContainerFactory factory) { + scopeCache.put(factory.getScope(), factory); + } + + public ScopeContainer getScopeContainer(RuntimeComponent runtimeComponent) { + if (!(runtimeComponent instanceof ScopedRuntimeComponent)) { + return null; + } + ScopedRuntimeComponent component = (ScopedRuntimeComponent)runtimeComponent; + if (component.getScopeContainer() != null) { + return component.getScopeContainer(); + } + ImplementationProvider implementationProvider = component.getImplementationProvider(); + if (implementationProvider instanceof ScopedImplementationProvider) { + ScopedImplementationProvider provider = (ScopedImplementationProvider)implementationProvider; + Scope scope = provider.getScope(); + if (scope == null) { + scope = Scope.STATELESS; + } + ScopeContainerFactory factory = scopeCache.get(scope); + ScopeContainer container = factory.createScopeContainer(component); + component.setScopeContainer(container); + return container; + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java new file mode 100644 index 0000000000..dd481fa062 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java @@ -0,0 +1,54 @@ +/* + * 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.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.TargetDestructionException; +import org.apache.tuscany.sca.scope.TargetResolutionException; + +/** + * A scope context which manages stateless atomic component instances in a non-pooled fashion. + * + * @version $Rev$ $Date$ + */ +public class StatelessScopeContainer extends AbstractScopeContainer { + + public StatelessScopeContainer(RuntimeComponent component) { + super(Scope.STATELESS, component); + } + + public InstanceWrapper getWrapper(KEY contextId) + throws TargetResolutionException { + InstanceWrapper ctx = createInstanceWrapper(); + ctx.start(); + return ctx; + } + + public InstanceWrapper getAssociatedWrapper(KEY contextId) + throws TargetResolutionException { + throw new UnsupportedOperationException(); + } + + public void returnWrapper(InstanceWrapper wrapper, KEY contextId) + throws TargetDestructionException { + wrapper.stop(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java new file mode 100644 index 0000000000..e0eff710e9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java @@ -0,0 +1,40 @@ +/* + * 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.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; + +/** + * @version $Rev$ $Date$ + */ +public class StatelessScopeContainerFactory implements ScopeContainerFactory { + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new StatelessScopeContainer(component); + } + + public Scope getScope() { + return Scope.STATELESS; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java new file mode 100644 index 0000000000..5b838116c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java @@ -0,0 +1,195 @@ +/* + * 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.tuscany.sca.core.store; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import org.apache.tuscany.sca.core.event.BaseEventPublisher; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.store.DuplicateRecordException; +import org.apache.tuscany.sca.store.RecoveryListener; +import org.apache.tuscany.sca.store.Store; +import org.apache.tuscany.sca.store.StoreExpirationEvent; +import org.apache.tuscany.sca.store.StoreMonitor; +import org.apache.tuscany.sca.store.StoreWriteException; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Service; + +/** + * Implements a non-durable, non-transactional store using a simple in-memory map + * + * @version $Rev$ $Date$ + */ +@Service(Store.class) +@EagerInit +public class MemoryStore extends BaseEventPublisher implements Store { + private Map> store; + // TODO integrate with a core threading scheme + private ScheduledExecutorService scheduler; + private long reaperInterval = 300000; + private StoreMonitor monitor; + private long defaultExpirationOffset = 600000; // 10 minutes + + public MemoryStore(StoreMonitor monitor) { + this.monitor = monitor; + this.store = new ConcurrentHashMap>(); + this.scheduler = Executors.newSingleThreadScheduledExecutor(); + } + + /** + * Returns the maximum default expiration offset for records in the store + * + * @return the maximum default expiration offset for records in the store + */ + public long getDefaultExpirationOffset() { + return defaultExpirationOffset; + } + + /** + * Sets the maximum default expiration offset for records in the store + */ + @Property + public void setDefaultExpirationOffset(long defaultExpirationOffset) { + this.defaultExpirationOffset = defaultExpirationOffset; + } + + /** + * Sets the interval for expired entry scanning to be performed + */ + @Property + public void setReaperInterval(long reaperInterval) { + this.reaperInterval = reaperInterval; + } + + public long getReaperInterval() { + return reaperInterval; + } + + @Init + public void init() { + scheduler.scheduleWithFixedDelay(new Reaper(), reaperInterval, reaperInterval, TimeUnit.MILLISECONDS); + monitor.start("In-memory store started"); + } + + @Destroy + public void destroy() { + scheduler.shutdown(); + monitor.stop("In-memory store stopped"); + } + + public void insertRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException { + Map map = store.get(owner); + if (map == null) { + map = new ConcurrentHashMap(); + store.put(owner, map); + } + if (map.containsKey(id)) { + throw new DuplicateRecordException("Duplicate record: " + owner.getURI() +" : " + id); + } + map.put(id, new Record(object, expiration)); + } + + public void updateRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException { + Map map = store.get(owner); + if (map == null) { + throw new StoreWriteException("Record not found: " + owner.getURI() +" : " + id); + } + Record record = map.get(id); + if (record == null) { + throw new StoreWriteException("Record not found: " + owner.getURI() +" : " + id); + } + record.data = object; + } + + public Object readRecord(RuntimeComponent owner, String id) { + Map map = store.get(owner); + if (map == null) { + return null; + } + Record record = map.get(id); + if (record != null) { + return record.data; + } + return null; + } + + public void removeRecords() { + store.clear(); + } + + public void removeRecord(RuntimeComponent owner, String id) throws StoreWriteException { + Map map = store.get(owner); + if (map == null) { + throw new StoreWriteException("Owner not found: " + owner.getURI() +" : " + id); + } + if (map.remove(id) == null) { + throw new StoreWriteException("Owner not found: " + owner.getURI() +" : " + id); + } + } + + public void recover(RecoveryListener listener) { + throw new UnsupportedOperationException(); + } + + private class Record { + private Object data; + private long expiration = NEVER; + + public Record(Object data, long expiration) { + this.data = data; + this.expiration = expiration; + } + + public Object getData() { + return data; + } + + public long getExpiration() { + return expiration; + } + } + + private class Reaper implements Runnable { + + public void run() { + long now = System.currentTimeMillis(); + for (Map.Entry> entries : store.entrySet()) { + for (Map.Entry entry : entries.getValue().entrySet()) { + final long expiration = entry.getValue().expiration; + if (expiration != NEVER && now >= expiration) { + RuntimeComponent owner = entries.getKey(); + Object instance = entry.getValue().getData(); + // notify listeners of the expiration + StoreExpirationEvent event = new StoreExpirationEvent(this, owner, instance); + publish(event); + entries.getValue().remove(entry.getKey()); + } + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/util/IOHelper.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/util/IOHelper.java new file mode 100644 index 0000000000..2058397fb0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/util/IOHelper.java @@ -0,0 +1,182 @@ +/* + * 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.tuscany.sca.core.util; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.JarURLConnection; +import java.net.URL; +import java.util.jar.JarFile; + +public class IOHelper { + /** + * The default buffer size to use. + */ + private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + + protected IOHelper() { + + } + + /** + * Unconditionally close an InputStream. + *

+ * Equivalent to {@link InputStream#close()}, except any exceptions will be ignored. + * This is typically used in finally blocks. + * + * @param input the InputStream to close, may be null or already closed + */ + public static void closeQuietly(InputStream input) { + try { + if (input != null) { + input.close(); + } + } catch (IOException ioe) { + // ignore + } + } + + /** + * Unconditionally close an OutputStream. + *

+ * Equivalent to {@link OutputStream#close()}, except any exceptions will be ignored. + * This is typically used in finally blocks. + * + * @param output the OutputStream to close, may be null or already closed + */ + public static void closeQuietly(OutputStream output) { + try { + if (output != null) { + output.close(); + } + } catch (IOException ioe) { + // ignore + } + } + + /** + * Copy bytes from an InputStream to an + * OutputStream. + *

+ * This method buffers the input internally, so there is no need to use a + * BufferedInputStream. + * + * @param input the InputStream to read from + * @param output the OutputStream to write to + * @return the number of bytes copied + * @throws NullPointerException if the input or output is null + * @throws IOException if an I/O error occurs + * @since Commons IO 1.1 + */ + public static int copy(InputStream input, OutputStream output) throws IOException { + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + int count = 0; + int n = 0; + while (-1 != (n = input.read(buffer))) { // NOPMD + output.write(buffer, 0, n); + count += n; + } + return count; + } + + public static InputStream getInputStream(URL url) throws IOException { + return new SafeURLInputStream(url); + } + + /** + * This class is a workaround for URL stream issue as illustrated below. + * InputStream is=url.getInputStream(); is.close(); // This line doesn't close + * the JAR file if the URL is a jar entry like "jar:file:/a.jar!/my.composite" We + * also need to turn off the JarFile cache. + * + * @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4950148 + * + * @version $Rev$ $Date$ + */ + public static class SafeURLInputStream extends InputStream { + private JarFile jarFile; + private InputStream is; + + public SafeURLInputStream(URL url) throws IOException { + String protocol = url.getProtocol(); + if (protocol != null && (protocol.equals("jar"))) { + JarURLConnection connection = (JarURLConnection)url.openConnection(); + // We cannot use cache + connection.setUseCaches(false); + try { + is = connection.getInputStream(); + } catch (IOException e) { + throw e; + } + jarFile = connection.getJarFile(); + } else { + is = url.openStream(); + } + } + + public SafeURLInputStream(JarURLConnection connection) throws IOException { + // We cannot use cache + connection.setUseCaches(false); + is = connection.getInputStream(); + jarFile = connection.getJarFile(); + } + + public int available() throws IOException { + return is.available(); + } + + public void close() throws IOException { + is.close(); + // We need to close the JAR file + if (jarFile != null) { + jarFile.close(); + } + } + + public synchronized void mark(int readlimit) { + is.mark(readlimit); + } + + public boolean markSupported() { + return is.markSupported(); + } + + public int read() throws IOException { + return is.read(); + } + + public int read(byte[] b, int off, int len) throws IOException { + return is.read(b, off, len); + } + + public int read(byte[] b) throws IOException { + return is.read(b); + } + + public synchronized void reset() throws IOException { + is.reset(); + } + + public long skip(long n) throws IOException { + return is.skip(n); + } + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java new file mode 100644 index 0000000000..6fe883157f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java @@ -0,0 +1,63 @@ +/* + * 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.tuscany.sca.core.work; + +/* + * JCA work wrapper. + */ +public class Jsr237Work implements commonj.work.Work { + + // Work that is being executed. + private T work; + + /* + * Initializes the work instance. + */ + public Jsr237Work(T work) { + this.work = work; + } + + /* + * Returns the completed work. + */ + public T getWork() { + return work; + } + + /* + * Release the work. + */ + public void release() { + } + + /* + * Work attributes are not daemon. + */ + public boolean isDaemon() { + return false; + } + + /* + * Runs the work. + */ + public void run() { + work.run(); + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java new file mode 100644 index 0000000000..c8a5dd7afe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java @@ -0,0 +1,167 @@ +/* + * 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.tuscany.sca.core.work; + +import org.apache.tuscany.sca.work.NotificationListener; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.apache.tuscany.sca.work.WorkSchedulerException; + +import commonj.work.WorkEvent; +import commonj.work.WorkException; +import commonj.work.WorkListener; +import commonj.work.WorkManager; +import commonj.work.WorkRejectedException; + +/** + * A work scheduler implementation based on a JSR 237 work manager. + *

+ *

+ * This needs a JSR 237 work manager implementation available for scheduling work. Instances can be configured with a + * work manager implementation that is injected in. It is the responsibility of the runtime environment to make a work + * manager implementaion available. For example, if the managed environment supports work manager the runtime can use + * the appropriate lookup mechanism to inject the work manager implementation.

+ */ +public class Jsr237WorkScheduler implements WorkScheduler { + + /** + * Underlying JSR-237 work manager + */ + private WorkManager jsr237WorkManager; + + /** + * Initializes the JSR 237 work manager. + * + * @param jsr237WorkManager JSR 237 work manager. + */ + public Jsr237WorkScheduler(WorkManager jsr237WorkManager) { + if (jsr237WorkManager == null) { + throw new IllegalArgumentException("Work manager cannot be null"); + } + this.jsr237WorkManager = jsr237WorkManager; + } + + /** + * Schedules a unit of work for future execution. The notification listener is used to register interest in + * callbacks regarding the status of the work. + * + * @param work The unit of work that needs to be asynchronously executed. + */ + public void scheduleWork(T work) { + scheduleWork(work, null); + } + + /** + * Schedules a unit of work for future execution. The notification listener is used to register interest in + * callbacks regarding the status of the work. + * + * @param work The unit of work that needs to be asynchronously executed. + * @param listener Notification listener for callbacks. + */ + public void scheduleWork(T work, NotificationListener listener) { + + if (work == null) { + throw new IllegalArgumentException("Work cannot be null"); + } + + Jsr237Work jsr237Work = new Jsr237Work(work); + try { + if (listener == null) { + jsr237WorkManager.schedule(jsr237Work); + } else { + Jsr237WorkListener jsr237WorkListener = new Jsr237WorkListener(listener, work); + jsr237WorkManager.schedule(jsr237Work, jsr237WorkListener); + } + } catch (WorkRejectedException ex) { + if (listener != null) { + listener.workRejected(work); + } else { + throw new WorkSchedulerException(ex); + } + } catch (WorkException ex) { + throw new WorkSchedulerException(ex); + } + + } + + /* + * Worklistener for keeping track of work status callbacks. + * + */ + private class Jsr237WorkListener implements WorkListener { + + // Notification listener + private NotificationListener listener; + + // Work + private T work; + + /* + * Initializes the notification listener. + */ + public Jsr237WorkListener(NotificationListener listener, T work) { + this.listener = listener; + this.work = work; + } + + /* + * Callback when the work is accepted. + */ + public void workAccepted(WorkEvent workEvent) { + T work = getWork(); + listener.workAccepted(work); + } + + /* + * Callback when the work is rejected. + */ + public void workRejected(WorkEvent workEvent) { + T work = getWork(); + listener.workRejected(work); + } + + /* + * Callback when the work is started. + */ + public void workStarted(WorkEvent workEvent) { + T work = getWork(); + listener.workStarted(work); + } + + /* + * Callback when the work is completed. + */ + public void workCompleted(WorkEvent workEvent) { + T work = getWork(); + Exception exception = workEvent.getException(); + if (exception != null) { + listener.workFailed(work, exception); + } else { + listener.workCompleted(work); + } + } + + /* + * Gets the underlying work from the work event. + */ + private T getWork() { + return work; + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java new file mode 100644 index 0000000000..0bc6f1b336 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java @@ -0,0 +1,220 @@ +/* + * 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.tuscany.sca.core.work; + +import java.rmi.server.UID; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionException; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Property; + +import commonj.work.Work; +import commonj.work.WorkEvent; +import commonj.work.WorkException; +import commonj.work.WorkItem; +import commonj.work.WorkListener; +import commonj.work.WorkManager; +import commonj.work.WorkRejectedException; + +/** + * A thread-pool based implementation for the JSR-237 work manager. + *

+ *

+ * This implementation supports only local work. + *

+ * TODO Elaborate the implementation.

+ */ +public class ThreadPoolWorkManager implements WorkManager { + + // Map of work items currently handled by the work manager + private Map workItems = new ConcurrentHashMap(); + + // Thread-pool + private ExecutorService executor; + + /** + * Initializes the thread-pool. + * + * @param threadPoolSize Thread-pool size. + */ + public ThreadPoolWorkManager(@Property(name = "poolSize") int threadPoolSize) { + executor = Executors.newFixedThreadPool(threadPoolSize); + } + + /** + * Schedules a unit of work asynchronously. + * + * @param work Work that needs to be scheduled. + * @return Work Work item representing the asynchronous work + */ + public WorkItem schedule(Work work) throws WorkException { + return schedule(work, null); + } + + /** + * Schedules a unit of work asynchronously. + * + * @param work Work that needs to be scheduled. + * @param workListener Work listener for callbacks. + * @return Work Work item representing the asynchronous work + */ + public WorkItem schedule(Work work, WorkListener workListener) throws WorkRejectedException { + + WorkItemImpl workItem = new WorkItemImpl(new UID().toString(), work); + if (workListener != null) { + workItems.put(workItem, workListener); + } + workAccepted(workItem, work); + if (scheduleWork(work, workItem)) { + return workItem; + } else { + workItem.setStatus(WorkEvent.WORK_REJECTED); + if (workListener != null) { + workListener.workRejected(new WorkEventImpl(workItem)); + } + throw new WorkRejectedException("Unable to schedule work"); + } + } + + /** + * Wait for all the specified units of work to finish. + * + * @param works Units of the work that need to finish. + * @param timeout Timeout for waiting for the units of work to finish. + */ + public boolean waitForAll(Collection works, long timeout) { + throw new UnsupportedOperationException("waitForAll not supported"); + } + + /** + * Wait for any of the specified units of work to finish. + * + * @param works Units of the work that need to finish. + * @param timeout Timeout for waiting for the units of work to finish. + */ + public Collection waitForAny(Collection works, long timeout) { + throw new UnsupportedOperationException("waitForAny not supported"); + } + + /** + * Method provided for subclasses to indicate a work accptance. + * + * @param workItem Work item representing the work that was accepted. + * @param work Work that was accepted. + */ + private void workAccepted(final WorkItemImpl workItem, final Work work) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_ACCEPTED); + WorkEvent event = new WorkEventImpl(workItem); + listener.workAccepted(event); + } + } + + /* + * Method to indicate a work start. + */ + private void workStarted(final WorkItemImpl workItem, final Work work) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_STARTED); + WorkEvent event = new WorkEventImpl(workItem); + listener.workStarted(event); + } + } + + /* + * Method to indicate a work completion. + */ + private void workCompleted(final WorkItemImpl workItem, final Work work) { + workCompleted(workItem, work, null); + } + + /* + * Method to indicate a work completion. + */ + private void workCompleted(final WorkItemImpl workItem, final Work work, final WorkException exception) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_COMPLETED); + workItem.setResult(work); + workItem.setException(exception); + WorkEvent event = new WorkEventImpl(workItem); + listener.workCompleted(event); + workItems.remove(workItem); + } + } + + /* + * Schedules the work using the threadpool. + */ + private boolean scheduleWork(final Work work, final WorkItemImpl workItem) { + try { + executor.execute(new DecoratingWork(workItem, work)); + return true; + } catch (RejectedExecutionException ex) { + return false; + } + } + + /* + * Class that decorates the original worker so that it can get callbacks when work is done. + */ + private final class DecoratingWork implements Runnable { + + // Work item for this work. + private WorkItemImpl workItem; + + // The original work. + private Work decoratedWork; + + /* + * Initializes the work item and underlying work. + */ + private DecoratingWork(final WorkItemImpl workItem, final Work decoratedWork) { + this.workItem = workItem; + this.decoratedWork = decoratedWork; + } + + /* + * Overrides the run method. + */ + public void run() { + workStarted(workItem, decoratedWork); + try { + decoratedWork.run(); + workCompleted(workItem, decoratedWork); + } catch (Throwable th) { + workCompleted(workItem, decoratedWork, new WorkException(th.getMessage(), th)); + } + } + + } + + @Destroy + public void destroy() { + executor.shutdown(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java new file mode 100644 index 0000000000..62ebeea1fb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java @@ -0,0 +1,74 @@ +/* + * 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.tuscany.sca.core.work; + + +import commonj.work.WorkEvent; +import commonj.work.WorkException; +import commonj.work.WorkItem; + +/** + * Default immutable implementation of the WorkEvent class. + */ +class WorkEventImpl implements WorkEvent { + + // Work item for this event + private WorkItem workItem; + + // Exception if something has gone wrong + private WorkException exception; + + /** + * Instantiates the event. + * + * @param workItem Work item for this event. + */ + public WorkEventImpl(final WorkItemImpl workItem) { + this.workItem = workItem; + this.exception = workItem.getException(); + } + + /** + * Returns the work type based on whether the work was accepted, started, + * rejected or completed. + * + * @return Work type. + */ + public int getType() { + return workItem.getStatus(); + } + + /** + * Returns the work item associated with this work type. + * + * @return Work item. + */ + public WorkItem getWorkItem() { + return workItem; + } + + /** + * Returns the exception if the work completed with an exception. + * + * @return Work exception. + */ + public WorkException getException() { + return exception; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java new file mode 100644 index 0000000000..fae3f1aae3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java @@ -0,0 +1,166 @@ +/* + * 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.tuscany.sca.core.work; + +import commonj.work.Work; +import commonj.work.WorkException; +import commonj.work.WorkItem; + +/** + * An identity based immutable implementation of the WorkItem + * interface. + * + */ +class WorkItemImpl implements WorkItem { + + // Id scoped for the VM + private String id; + + // Status + private int status = -1; + + // Result + private Work result; + + // Original work + private Work originalWork; + + // Exception + private WorkException exception; + + /** + * Instantiates an id for this item. + * + * @param id of this work event. + */ + protected WorkItemImpl(final String id, final Work orginalWork) { + this.id = id; + this.originalWork = orginalWork; + } + + /** + * Returns the id. + * + * @return Id of this item. + */ + public String getId() { + return id; + } + + /** + * Returns the original work. + * + * @return Original work. + */ + public Work getOriginalWork() { + return originalWork; + } + + /** + * Returns the work result if the work completed. + * + * @return Work. + * @throws WorkException If the work completed with an exception. + */ + public Work getResult() throws WorkException { + return result; + } + + /** + * Sets the result. + * + * @param result Result. + */ + protected void setResult(final Work result) { + this.result = result; + } + + /** + * Returns the exception if work completed with an exception. + * + * @return Work exception. + */ + protected WorkException getException() { + return exception; + } + + /** + * Sets the exception. + * + * @param exception Exception. + */ + protected void setException(final WorkException exception) { + this.exception = exception; + } + + /** + * Returns the work type based on whether the work was accepted, started, + * rejected or completed. + * + * @return Work status. + */ + public int getStatus() { + return status; + } + + /** + * Sets the status. + * + * @param status Status. + */ + protected void setStatus(final int status) { + this.status = status; + } + + /** + * @see Object#hashCode() + */ + public int hashCode() { + return id.hashCode(); + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param obj Object to be compared. + * @return true if this object is the same as the obj argument; false + * otherwise.. + */ + public boolean equals(final Object obj) { + return (obj != null) && (obj.getClass() == WorkItemImpl.class) && ((WorkItemImpl) obj).id.equals(id); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * + * @param o Object to be compared. + * @return A negative integer, zero, or a positive integer as this object + * is less than, equal to, or greater than the specified object. + * @throws ClassCastException needs better documentation. + */ + public int compareTo(final Object o) { + if (o.getClass() != WorkItemImpl.class) { + throw new ClassCastException(o.getClass().getName()); + } else { + return ((WorkItemImpl) o).getId().compareTo(getId()); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectCreationException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectCreationException.java new file mode 100644 index 0000000000..3432c61c76 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectCreationException.java @@ -0,0 +1,47 @@ +/* + * 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.tuscany.sca.factory; + + +/** + * Denotes an error creating a new object instance + * + * @version $Rev$ $Date$ + */ +public class ObjectCreationException extends RuntimeException { + private static final long serialVersionUID = -6423113430265944499L; + + public ObjectCreationException() { + super(); + } + + public ObjectCreationException(String message, Throwable cause) { + super(message, cause); + } + + public ObjectCreationException(String message) { + super(message); + } + + public ObjectCreationException(Throwable cause) { + super(cause); + } + +} + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectFactory.java new file mode 100644 index 0000000000..c5e0dad4e7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectFactory.java @@ -0,0 +1,35 @@ +/* + * 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.tuscany.sca.factory; + +/** + * Implementations create new instances of a particular type + * + * @version $Rev$ $Date$ + */ +public interface ObjectFactory { + + /** + * Return a instance of the type that this factory creates. + * + * @return a instance from this factory + */ + T getInstance() throws ObjectCreationException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/SingletonObjectFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/SingletonObjectFactory.java new file mode 100644 index 0000000000..074a1121c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/factory/SingletonObjectFactory.java @@ -0,0 +1,38 @@ +/* + * 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.tuscany.sca.factory; + + +/** + * Implementation of ObjectFactory that returns a single instance, typically an immutable type. + * + * @version $Rev$ $Date$ + */ +public class SingletonObjectFactory implements ObjectFactory { + private final T instance; + + public SingletonObjectFactory(T instance) { + this.instance = instance; + } + + public T getInstance() { + return instance; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/AbstractLifecycle.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/AbstractLifecycle.java new file mode 100644 index 0000000000..e5f88d91c6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/AbstractLifecycle.java @@ -0,0 +1,77 @@ +/* + * 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.tuscany.sca.scope; + +/** + * Base class providing a simple implementation of Lifecycle. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractLifecycle implements Lifecycle { + protected volatile int lifecycleState = UNINITIALIZED; + + public int getLifecycleState() { + return lifecycleState; + } + + /** + * Set the current state of the Lifecycle. + * + * @param lifecycleState the new state + */ + protected void setLifecycleState(int lifecycleState) { + this.lifecycleState = lifecycleState; + } + + public void start() { + setLifecycleState(RUNNING); + } + + public void stop() { + setLifecycleState(STOPPED); + } + + /** + * Returns the current lifecycle as a String (for example, "RUNNING"). + * + * @return the current lifecycle as a String + */ + public String toString() { + switch (lifecycleState) { + case Lifecycle.CONFIG_ERROR: + return "CONFIG_ERROR"; + case Lifecycle.ERROR: + return "ERROR"; + case Lifecycle.INITIALIZING: + return "INITIALIZING"; + case Lifecycle.INITIALIZED: + return "INITIALIZED"; + case Lifecycle.RUNNING: + return "RUNNING"; + case Lifecycle.STOPPING: + return "STOPPING"; + case Lifecycle.STOPPED: + return "STOPPED"; + case Lifecycle.UNINITIALIZED: + return "UNINITIALIZED"; + default: + return "UNKNOWN"; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/CoreRuntimeException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/CoreRuntimeException.java new file mode 100644 index 0000000000..ac3e51a982 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/CoreRuntimeException.java @@ -0,0 +1,45 @@ +/* + * 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.tuscany.sca.scope; + + +/** + * The root exception for the runtime package. Exceptions occurring in the runtime are generally non-recoverable + * + * @version $Rev$ $Date$ + */ +public abstract class CoreRuntimeException extends RuntimeException { + + public CoreRuntimeException() { + super(); + } + + public CoreRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + public CoreRuntimeException(String message) { + super(message); + } + + public CoreRuntimeException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/InstanceWrapper.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/InstanceWrapper.java new file mode 100644 index 0000000000..a952e2e72b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/InstanceWrapper.java @@ -0,0 +1,45 @@ +/* + * 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.tuscany.sca.scope; + + +/** + * Provides lifecycle management for an implementation instance associated with + * a component for use by the component's associated {@link org.apache.tuscany.sca.scope.ScopeContainer} + * + * @version $Rev$ $Date$ + */ +public interface InstanceWrapper { + + /** + * @return + */ + T getInstance(); + + /** + * @throws TargetInitializationException + */ + void start() throws TargetInitializationException; + + /** + * @throws TargetDestructionException + */ + void stop() throws TargetDestructionException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/Lifecycle.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/Lifecycle.java new file mode 100644 index 0000000000..02075cad01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/Lifecycle.java @@ -0,0 +1,69 @@ +/* + * 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.tuscany.sca.scope; + +/** + * Implementations adhere to runtime lifecycle semantics + * + * @version $Rev$ $Date$ + */ +public interface Lifecycle { + /* A configuration error state */ + int CONFIG_ERROR = -1; + /* Has not been initialized */ + int UNINITIALIZED = 0; + /* In the process of being configured and initialized */ + int INITIALIZING = 1; + /* Instantiated and configured */ + int INITIALIZED = 2; + /* Configured and initialized */ + int RUNNING = 4; + /* In the process of being shutdown */ + int STOPPING = 5; + /* Has been shutdown and removed from the composite */ + int STOPPED = 6; + /* In an error state */ + int ERROR = 7; + + /** + * Returns the lifecycle state + * + * @see #UNINITIALIZED + * @see #INITIALIZING + * @see #INITIALIZED + * @see #RUNNING + * @see #STOPPING + * @see #STOPPED + */ + int getLifecycleState(); + + /** + * Starts the Lifecycle. + * + * @throws CoreRuntimeException + */ + void start() throws CoreRuntimeException; + + /** + * Stops the Lifecycle. + * + * @throws CoreRuntimeException + */ + void stop() throws CoreRuntimeException; +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/PersistenceException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/PersistenceException.java new file mode 100644 index 0000000000..54fba1ee03 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/PersistenceException.java @@ -0,0 +1,43 @@ +/* + * 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.tuscany.sca.scope; + +/** + * Raised when an error persisting a component implementation instance is encountered + * + * @version $Rev$ $Date$ + */ +public class PersistenceException extends Exception { + private static final long serialVersionUID = -908468170919651248L; + + public PersistenceException() { + } + + public PersistenceException(String message) { + super(message); + } + + public PersistenceException(String message, Throwable cause) { + super(message, cause); + } + + public PersistenceException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/Scope.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/Scope.java new file mode 100644 index 0000000000..9b3f208cb3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/Scope.java @@ -0,0 +1,63 @@ +/* + * 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.tuscany.sca.scope; + +/** + * The default implementation scopes supported by assemblies. + * + * @version $Rev$ $Date$ + */ +public class Scope { + public static final Scope STATELESS = new Scope("STATELESS"); + public static final Scope REQUEST = new Scope("REQUEST"); + public static final Scope SESSION = new Scope("SESSION"); + public static final Scope CONVERSATION = new Scope("CONVERSATION"); + public static final Scope COMPOSITE = new Scope("COMPOSITE"); + public static final Scope SYSTEM = new Scope("SYSTEM"); + public static final Scope UNDEFINED = new Scope("UNDEFINED"); + + private String scope; + + public Scope(String scope) { + this.scope = scope.toUpperCase().intern(); + } + + public String getScope() { + return scope; + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final Scope scope1 = (Scope) o; + return !(scope != null ? scope != scope1.scope.intern() : scope1.scope != null); + } + + public int hashCode() { + return scope != null ? scope.hashCode() : 0; + } + + public String toString() { + return scope; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainer.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainer.java new file mode 100644 index 0000000000..30482fae90 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainer.java @@ -0,0 +1,93 @@ +/* + * 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.tuscany.sca.scope; + +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + + +/** + * Manages the lifecycle and visibility of instances associated with a an {@link RuntimeComponent}. + * + * @version $Rev$ $Date$ + * @param the type of IDs that this container uses to identify its contexts. + * For example, for COMPOSITE scope this could be the URI of the composite component, + * or for HTTP Session scope it might be the HTTP session ID. + */ +public interface ScopeContainer extends Lifecycle, RuntimeEventListener { + + /** + * Returns the Scope that this container supports. + * + * @return the Scope that this container supports + */ + Scope getScope(); + + /** + * Start a new context with the supplied ID. + * + * @param contextId an ID that uniquely identifies the context. + */ + void startContext(KEY contextId); + + /** + * Stop the context with the supplied ID. + * + * @param contextId an ID that uniquely identifies the context. + */ + void stopContext(KEY contextId); + + /** + * Returns an instance wrapper associated with the current scope context, creating one if necessary + * @param contextId the id for the scope context + * + * @return the wrapper for the target instance + * @throws TargetResolutionException if there was a problem instantiating the target instance + */ + InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException; + + /** + * Returns an implementation instance associated with the current scope context. + * If no instance is found, a {@link TargetNotFoundException} is thrown. + * @param contextId the id for the scope context + * + * @return the wrapper for the target instance + * @throws TargetResolutionException if there was a problem instantiating the target instance + */ + InstanceWrapper getAssociatedWrapper(KEY contextId) + throws TargetResolutionException; + + /** + * Return a wrapper after use (for example, after invoking the instance). + * @param wrapper the wrapper for the target instance being returned + * @param contextId the id for the scope context + * + * @throws TargetDestructionException if there was a problem returning the target instance + */ + void returnWrapper(InstanceWrapper wrapper, KEY contextId) + throws TargetDestructionException; + + /** + * Removes a component implementation instance associated with the current context from persistent storage + * + * @param component the owning component + * @throws PersistenceException if there was a problem removing the instance + */ + void remove() throws PersistenceException; +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainerFactory.java new file mode 100644 index 0000000000..b6acae7382 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainerFactory.java @@ -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.tuscany.sca.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Factory to create ScopeContainer for components + * + * @version $Rev$ $Date$ + */ +public interface ScopeContainerFactory { + ScopeContainer createScopeContainer(RuntimeComponent component); + Scope getScope(); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeIdentifier.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeIdentifier.java new file mode 100644 index 0000000000..77e7d76842 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeIdentifier.java @@ -0,0 +1,35 @@ +/* + * 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.tuscany.sca.scope; + +/** + * Implementations enable lazy retrieval of a scope id associated with a request, i.e. an id (and presumably a context) + * do not have to be generated if the scope is never accessed. Identifiers are associated with the current request + * thread and keyed on scope type. + * + * @version $Rev$ $Date$ + * @see org.apache.tuscany.sca.factory.component.WorkContext + */ +public interface ScopeIdentifier { + + /** + * Returns the scope id for the request. + */ + Object getIdentifier(); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeNotFoundException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeNotFoundException.java new file mode 100644 index 0000000000..40a251c6f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeNotFoundException.java @@ -0,0 +1,31 @@ +/* + * 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.tuscany.sca.scope; + +/** + * @version $Rev$ $Date$ + */ +public class ScopeNotFoundException extends Exception { + + private static final long serialVersionUID = -3447306764458851441L; + + public ScopeNotFoundException(String scope) { + super("Scope not found: " + scope); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeRegistry.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeRegistry.java new file mode 100644 index 0000000000..f3319ee093 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeRegistry.java @@ -0,0 +1,43 @@ +/* + * 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.tuscany.sca.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + + +/** + * Manages {@link ScopeContainer}s in the runtime + * + * @version $$Rev$$ $$Date$$ + */ +public interface ScopeRegistry { + + /** + * Returns the scope container for the given scope or null if one not found + * + * @param scope the scope + * @return the scope container for the given scope or null if one not found + */ + ScopeContainer getScopeContainer(RuntimeComponent component); + + /** + * @param factory + */ + void register(ScopeContainerFactory factory); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedImplementationProvider.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedImplementationProvider.java new file mode 100644 index 0000000000..8b9c50b070 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedImplementationProvider.java @@ -0,0 +1,64 @@ +/* + * 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.tuscany.sca.scope; + +import org.apache.tuscany.sca.provider.ImplementationProvider; + +/** + * A component implementation can implement this interface to provide scope + * management for the components + * + * @version $Rev$ $Date$ + */ +public interface ScopedImplementationProvider extends ImplementationProvider { + /** + * Get the scope for the component implementation + * + * @return The scope for the component implementation, if null is returned, + * STATELESS will be used + */ + Scope getScope(); + + /** + * Indicate if the component needs to be eagerly initialized + * + * @return true if the component is marked to be eagerly initialized, false + * otherwise + */ + boolean isEagerInit(); + + /** + * @return the maxAge + */ + long getMaxAge(); + + /** + * @return the maxIdleTime + */ + long getMaxIdleTime(); + + /** + * Create a wrapper for the component instance for the scope management + * + * @return A wrapper for the component instance + */ + InstanceWrapper createInstanceWrapper(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedRuntimeComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedRuntimeComponent.java new file mode 100644 index 0000000000..6c33683bde --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedRuntimeComponent.java @@ -0,0 +1,40 @@ +/* + * 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.tuscany.sca.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Scoped runtime component + * + * @version $Rev$ $Date$ + */ +public interface ScopedRuntimeComponent extends RuntimeComponent { + /** + * Set the associated scope container + * @param scopeContainer + */ + void setScopeContainer(ScopeContainer scopeContainer); + /** + * Get the assoicated scope container + * @return + */ + ScopeContainer getScopeContainer(); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetDestructionException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetDestructionException.java new file mode 100644 index 0000000000..6b251295f5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetDestructionException.java @@ -0,0 +1,44 @@ +/* + * 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.tuscany.sca.scope; + +/** + * Denotes an error destroying a target + * + * @version $Rev$ $Date$ + */ +public class TargetDestructionException extends TargetResolutionException { + private static final long serialVersionUID = -6126684147851674709L; + + public TargetDestructionException() { + super(); + } + + public TargetDestructionException(String message, Throwable cause) { + super(message, cause); + } + + public TargetDestructionException(String message) { + super(message); + } + + public TargetDestructionException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInitializationException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInitializationException.java new file mode 100644 index 0000000000..17cd21967f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInitializationException.java @@ -0,0 +1,44 @@ +/* + * 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.tuscany.sca.scope; + +/** + * Denotes an error initializing a target + * + * @version $Rev$ $Date$ + */ +public class TargetInitializationException extends TargetResolutionException { + private static final long serialVersionUID = -6228778208649752698L; + + public TargetInitializationException() { + super(); + } + + public TargetInitializationException(String message, Throwable cause) { + super(message, cause); + } + + public TargetInitializationException(String message) { + super(message); + } + + public TargetInitializationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvocationException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvocationException.java new file mode 100644 index 0000000000..f9bfa0a788 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvocationException.java @@ -0,0 +1,45 @@ +/* + * 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.tuscany.sca.scope; + +/** + * Raised when an error is encountered during a target invocation + * + * @version $Rev$ $Date$ + */ +public class TargetInvocationException extends Exception { + + private static final long serialVersionUID = -6553427708442761743L; + + public TargetInvocationException() { + super(); + } + + public TargetInvocationException(String message, Throwable cause) { + super(message, cause); + } + + public TargetInvocationException(String message) { + super(message); + } + + public TargetInvocationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvokerCreationException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvokerCreationException.java new file mode 100644 index 0000000000..a20d030ee8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvokerCreationException.java @@ -0,0 +1,44 @@ +/* + * 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.tuscany.sca.scope; + +/** + * Denotes an error creating a target invoker + * + * @version $Rev$ $Date$ + * @Deprecated + */ +public abstract class TargetInvokerCreationException extends Exception { + + public TargetInvokerCreationException() { + super(); + } + + public TargetInvokerCreationException(String message, Throwable cause) { + super(message, cause); + } + + public TargetInvokerCreationException(String message) { + super(message); + } + + public TargetInvokerCreationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetNotFoundException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetNotFoundException.java new file mode 100644 index 0000000000..4dd63f58f0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetNotFoundException.java @@ -0,0 +1,44 @@ +/* + * 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.tuscany.sca.scope; + +/** + * Thrown when a target of an operation cannot be found + * + * @version $$Rev$$ $$Date$$ + */ +public class TargetNotFoundException extends TargetResolutionException { + private static final long serialVersionUID = 5541830480658471186L; + + public TargetNotFoundException() { + super(); + } + + public TargetNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public TargetNotFoundException(String message) { + super(message); + } + + public TargetNotFoundException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetResolutionException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetResolutionException.java new file mode 100644 index 0000000000..284ab8b6c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetResolutionException.java @@ -0,0 +1,44 @@ +/* + * 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.tuscany.sca.scope; + +/** + * Denotes an error retrieving a target instance + * + * @version $Rev$ $Date$ + */ +public class TargetResolutionException extends Exception { + private static final long serialVersionUID = 2912513650522019405L; + + public TargetResolutionException() { + super(); + } + + public TargetResolutionException(String message, Throwable cause) { + super(message, cause); + } + + public TargetResolutionException(String message) { + super(message); + } + + public TargetResolutionException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java new file mode 100644 index 0000000000..40a146e129 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java @@ -0,0 +1,51 @@ +/* + * 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.tuscany.sca.core; + +import junit.framework.TestCase; + +public class DefaultExtensionPointRegistryTestCase extends TestCase { + private ExtensionPointRegistry registry; + + protected void setUp() throws Exception { + super.setUp(); + registry = new DefaultExtensionPointRegistry(); + } + + public void testRegistry() { + MyRegistry service = new MyREgistryImpl(); + registry.addExtensionPoint(service); + assertSame(service, registry.getExtensionPoint(MyRegistry.class)); + registry.removeExtensionPoint(service); + assertNull(registry.getExtensionPoint(MyRegistry.class)); + } + + private static interface MyRegistry { + void doSomething(); + } + + private static class MyREgistryImpl implements MyRegistry { + + public void doSomething() { + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java new file mode 100644 index 0000000000..d2050523eb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java @@ -0,0 +1,98 @@ +/* + * 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.tuscany.sca.core.event; + + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.event.EventFilter; +import org.apache.tuscany.sca.event.EventPublisher; +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.event.TrueFilter; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class BaseEventPublisherTestCase extends TestCase { + EventPublisher publisher; + + public void testFireListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + publisher.addListener(listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + public void testRemoveListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + publisher.addListener(listener); + publisher.removeListener(listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + public void testFalseFilterListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + publisher.addListener(new FalseFilter(), listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + public void testTrueFilterListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + publisher.addListener(new TrueFilter(), listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + protected void setUp() throws Exception { + super.setUp(); + publisher = new BaseEventPublisher() { + }; + } + + private class TestEvent implements Event { + public Object getSource() { + return null; + } + } + + private class FalseFilter implements EventFilter { + + public boolean match(Event event) { + return false; + } + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java new file mode 100644 index 0000000000..bf95d640c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java @@ -0,0 +1,69 @@ +/* + * 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.tuscany.sca.core.event; + +import java.net.URI; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class EventTestCase extends TestCase { + private URI uri = URI.create("foo"); + + public void testCompositeStart() { + ComponentStart event = new ComponentStart(this, uri); + assertEquals(uri, event.getComponentURI()); + } + + public void testCompositeStop() { + ComponentStop event = new ComponentStop(this, uri); + assertEquals(uri, event.getComponentURI()); + } + + public void testHttpSessionStart() { + Object id = new Object(); + HttpSessionStart event = new HttpSessionStart(this, id); + assertEquals(this, event.getSource()); + assertEquals(id, event.getSessionID()); + } + + public void testHttpSessionEnd() { + Object id = new Object(); + HttpSessionEnd event = new HttpSessionEnd(this, id); + assertEquals(this, event.getSource()); + assertEquals(id, event.getSessionID()); + } + + public void testRequestStart() { + RequestStart event = new RequestStart(this); + assertEquals(this, event.getSource()); + } + + public void testReequestEnd() { + RequestEnd event = new RequestEnd(this); + assertEquals(this, event.getSource()); + } + + + protected void setUp() throws Exception { + super.setUp(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/AsyncTarget.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/AsyncTarget.java new file mode 100644 index 0000000000..c30e19de88 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/AsyncTarget.java @@ -0,0 +1,31 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.OneWay; + +/** + * @version $Rev$ $Date$ + */ +public interface AsyncTarget { + @OneWay + void invoke(); + + int getCount(); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadContextPojo.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadContextPojo.java new file mode 100644 index 0000000000..f9ae94f152 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadContextPojo.java @@ -0,0 +1,28 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Context; + +public class BadContextPojo { + + @Context + String context; + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadNamePojo.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadNamePojo.java new file mode 100644 index 0000000000..c4074484b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadNamePojo.java @@ -0,0 +1,26 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.ComponentName; + +public class BadNamePojo { + @ComponentName + private int name; +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterface.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterface.java new file mode 100644 index 0000000000..ca305b9ef0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterface.java @@ -0,0 +1,30 @@ +/* + * 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.tuscany.sca.core.mock.component; + +/** + * @version $Rev$ $Date$ + */ +public interface BasicInterface { + String returnsProperty(); + + BasicInterface returnsReference(); + + int returnsInt(); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterfaceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterfaceImpl.java new file mode 100644 index 0000000000..ea32d1f6b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterfaceImpl.java @@ -0,0 +1,66 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +/** + * @version $Rev$ $Date$ + */ +public class BasicInterfaceImpl implements BasicInterface { + + @Property + public String publicProperty; + + @Reference (required = false) + public BasicInterface publicReference; + + @Property + protected String protectedProperty; + + @Reference (required = false) + protected BasicInterface protectedReference; + + private String privateProperty; + + private BasicInterface privateReference; + + @Property + public void setPrivateProperty(String privateProperty) { + this.privateProperty = privateProperty; + } + + @Reference (required = false) + public void setPrivateReference(BasicInterface privateReference) { + this.privateReference = privateReference; + } + + public String returnsProperty() { + return privateProperty; + } + + public BasicInterface returnsReference() { + return privateReference; + } + + public int returnsInt() { + return 0; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponent.java new file mode 100644 index 0000000000..6d320df145 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponent.java @@ -0,0 +1,31 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("COMPOSITE") +public interface CompositeScopeComponent { + + //public boolean isInit(); +} + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponentImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponentImpl.java new file mode 100644 index 0000000000..9ff289a502 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponentImpl.java @@ -0,0 +1,40 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + + +/** + * @version $Rev$ $Date$ + */ +@Scope("COMPOSITE") +public class CompositeScopeComponentImpl implements + CompositeScopeComponent { + + private String foo; + + public void setFoo(String foo) { + this.foo = foo; + } + + public String getFoo() { + return foo; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeDestroyOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..832055a084 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeDestroyOnlyComponent.java @@ -0,0 +1,36 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; + +public class CompositeScopeDestroyOnlyComponent extends CompositeScopeComponentImpl { + + boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitDestroyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitDestroyComponent.java new file mode 100644 index 0000000000..e8b76e13c0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitDestroyComponent.java @@ -0,0 +1,39 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; + +public class CompositeScopeInitDestroyComponent extends CompositeScopeInitOnlyComponent { + + boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + if (destroyed) { + throw new AssertionError("Destroy called more than once"); + } + destroyed = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitOnlyComponent.java new file mode 100644 index 0000000000..057580be7a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitOnlyComponent.java @@ -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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Init; + +public class CompositeScopeInitOnlyComponent extends CompositeScopeComponentImpl { + + private boolean initialized; + // this value tests to ensure introspection can find the init() method even + // if a field is named the same. Ultimately, this should be in the introspection tests + private boolean init; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + if (initialized) { + throw new AssertionError("Init called more than once"); + } + initialized = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponent.java new file mode 100644 index 0000000000..79f48a57c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponent.java @@ -0,0 +1,29 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev: 430937 $ $Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $ + */ +@Scope("CONVERSATION") +public interface ConversationalScopeComponent { + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponentImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponentImpl.java new file mode 100644 index 0000000000..5b42d92191 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponentImpl.java @@ -0,0 +1,29 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev: 430937 $ $Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $ + */ +@Scope("CONVERSATION") +public class ConversationalScopeComponentImpl implements ConversationalScopeComponent { + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeDestroyOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..c64556e754 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeDestroyOnlyComponent.java @@ -0,0 +1,37 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("CONVERSATION") +public class ConversationalScopeDestroyOnlyComponent extends ConversationalScopeComponentImpl { + + boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitDestroyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitDestroyComponent.java new file mode 100644 index 0000000000..6f930ef750 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitDestroyComponent.java @@ -0,0 +1,38 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("CONVERSATION") +public class ConversationalScopeInitDestroyComponent + extends ConversationalScopeInitOnlyComponent { + + private boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitOnlyComponent.java new file mode 100644 index 0000000000..70733f4d99 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitOnlyComponent.java @@ -0,0 +1,38 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("CONVERSATION") +public class ConversationalScopeInitOnlyComponent + extends ConversationalScopeComponentImpl { + + private boolean initialized; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + initialized = true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderException.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderException.java new file mode 100644 index 0000000000..4bb9cde958 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderException.java @@ -0,0 +1,40 @@ +/* + * 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.tuscany.sca.core.mock.component; + +public class OrderException extends Exception { + + public OrderException() { + super(); + } + + public OrderException(String message) { + super(message); + } + + public OrderException(String message, Throwable cause) { + super(message, cause); + } + + public OrderException(Throwable cause) { + super(cause); + } + +} + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojo.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojo.java new file mode 100644 index 0000000000..df59029884 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojo.java @@ -0,0 +1,29 @@ +/* + * 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.tuscany.sca.core.mock.component; + +/** + * @version $$Rev$$ $$Date$$ + */ +public interface OrderedDependentPojo extends OrderedInitPojo { + + OrderedInitPojo getPojo(); + + void setPojo(OrderedInitPojo pojo); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojoImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojoImpl.java new file mode 100644 index 0000000000..1b51c2772d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojoImpl.java @@ -0,0 +1,36 @@ +/* + * 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.tuscany.sca.core.mock.component; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class OrderedDependentPojoImpl extends OrderedInitPojoImpl implements OrderedDependentPojo { + + private OrderedInitPojo pojo; + + public OrderedInitPojo getPojo() { + return pojo; + } + + public void setPojo(OrderedInitPojo pojo) { + this.pojo = pojo; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedEagerInitPojo.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedEagerInitPojo.java new file mode 100644 index 0000000000..139086bf0d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedEagerInitPojo.java @@ -0,0 +1,60 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +@EagerInit +public class OrderedEagerInitPojo { + + private static final Object LOCK = new Object(); + private static int numberInstantied; + private int initOrder; + + @Init + public void init() { + synchronized (LOCK) { + ++numberInstantied; + initOrder = numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (LOCK) { + if (initOrder != numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --numberInstantied; + } + } + + public int getNumberInstantiated() { + return numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojo.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojo.java new file mode 100644 index 0000000000..1c3615fcd0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojo.java @@ -0,0 +1,28 @@ +/* + * 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.tuscany.sca.core.mock.component; + +/** + * @version $$Rev$$ $$Date$$ + */ +public interface OrderedInitPojo { + int getNumberInstantiated(); + + int getInitOrder(); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojoImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojoImpl.java new file mode 100644 index 0000000000..b65ead9b19 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojoImpl.java @@ -0,0 +1,61 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class OrderedInitPojoImpl implements OrderedInitPojo { + + private static final Object LOCK = new Object(); + private static int numberInstantied; + private int initOrder; + + public OrderedInitPojoImpl() { + } + + @Init + public void init() { + synchronized (LOCK) { + ++numberInstantied; + initOrder = numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (LOCK) { + if (initOrder != numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --numberInstantied; + } + } + + public int getNumberInstantiated() { + return numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTarget.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTarget.java new file mode 100644 index 0000000000..963c31a4ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTarget.java @@ -0,0 +1,31 @@ +/* + * 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.tuscany.sca.core.mock.component; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface OtherTarget { + + String getString(); + + void setString(String val); +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTargetImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTargetImpl.java new file mode 100644 index 0000000000..91ccc9e772 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTargetImpl.java @@ -0,0 +1,39 @@ +/* + * 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.tuscany.sca.core.mock.component; + +/** + * A target used for testing wires with a different source and target interface + * + * @version $Rev$ $Date$ + */ +public class OtherTargetImpl implements OtherTarget { + + private String theString; + + public String getString() { + return theString; + } + + public void setString(String val) { + theString = val; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeComponent.java new file mode 100644 index 0000000000..7d03c4372d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeComponent.java @@ -0,0 +1,30 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("REQUEST") +public interface RequestScopeComponent { + +} + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeDestroyOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..f94f071086 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeDestroyOnlyComponent.java @@ -0,0 +1,38 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeDestroyOnlyComponent extends SessionScopeComponentImpl { + + boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitDestroyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitDestroyComponent.java new file mode 100644 index 0000000000..f2de2d9afa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitDestroyComponent.java @@ -0,0 +1,38 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeInitDestroyComponent extends SessionScopeInitOnlyComponent { + + boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitOnlyComponent.java new file mode 100644 index 0000000000..9bcef40834 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitOnlyComponent.java @@ -0,0 +1,39 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeInitOnlyComponent extends SessionScopeComponentImpl { + + private boolean initialized; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + initialized = true; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponent.java new file mode 100644 index 0000000000..8318333feb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponent.java @@ -0,0 +1,30 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("SESSION") +public interface SessionScopeComponent { + +} + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponentImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponentImpl.java new file mode 100644 index 0000000000..0494d587aa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponentImpl.java @@ -0,0 +1,30 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("SESSION") +public class SessionScopeComponentImpl implements + SessionScopeComponent { + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitDestroyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitDestroyComponent.java new file mode 100644 index 0000000000..fdc11a80af --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitDestroyComponent.java @@ -0,0 +1,36 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; + +public class SessionScopeInitDestroyComponent extends SessionScopeInitOnlyComponent { + + private boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitOnlyComponent.java new file mode 100644 index 0000000000..4e849895f8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitOnlyComponent.java @@ -0,0 +1,37 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Init; + +public class SessionScopeInitOnlyComponent extends SessionScopeComponentImpl { + + private boolean initialized; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + initialized = true; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTarget.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTarget.java new file mode 100644 index 0000000000..44eb94260e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTarget.java @@ -0,0 +1,30 @@ +/* + * 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.tuscany.sca.core.mock.component; + +public interface SimpleTarget { + + String hello(String message) throws Exception; + + String goodbye(String message) throws Exception; + + String echo(String message) throws Exception; + +} + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTargetImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTargetImpl.java new file mode 100644 index 0000000000..662b21116a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTargetImpl.java @@ -0,0 +1,41 @@ +/* + * 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.tuscany.sca.core.mock.component; + +public class SimpleTargetImpl implements SimpleTarget { + + public SimpleTargetImpl() { + super(); + } + + public String hello(String message) throws Exception { + return message; + } + + public String goodbye(String message) throws Exception { + return message; + } + + public String echo(String message) throws Exception { + return message; + } + + +} + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Source.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Source.java new file mode 100644 index 0000000000..aa3b5be528 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Source.java @@ -0,0 +1,37 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import java.util.List; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface Source { + + Target getTarget(); + + List getTargets(); + + List getTargetsThroughField(); + +} + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SourceImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SourceImpl.java new file mode 100644 index 0000000000..81e39a9fe9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SourceImpl.java @@ -0,0 +1,63 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import java.util.List; + +/** + * Mock system component implementation used in wiring tests + * + * @version $Rev$ $Date$ + */ +public class SourceImpl implements Source { + + private Target target; + private List targets; + private List targetsThroughField; + private Target[] targetsArray; + + public void setTarget(Target target) { + this.target = target; + } + + public Target getTarget() { + return target; + } + + public List getTargets() { + return targets; + } + + public void setTargets(List targets) { + this.targets = targets; + } + + public List getTargetsThroughField() { + return targetsThroughField; + } + + public Target[] getArrayOfTargets() { + return targetsArray; + } + + public void setArrayOfTargets(Target[] targets) { + targetsArray = targets; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponent.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponent.java new file mode 100644 index 0000000000..89d0be7a53 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponent.java @@ -0,0 +1,30 @@ +/* + * 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.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("STATELESS") +public interface StatelessComponent { + +} + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponentImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponentImpl.java new file mode 100644 index 0000000000..28eb28e76d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponentImpl.java @@ -0,0 +1,27 @@ +/* + * 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.tuscany.sca.core.mock.component; + +/** + * @version $Rev$ $Date$ + */ +public class StatelessComponentImpl implements + StatelessComponent { + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Target.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Target.java new file mode 100644 index 0000000000..5e85ed48b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Target.java @@ -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.tuscany.sca.core.mock.component; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface Target { + + String getString(); + + void setString(String val); +} + diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/TargetImpl.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/TargetImpl.java new file mode 100644 index 0000000000..169b38a8d0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/TargetImpl.java @@ -0,0 +1,38 @@ +/* + * 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.tuscany.sca.core.mock.component; + +/** + * Mock system component implementation used in wiring tests + * + * @version $Rev$ $Date$ + */ +public class TargetImpl implements Target { + + private String theString; + + public String getString() { + return theString; + } + + public void setString(String val) { + theString = val; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java new file mode 100644 index 0000000000..5be8fe21b3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java @@ -0,0 +1,70 @@ +/* + * 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.tuscany.sca.core.scope; + +import java.net.URI; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopedImplementationProvider; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; + +/** + * @version $Rev$ $Date$ + */ +public abstract class AbstractScopeContainerTestCase extends TestCase { + protected IMocksControl control; + protected ScopeContainer scopeContainer; + protected URI groupId; + protected KEY contextId; + protected RuntimeComponent component; + protected ScopedImplementation implementation; + protected InstanceWrapper wrapper; + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + control = EasyMock.createStrictControl(); + component = control.createMock(RuntimeComponent.class); + wrapper = control.createMock(InstanceWrapper.class); + implementation = control.createMock(ScopedImplementation.class); + EasyMock.expect(component.getImplementation()).andReturn(implementation).anyTimes(); + } + + protected void preRegisterComponent() throws Exception { + scopeContainer.start(); + EasyMock.expect(implementation.isEagerInit()).andStubReturn(false); + } + + protected void expectCreateWrapper() throws Exception { + EasyMock.expect(implementation.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + } + + protected static interface ScopedImplementation extends ScopedImplementationProvider, Implementation { + + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java new file mode 100644 index 0000000000..2f5c182f45 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java @@ -0,0 +1,165 @@ +/* + * 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.tuscany.sca.core.store; + +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.store.DuplicateRecordException; +import org.apache.tuscany.sca.store.Store; +import org.apache.tuscany.sca.store.StoreExpirationEvent; +import org.apache.tuscany.sca.store.StoreMonitor; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class MemoryStoreTestCase extends TestCase { + private StoreMonitor monitor; + + public void testEviction() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, 1); + Thread.sleep(200); + assertNull(store.readRecord(component, id)); + store.destroy(); + } + + public void testNotifyOnEviction() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.isA(StoreExpirationEvent.class)); + EasyMock.expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + latch.countDown(); + return null; + } + }); + EasyMock.replay(listener); + MemoryStore store = new MemoryStore(monitor); + store.addListener(listener); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, 1); + if (!latch.await(1000, TimeUnit.MILLISECONDS)) { + // failed to notify listener + fail(); + } + EasyMock.verify(listener); + } + + public void testNoEviction() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + Thread.sleep(100); + assertNotNull(store.readRecord(component, id)); + store.destroy(); + } + + public void testInsertRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + store.destroy(); + } + + public void testInsertAlreadyExists() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createMock(RuntimeComponent.class); + EasyMock.expect(component.getURI()).andReturn("component"); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + try { + store.insertRecord(component, id, value, Store.NEVER); + fail(); + } catch (DuplicateRecordException e) { + //expected + } + store.destroy(); + } + + public void testUpdateRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + Object newValue = new Object(); + + store.insertRecord(component, id, value, Store.NEVER); + store.updateRecord(component, id, newValue, 1L); + assertEquals(newValue, store.readRecord(component, id)); + store.destroy(); + } + + public void testDeleteRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + + store.insertRecord(component, id, value, Store.NEVER); + store.removeRecord(component, id); + assertNull(store.readRecord(component, id)); + store.destroy(); + } + + protected void setUp() throws Exception { + super.setUp(); + monitor = EasyMock.createNiceMock(StoreMonitor.class); + EasyMock.replay(monitor); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java new file mode 100644 index 0000000000..58503fd852 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java @@ -0,0 +1,55 @@ +/* + * 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.tuscany.sca.core.wire; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.CallbackInterfaceInterceptor; +import org.apache.tuscany.sca.core.invocation.MessageFactoryImpl; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Message; +import org.easymock.EasyMock; +import org.osoa.sca.NoRegisteredCallbackException; + +/** + * @version $Rev$ $Date$ + */ +public class CallbackInterfaceInterceptorTestCase extends TestCase { + + public void testImplements() { + CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(true); + Interceptor next = EasyMock.createMock(Interceptor.class); + EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(null); + EasyMock.replay(next); + interceptor.setNext(next); + interceptor.invoke(new MessageFactoryImpl().createMessage()); + EasyMock.verify(next); + } + + public void testDoesNotImplement() { + CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(false); + try { + interceptor.invoke(new MessageFactoryImpl().createMessage()); + fail(); + } catch (NoRegisteredCallbackException e) { + // expected + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java new file mode 100644 index 0000000000..83f7bdd887 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java @@ -0,0 +1,66 @@ +/* + * 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.tuscany.sca.core.wire; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.InvocationChainImpl; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * @version $Rev$ $Date$ + */ +public class InvocationChainImplTestCase extends TestCase { + + public void testInsertAtEnd() throws Exception { + InvocationChain chain = new InvocationChainImpl(new OperationImpl("foo")); + Interceptor inter2 = new MockInterceptor(); + Interceptor inter1 = new MockInterceptor(); + chain.addInterceptor(inter1); + chain.addInterceptor(inter2); + Interceptor head = (Interceptor)chain.getHeadInvoker(); + assertEquals(inter1, head); + assertEquals(inter2, head.getNext()); + assertEquals(inter2, chain.getTailInvoker()); + + } + + private class MockInterceptor implements Interceptor { + + private Invoker next; + + public Message invoke(Message msg) { + return null; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Invoker getNext() { + return next; + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java new file mode 100644 index 0000000000..c5f93edeb6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java @@ -0,0 +1,72 @@ +/* + * 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.tuscany.sca.core.wire; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.getCurrentArguments; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor; +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class NonBlockingInterceptorTestCase extends TestCase { + + public void testInvoke() throws Exception { + WorkScheduler scheduler = createMock(WorkScheduler.class); + scheduler.scheduleWork(isA(Runnable.class)); + expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + Runnable runnable = (Runnable) getCurrentArguments()[0]; + runnable.run(); + return null; + } + }); + replay(scheduler); + Message context = createMock(Message.class); + String convID = "convID"; + EasyMock.expect(context.getConversationID()).andReturn(convID); + EasyMock.replay(context); + ThreadMessageContext.setMessageContext(context); + Message msg = createMock(Message.class); + msg.setCorrelationID(null); + msg.setConversationID(convID); + Interceptor next = EasyMock.createMock(Interceptor.class); + EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg); + EasyMock.replay(next); + EasyMock.replay(msg); + Interceptor interceptor = new NonBlockingInterceptor(scheduler, next); + interceptor.invoke(msg); + verify(context); + verify(next); + verify(msg); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/factory/AssertionTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/factory/AssertionTestCase.java new file mode 100644 index 0000000000..77d0e01dc9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/factory/AssertionTestCase.java @@ -0,0 +1,38 @@ +/* + * 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.tuscany.sca.factory; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class AssertionTestCase extends TestCase { + /** + * test case that confirms that JRE assertions are enabled + */ + public void testAssertionsAreEnabled() { + try { + assert false; + fail("assertions are not enabled"); + } catch (AssertionError e) { + // ok + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/factory/SingletonObjectFactoryTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/factory/SingletonObjectFactoryTestCase.java new file mode 100644 index 0000000000..4d38c447ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/factory/SingletonObjectFactoryTestCase.java @@ -0,0 +1,33 @@ +/* + * 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.tuscany.sca.factory; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class SingletonObjectFactoryTestCase extends TestCase { + + public void testSingleton() throws Exception { + Object o = new Object(); + SingletonObjectFactory factory = new SingletonObjectFactory(o); + assertEquals(o, factory.getInstance()); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java new file mode 100644 index 0000000000..1b95c6ff63 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.90/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java @@ -0,0 +1,61 @@ +/* + * 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.tuscany.sca.scope; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.scope.Scope; + +/** + * @version $Rev$ $Date$ + */ +public class ScopeTestCase extends TestCase { + + public void testEquals() throws Exception { + Scope scope = new Scope("COMPOSITE"); + assertTrue(scope.equals(Scope.COMPOSITE)); + } + + public void testEqualsNew() throws Exception { + Scope foo = new Scope("foo"); + Scope foo2 = new Scope("FOO"); + assertTrue(foo.equals(foo2)); + } + + public void testNotEquals() throws Exception { + Scope foo = new Scope("BAR"); + Scope foo2 = new Scope("FOO"); + assertFalse(foo.equals(foo2)); + } + + public void testNotEqualsDifferent() throws Exception { + Scope foo = new Scope("FOO"); + assertFalse(foo.equals(new Bar("FOO"))); + } + + public class Bar { + String scope; + + public Bar(String scope) { + this.scope = scope; + } + } + + +} -- cgit v1.2.3