diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/OnwireClassRegistry.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/OnwireClassRegistry.java index e787b6040a8..d26777e9af1 100644 --- a/framework/ipc/src/org/apache/cloudstack/framework/messaging/OnwireClassRegistry.java +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/OnwireClassRegistry.java @@ -32,14 +32,10 @@ import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; -import org.springframework.stereotype.Component; - // // Finding classes in a given package code is taken and modified from // Credit: http://internna.blogspot.com/2007/11/java-5-retrieving-all-classes-from.html // - -@Component public class OnwireClassRegistry { private List packages = new ArrayList(); @@ -48,6 +44,22 @@ public class OnwireClassRegistry { public OnwireClassRegistry() { } + public OnwireClassRegistry(String packageName) { + addPackage(packageName); + } + + public OnwireClassRegistry(List packages) { + packages.addAll(packages); + } + + public List getPackages() { + return packages; + } + + public void setPackages(List packages) { + this.packages = packages; + } + public void addPackage(String packageName) { packages.add(packageName); } @@ -60,9 +72,11 @@ public class OnwireClassRegistry { for(Class clz : classes) { OnwireName onwire = clz.getAnnotation(OnwireName.class); - assert(onwire.name() != null); - - registry.put(onwire.name(), clz); + if(onwire != null) { + assert(onwire.name() != null); + + registry.put(onwire.name(), clz); + } } } diff --git a/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcProviderImpl.java b/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcProviderImpl.java index 409be59dac4..9be50e5f702 100644 --- a/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcProviderImpl.java +++ b/framework/ipc/src/org/apache/cloudstack/framework/messaging/RpcProviderImpl.java @@ -39,6 +39,10 @@ public class RpcProviderImpl implements RpcProvider { public RpcProviderImpl() { } + public RpcProviderImpl(TransportProvider transportProvider) { + _transportProvider = transportProvider; + } + public TransportProvider getTransportProvider() { return _transportProvider; } diff --git a/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagementServer.java b/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagementServer.java new file mode 100644 index 00000000000..d00fba25b9d --- /dev/null +++ b/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagementServer.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.framework.messaging.server; + +import org.springframework.stereotype.Component; + +@Component +public class SampleManagementServer { + + public void mainLoop() { + while(true) { + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException e) { + } + } + } +} diff --git a/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagementServerApp.java b/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagementServerApp.java new file mode 100644 index 00000000000..2748e7f4d8e --- /dev/null +++ b/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagementServerApp.java @@ -0,0 +1,56 @@ +/* + * 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.cloudstack.framework.messaging.server; + +import java.io.File; +import java.net.URISyntaxException; +import java.net.URL; + +import org.apache.log4j.xml.DOMConfigurator; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class SampleManagementServerApp { + + private static void setupLog4j() { + URL configUrl = System.class.getResource("/resources/log4j-cloud.xml"); + if(configUrl != null) { + System.out.println("Configure log4j using log4j-cloud.xml"); + + try { + File file = new File(configUrl.toURI()); + + System.out.println("Log4j configuration from : " + file.getAbsolutePath()); + DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); + } catch (URISyntaxException e) { + System.out.println("Unable to convert log4j configuration Url to URI"); + } + } else { + System.out.println("Configure log4j with default properties"); + } + } + + public static void main(String args[]) { + setupLog4j(); + + ApplicationContext context = new ClassPathXmlApplicationContext("/resources/SampleManagementServerAppContext.xml"); + SampleManagementServer server = context.getBean(SampleManagementServer.class); + server.mainLoop(); + } +} diff --git a/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagerComponent.java b/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagerComponent.java new file mode 100644 index 00000000000..728f4ae114d --- /dev/null +++ b/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagerComponent.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.cloudstack.framework.messaging.server; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.apache.cloudstack.framework.messaging.EventBus; +import org.apache.cloudstack.framework.messaging.EventDispatcher; +import org.apache.cloudstack.framework.messaging.EventHandler; +import org.apache.cloudstack.framework.messaging.RpcProvider; +import org.apache.cloudstack.framework.messaging.RpcServerCall; +import org.apache.cloudstack.framework.messaging.RpcServiceDispatcher; +import org.apache.cloudstack.framework.messaging.RpcServiceHandler; +import org.springframework.stereotype.Component; + +@Component +public class SampleManagerComponent { + + @Inject + private EventBus _eventBus; + + @Inject + private RpcProvider _rpcProvider; + + public SampleManagerComponent() { + } + + @PostConstruct + public void init() { + _rpcProvider.registerRpcServiceEndpoint( + RpcServiceDispatcher.getDispatcher(this)); + + // subscribe to all network events (for example) + _eventBus.subscribe("network", + EventDispatcher.getDispatcher(this)); + } + + @RpcServiceHandler(command="NetworkPrepare") + void onStartCommand(RpcServerCall call) { + call.completeCall("NetworkPrepare completed"); + } + + @EventHandler(topic="network.prepare") + void onPrepareNetwork(String sender, String topic, Object args) { + } +} diff --git a/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagerComponent2.java b/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagerComponent2.java new file mode 100644 index 00000000000..3dda9e2eb6e --- /dev/null +++ b/framework/ipc/test/org/apache/cloudstack/framework/messaging/server/SampleManagerComponent2.java @@ -0,0 +1,62 @@ +/* + * 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.cloudstack.framework.messaging.server; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.apache.cloudstack.framework.messaging.EventBus; +import org.apache.cloudstack.framework.messaging.EventDispatcher; +import org.apache.cloudstack.framework.messaging.EventHandler; +import org.apache.cloudstack.framework.messaging.RpcProvider; +import org.apache.cloudstack.framework.messaging.RpcServerCall; +import org.apache.cloudstack.framework.messaging.RpcServiceDispatcher; +import org.apache.cloudstack.framework.messaging.RpcServiceHandler; +import org.springframework.stereotype.Component; + +@Component +public class SampleManagerComponent2 { + @Inject + private EventBus _eventBus; + + @Inject + private RpcProvider _rpcProvider; + + public SampleManagerComponent2() { + } + + @PostConstruct + public void init() { + _rpcProvider.registerRpcServiceEndpoint( + RpcServiceDispatcher.getDispatcher(this)); + + // subscribe to all network events (for example) + _eventBus.subscribe("storage", + EventDispatcher.getDispatcher(this)); + } + + @RpcServiceHandler(command="StoragePrepare") + void onStartCommand(RpcServerCall call) { + call.completeCall("StoragePrepare completed"); + } + + @EventHandler(topic="storage.prepare") + void onPrepareNetwork(String sender, String topic, Object args) { + } +} diff --git a/framework/ipc/test/resources/SampleManagementServerAppContext.xml b/framework/ipc/test/resources/SampleManagementServerAppContext.xml new file mode 100644 index 00000000000..f53ced00b49 --- /dev/null +++ b/framework/ipc/test/resources/SampleManagementServerAppContext.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + org.apache.cloudstack.framework.messaging + + + + + diff --git a/framework/ipc/test/resources/log4j-cloud.xml b/framework/ipc/test/resources/log4j-cloud.xml new file mode 100644 index 00000000000..e9b1918b6e6 --- /dev/null +++ b/framework/ipc/test/resources/log4j-cloud.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +