Refactor and finalize framework IPC java package structure

This commit is contained in:
Kelven Yang 2012-12-13 18:44:57 -08:00
parent e998ee59f6
commit 01a4a51abf
63 changed files with 175 additions and 214 deletions

View File

@ -17,13 +17,14 @@
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.async;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public class AsyncCallbackDispatcher implements AsyncCompletionCallback { public class AsyncCallbackDispatcher implements AsyncCompletionCallback {
private static Map<Class<?>, Map<String, Method>> s_handlerCache = new HashMap<Class<?>, Map<String, Method>>(); private static Map<Class<?>, Map<String, Method>> s_handlerCache = new HashMap<Class<?>, Map<String, Method>>();

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.async;
public interface AsyncCallbackDriver { public interface AsyncCallbackDriver {
public void performCompletionCallback(AsyncCallbackDispatcher dispatcher); public void performCompletionCallback(AsyncCallbackDispatcher dispatcher);

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.async;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.async;
public interface AsyncCompletionCallback <T> { public interface AsyncCompletionCallback <T> {
void complete(T resultObject); void complete(T resultObject);

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.async;
public class InplaceAsyncCallbackDriver implements AsyncCallbackDriver { public class InplaceAsyncCallbackDriver implements AsyncCallbackDriver {

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.async;
/** /**
* This is place-holder class to help AsyncMethod to indicate void return value * This is place-holder class to help AsyncMethod to indicate void return value

View File

@ -16,10 +16,10 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.client; package org.apache.cloudstack.framework.client;
import org.apache.cloudstack.framework.messaging.EventBusBase; import org.apache.cloudstack.framework.eventbus.EventBusBase;
import org.apache.cloudstack.framework.messaging.TransportMultiplexier; import org.apache.cloudstack.framework.transport.TransportMultiplexier;
public class ClientEventBus extends EventBusBase implements TransportMultiplexier { public class ClientEventBus extends EventBusBase implements TransportMultiplexier {

View File

@ -16,9 +16,9 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.client; package org.apache.cloudstack.framework.client;
import org.apache.cloudstack.framework.messaging.TransportEndpoint; import org.apache.cloudstack.framework.transport.TransportEndpoint;
public class ClientTransportEndpoint implements TransportEndpoint { public class ClientTransportEndpoint implements TransportEndpoint {

View File

@ -16,12 +16,12 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.client; package org.apache.cloudstack.framework.client;
import org.apache.cloudstack.framework.messaging.MessageSerializer; import org.apache.cloudstack.framework.serializer.MessageSerializer;
import org.apache.cloudstack.framework.messaging.TransportEndpoint; import org.apache.cloudstack.framework.transport.TransportEndpoint;
import org.apache.cloudstack.framework.messaging.TransportEndpointSite; import org.apache.cloudstack.framework.transport.TransportEndpointSite;
import org.apache.cloudstack.framework.messaging.TransportProvider; import org.apache.cloudstack.framework.transport.TransportProvider;
public class ClientTransportProvider implements TransportProvider { public class ClientTransportProvider implements TransportProvider {

View File

@ -17,7 +17,9 @@
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.eventbus;
import org.apache.cloudstack.framework.serializer.MessageSerializer;
public interface EventBus { public interface EventBus {
void setMessageSerializer(MessageSerializer messageSerializer); void setMessageSerializer(MessageSerializer messageSerializer);

View File

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.eventbus;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -26,6 +26,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.cloudstack.framework.serializer.MessageSerializer;
public class EventBusBase implements EventBus { public class EventBusBase implements EventBus {
private Gate _gate; private Gate _gate;

View File

@ -17,7 +17,8 @@
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.eventbus;
public class EventBusEndpoint { public class EventBusEndpoint {
private EventBus _eventBus; private EventBus _eventBus;

View File

@ -16,13 +16,14 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.eventbus;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class EventDispatcher implements Subscriber { public class EventDispatcher implements Subscriber {
private static Map<Class<?>, Method> s_handlerCache = new HashMap<Class<?>, Method>(); private static Map<Class<?>, Method> s_handlerCache = new HashMap<Class<?>, Method>();

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.eventbus;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View File

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.eventbus;
public enum PublishScope { public enum PublishScope {
LOCAL, GLOBAL LOCAL, GLOBAL

View File

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.eventbus;
public interface Subscriber { public interface Subscriber {
void onPublishEvent(String senderAddress, String subject, Object args); void onPublishEvent(String senderAddress, String subject, Object args);

View File

@ -16,7 +16,9 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
import org.apache.cloudstack.framework.serializer.OnwireName;
@OnwireName(name="RpcRequest") @OnwireName(name="RpcRequest")
public class RpcCallRequestPdu { public class RpcCallRequestPdu {

View File

@ -16,7 +16,9 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
import org.apache.cloudstack.framework.serializer.OnwireName;
@OnwireName(name="RpcResponse") @OnwireName(name="RpcResponse")
public class RpcCallResponsePdu { public class RpcCallResponsePdu {

View File

@ -16,13 +16,14 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class RpcCallbackDispatcher { public class RpcCallbackDispatcher {
private static Map<Class<?>, Map<String, Method>> s_handlerCache = new HashMap<Class<?>, Map<String, Method>>(); private static Map<Class<?>, Map<String, Method>> s_handlerCache = new HashMap<Class<?>, Map<String, Method>>();

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
public interface RpcCallbackListener<T> { public interface RpcCallbackListener<T> {
void onSuccess(T result); void onSuccess(T result);

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
public interface RpcClientCall { public interface RpcClientCall {
final static int DEFAULT_RPC_TIMEOUT = 10000; final static int DEFAULT_RPC_TIMEOUT = 10000;

View File

@ -16,13 +16,14 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class RpcClientCallImpl implements RpcClientCall { public class RpcClientCallImpl implements RpcClientCall {
private String _command; private String _command;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
public class RpcException extends RuntimeException { public class RpcException extends RuntimeException {
private static final long serialVersionUID = -3164514701087423787L; private static final long serialVersionUID = -3164514701087423787L;

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
public class RpcIOException extends RpcException { public class RpcIOException extends RpcException {

View File

@ -16,7 +16,11 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
import org.apache.cloudstack.framework.serializer.MessageSerializer;
import org.apache.cloudstack.framework.transport.TransportAddressMapper;
import org.apache.cloudstack.framework.transport.TransportMultiplexier;
public interface RpcProvider extends TransportMultiplexier { public interface RpcProvider extends TransportMultiplexier {
final static String RPC_MULTIPLEXIER = "rpc"; final static String RPC_MULTIPLEXIER = "rpc";

View File

@ -16,13 +16,20 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.cloudstack.framework.serializer.MessageSerializer;
import org.apache.cloudstack.framework.transport.TransportAddress;
import org.apache.cloudstack.framework.transport.TransportAddressMapper;
import org.apache.cloudstack.framework.transport.TransportEndpoint;
import org.apache.cloudstack.framework.transport.TransportEndpointSite;
import org.apache.cloudstack.framework.transport.TransportProvider;
public class RpcProviderImpl implements RpcProvider { public class RpcProviderImpl implements RpcProvider {
public static final String RPC_MULTIPLEXIER = "rpc"; public static final String RPC_MULTIPLEXIER = "rpc";

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
public interface RpcServerCall { public interface RpcServerCall {
String getCommand(); String getCommand();

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
public class RpcServerCallImpl implements RpcServerCall { public class RpcServerCallImpl implements RpcServerCall {

View File

@ -16,13 +16,14 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class RpcServiceDispatcher implements RpcServiceEndpoint { public class RpcServiceDispatcher implements RpcServiceEndpoint {
private static Map<Class<?>, Map<String, Method>> s_handlerCache = new HashMap<Class<?>, Map<String, Method>>(); private static Map<Class<?>, Map<String, Method>> s_handlerCache = new HashMap<Class<?>, Map<String, Method>>();

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
public interface RpcServiceEndpoint { public interface RpcServiceEndpoint {
/* /*

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.rpc;
public class RpcTimeoutException extends RpcException { public class RpcTimeoutException extends RpcException {

View File

@ -16,7 +16,8 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.serializer;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.serializer;
public interface MessageSerializer { public interface MessageSerializer {
<T>String serializeTo(Class<?> clz, T object); <T>String serializeTo(Class<?> clz, T object);

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.serializer;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -32,6 +32,7 @@ import java.util.Set;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
// //
// Finding classes in a given package code is taken and modified from // 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 // Credit: http://internna.blogspot.com/2007/11/java-5-retrieving-all-classes-from.html

View File

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.serializer;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View File

@ -16,10 +16,10 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.server; package org.apache.cloudstack.framework.server;
import org.apache.cloudstack.framework.messaging.EventBusBase; import org.apache.cloudstack.framework.eventbus.EventBusBase;
import org.apache.cloudstack.framework.messaging.TransportMultiplexier; import org.apache.cloudstack.framework.transport.TransportMultiplexier;
public class ServerEventBus extends EventBusBase implements TransportMultiplexier { public class ServerEventBus extends EventBusBase implements TransportMultiplexier {

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.server; package org.apache.cloudstack.framework.server;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -24,13 +24,13 @@ import java.util.Random;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import org.apache.cloudstack.framework.messaging.MessageSerializer; import org.apache.cloudstack.framework.serializer.MessageSerializer;
import org.apache.cloudstack.framework.messaging.TransportAddress; import org.apache.cloudstack.framework.transport.TransportAddress;
import org.apache.cloudstack.framework.messaging.TransportDataPdu; import org.apache.cloudstack.framework.transport.TransportDataPdu;
import org.apache.cloudstack.framework.messaging.TransportEndpoint; import org.apache.cloudstack.framework.transport.TransportEndpoint;
import org.apache.cloudstack.framework.messaging.TransportEndpointSite; import org.apache.cloudstack.framework.transport.TransportEndpointSite;
import org.apache.cloudstack.framework.messaging.TransportPdu; import org.apache.cloudstack.framework.transport.TransportPdu;
import org.apache.cloudstack.framework.messaging.TransportProvider; import org.apache.cloudstack.framework.transport.TransportProvider;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.concurrency.NamedThreadFactory;

View File

@ -17,7 +17,7 @@
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.transport;
import java.util.Random; import java.util.Random;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.transport;
public interface TransportAddressMapper { public interface TransportAddressMapper {
String getAddress(); String getAddress();

View File

@ -16,7 +16,9 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.transport;
import org.apache.cloudstack.framework.serializer.OnwireName;
@OnwireName(name="TransportDataPdu") @OnwireName(name="TransportDataPdu")
public class TransportDataPdu extends TransportPdu { public class TransportDataPdu extends TransportPdu {

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.transport;
public interface TransportEndpoint extends TransportMultiplexier { public interface TransportEndpoint extends TransportMultiplexier {
void onAttachConfirm(boolean bSuccess, String endpointAddress); void onAttachConfirm(boolean bSuccess, String endpointAddress);

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.transport;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.transport;
public interface TransportMultiplexier { public interface TransportMultiplexier {
public void onTransportMessage(String senderEndpointAddress, String targetEndpointAddress, public void onTransportMessage(String senderEndpointAddress, String targetEndpointAddress,

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.transport;
public class TransportPdu { public class TransportPdu {
protected String _sourceAddress; protected String _sourceAddress;

View File

@ -16,7 +16,9 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.transport;
import org.apache.cloudstack.framework.serializer.MessageSerializer;
public interface TransportProvider { public interface TransportProvider {
void setMessageSerializer(MessageSerializer messageSerializer); void setMessageSerializer(MessageSerializer messageSerializer);

View File

@ -16,17 +16,19 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.codestyle;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
public class AsyncSampleCallee { public class AsyncSampleCallee {
AsyncSampleCallee _driver; AsyncSampleCallee _driver;
public void createVolume(Object realParam, AsyncCompletionCallback<TestVolume> callback) { public void createVolume(Object realParam, AsyncCompletionCallback<String> callback) {
// async executed logic // async executed logic
{ {
TestVolume resultObject = new TestVolume(); String resultObject = new String();
callback.complete(resultObject); callback.complete(resultObject);
} }

View File

@ -16,14 +16,18 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.codestyle;
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
import org.apache.cloudstack.framework.async.AsyncCallbackDriver;
import org.apache.cloudstack.framework.async.AsyncCallbackHandler;
public class AsyncSampleEventDrivenStyleCaller { public class AsyncSampleEventDrivenStyleCaller {
AsyncSampleCallee _ds = new AsyncSampleCallee(); AsyncSampleCallee _ds = new AsyncSampleCallee();
AsyncCallbackDriver _callbackDriver; AsyncCallbackDriver _callbackDriver;
public void MethodThatWillCallAsyncMethod() { public void MethodThatWillCallAsyncMethod() {
TestVolume vol = new TestVolume(); Object vol = new Object();
_ds.createVolume(vol, _ds.createVolume(vol,
new AsyncCallbackDispatcher(this) new AsyncCallbackDispatcher(this)
.setOperationName("volume.create") .setOperationName("volume.create")
@ -33,9 +37,9 @@ public class AsyncSampleEventDrivenStyleCaller {
@AsyncCallbackHandler(operationName="volume.create") @AsyncCallbackHandler(operationName="volume.create")
public void HandleVolumeCreateAsyncCallback(AsyncCallbackDispatcher callback) { public void HandleVolumeCreateAsyncCallback(AsyncCallbackDispatcher callback) {
TestVolume origVol = callback.getContextParam("origVolume"); Object origVol = callback.getContextParam("origVolume");
TestVolume resultVol = callback.getResult(); Object resultVol = callback.getResult();
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -16,18 +16,20 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.codestyle;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
public class AsyncSampleListenerStyleCaller { public class AsyncSampleListenerStyleCaller {
AsyncSampleCallee _ds; AsyncSampleCallee _ds;
public void MethodThatWillCallAsyncMethod() { public void MethodThatWillCallAsyncMethod() {
TestVolume vol = new TestVolume(); String vol = new String();
_ds.createVolume(vol, _ds.createVolume(vol,
new AsyncCompletionCallback<TestVolume>() { new AsyncCompletionCallback<String>() {
@Override @Override
public void complete(TestVolume resultObject) { public void complete(String resultObject) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }

View File

@ -16,13 +16,20 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.codestyle;
import org.apache.cloudstack.framework.rpc.RpcCallbackHandler;
import org.apache.cloudstack.framework.rpc.RpcClientCall;
import org.apache.cloudstack.framework.rpc.RpcException;
import org.apache.cloudstack.framework.rpc.RpcIOException;
import org.apache.cloudstack.framework.rpc.RpcProvider;
import org.apache.cloudstack.framework.rpc.RpcTimeoutException;
public class ClientOnlyEventDrivenStyle { public class ClientOnlyEventDrivenStyle {
RpcProvider _rpcProvider; RpcProvider _rpcProvider;
public void AsyncCallRpcService() { public void AsyncCallRpcService() {
TestCommand cmd = new TestCommand(); String cmd = new String();
_rpcProvider.newCall("host-2").setCommand("TestCommand").setCommandArg(cmd).setTimeout(10000) _rpcProvider.newCall("host-2").setCommand("TestCommand").setCommandArg(cmd).setTimeout(10000)
.setCallbackDispatcherTarget(this) .setCallbackDispatcherTarget(this)
.setContextParam("origCmd", cmd) // save context object for callback handler .setContextParam("origCmd", cmd) // save context object for callback handler
@ -32,9 +39,9 @@ public class ClientOnlyEventDrivenStyle {
@RpcCallbackHandler(command="TestCommand") @RpcCallbackHandler(command="TestCommand")
public void OnAsyncCallRpcServiceCallback(RpcClientCall call) { public void OnAsyncCallRpcServiceCallback(RpcClientCall call) {
try { try {
TestCommand origCmd = call.getContextParam("origCmd"); // restore calling context at callback handler String origCmd = call.getContextParam("origCmd"); // restore calling context at callback handler
TestCommandAnswer answer = call.get(); String answer = call.get();
} catch(RpcTimeoutException e) { } catch(RpcTimeoutException e) {

View File

@ -16,18 +16,25 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging; package org.apache.cloudstack.framework.codestyle;
import org.apache.cloudstack.framework.rpc.RpcCallbackListener;
import org.apache.cloudstack.framework.rpc.RpcClientCall;
import org.apache.cloudstack.framework.rpc.RpcException;
import org.apache.cloudstack.framework.rpc.RpcIOException;
import org.apache.cloudstack.framework.rpc.RpcProvider;
import org.apache.cloudstack.framework.rpc.RpcTimeoutException;
public class ClientOnlyListenerStyle { public class ClientOnlyListenerStyle {
RpcProvider _rpcProvider; RpcProvider _rpcProvider;
public void AsyncCallRpcService() { public void AsyncCallRpcService() {
TestCommand cmd = new TestCommand(); String cmd = new String();
_rpcProvider.newCall("host-2").setCommand("TestCommand").setCommandArg(cmd).setTimeout(10000) _rpcProvider.newCall("host-2").setCommand("TestCommand").setCommandArg(cmd).setTimeout(10000)
.addCallbackListener(new RpcCallbackListener<TestCommandAnswer>() { .addCallbackListener(new RpcCallbackListener<String>() {
@Override @Override
public void onSuccess(TestCommandAnswer result) { public void onSuccess(String result) {
} }
@Override @Override
@ -37,11 +44,11 @@ public class ClientOnlyListenerStyle {
} }
public void SyncCallRpcService() { public void SyncCallRpcService() {
TestCommand cmd = new TestCommand(); String cmd = new String();
RpcClientCall call = _rpcProvider.newCall("host-2").setCommand("TestCommand").setCommandArg(cmd).setTimeout(10000).apply(); RpcClientCall call = _rpcProvider.newCall("host-2").setCommand("TestCommand").setCommandArg(cmd).setTimeout(10000).apply();
try { try {
TestCommandAnswer answer = call.get(); String answer = call.get();
} catch (RpcTimeoutException e) { } catch (RpcTimeoutException e) {
} catch (RpcIOException e) { } catch (RpcIOException e) {

View File

@ -1,47 +0,0 @@
/*
* 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;
public class SampleComponent {
RpcProvider _rpcProvider;
EventBus _eventBus;
public SampleComponent() {
}
public void init() {
_rpcProvider.registerRpcServiceEndpoint(
RpcServiceDispatcher.getDispatcher(this));
// subscribe to all network events (for example)
_eventBus.subscribe("network",
EventDispatcher.getDispatcher(this));
}
@RpcServiceHandler(command="StartCommand")
void onStartCommand(RpcServerCall call) {
call.completeCall("Call response");
}
@EventHandler(topic="network.prepare")
void onPrepareNetwork(String sender, String topic, Object args) {
}
}

View File

@ -1,25 +0,0 @@
/*
* 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;
@OnwireName(name="TestCommand")
public class TestCommand {
public TestCommand() {
}
}

View File

@ -1,23 +0,0 @@
/*
* 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;
@OnwireName(name="TestCommandAnswer")
public class TestCommandAnswer {
}

View File

@ -1,5 +0,0 @@
package org.apache.cloudstack.framework.messaging;
public class TestVolume {
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.server; package org.apache.cloudstack.framework.sampleserver;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.server; package org.apache.cloudstack.framework.sampleserver;
import java.io.File; import java.io.File;
import java.net.URISyntaxException; import java.net.URISyntaxException;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.server; package org.apache.cloudstack.framework.sampleserver;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
@ -24,15 +24,15 @@ import java.util.TimerTask;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.cloudstack.framework.messaging.EventBus; import org.apache.cloudstack.framework.eventbus.EventBus;
import org.apache.cloudstack.framework.messaging.EventDispatcher; import org.apache.cloudstack.framework.eventbus.EventDispatcher;
import org.apache.cloudstack.framework.messaging.EventHandler; import org.apache.cloudstack.framework.eventbus.EventHandler;
import org.apache.cloudstack.framework.messaging.RpcCallbackListener; import org.apache.cloudstack.framework.rpc.RpcCallbackListener;
import org.apache.cloudstack.framework.messaging.RpcException; import org.apache.cloudstack.framework.rpc.RpcException;
import org.apache.cloudstack.framework.messaging.RpcProvider; import org.apache.cloudstack.framework.rpc.RpcProvider;
import org.apache.cloudstack.framework.messaging.RpcServerCall; import org.apache.cloudstack.framework.rpc.RpcServerCall;
import org.apache.cloudstack.framework.messaging.RpcServiceDispatcher; import org.apache.cloudstack.framework.rpc.RpcServiceDispatcher;
import org.apache.cloudstack.framework.messaging.RpcServiceHandler; import org.apache.cloudstack.framework.rpc.RpcServiceHandler;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -16,18 +16,18 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.server; package org.apache.cloudstack.framework.sampleserver;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.cloudstack.framework.messaging.EventBus; import org.apache.cloudstack.framework.eventbus.EventBus;
import org.apache.cloudstack.framework.messaging.EventDispatcher; import org.apache.cloudstack.framework.eventbus.EventDispatcher;
import org.apache.cloudstack.framework.messaging.EventHandler; import org.apache.cloudstack.framework.eventbus.EventHandler;
import org.apache.cloudstack.framework.messaging.RpcProvider; import org.apache.cloudstack.framework.rpc.RpcProvider;
import org.apache.cloudstack.framework.messaging.RpcServerCall; import org.apache.cloudstack.framework.rpc.RpcServerCall;
import org.apache.cloudstack.framework.messaging.RpcServiceDispatcher; import org.apache.cloudstack.framework.rpc.RpcServiceDispatcher;
import org.apache.cloudstack.framework.messaging.RpcServiceHandler; import org.apache.cloudstack.framework.rpc.RpcServiceHandler;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;

View File

@ -16,9 +16,9 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.server; package org.apache.cloudstack.framework.sampleserver;
import org.apache.cloudstack.framework.messaging.OnwireName; import org.apache.cloudstack.framework.serializer.OnwireName;
@OnwireName(name="SampleStoragePrepareAnswer") @OnwireName(name="SampleStoragePrepareAnswer")
public class SampleStoragePrepareAnswer { public class SampleStoragePrepareAnswer {

View File

@ -16,9 +16,9 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.framework.messaging.server; package org.apache.cloudstack.framework.sampleserver;
import org.apache.cloudstack.framework.messaging.OnwireName; import org.apache.cloudstack.framework.serializer.OnwireName;
@OnwireName(name="SampleStoragePrepareCommand") @OnwireName(name="SampleStoragePrepareCommand")
public class SampleStoragePrepareCommand { public class SampleStoragePrepareCommand {

View File

@ -16,30 +16,30 @@
<context:annotation-config /> <context:annotation-config />
<context:component-scan base-package="org.apache.cloudstack, com.cloud" /> <context:component-scan base-package="org.apache.cloudstack, com.cloud" />
<bean id="onwireRegistry" class="org.apache.cloudstack.framework.messaging.OnwireClassRegistry" <bean id="onwireRegistry" class="org.apache.cloudstack.framework.serializer.OnwireClassRegistry"
init-method="scan" > init-method="scan" >
<property name="packages"> <property name="packages">
<list> <list>
<value>org.apache.cloudstack.framework.messaging</value> <value>org.apache.cloudstack.framework</value>
</list> </list>
</property> </property>
</bean> </bean>
<bean id="messageSerializer" class="org.apache.cloudstack.framework.messaging.JsonMessageSerializer"> <bean id="messageSerializer" class="org.apache.cloudstack.framework.serializer.JsonMessageSerializer">
<property name="onwireClassRegistry" ref="onwireRegistry" /> <property name="onwireClassRegistry" ref="onwireRegistry" />
</bean> </bean>
<bean id="transportProvider" class="org.apache.cloudstack.framework.messaging.server.ServerTransportProvider" init-method="initialize"> <bean id="transportProvider" class="org.apache.cloudstack.framework.server.ServerTransportProvider" init-method="initialize">
<property name="workerPoolSize" value="5" /> <property name="workerPoolSize" value="5" />
<property name="nodeId" value="Node1" /> <property name="nodeId" value="Node1" />
<property name="messageSerializer" ref="messageSerializer" /> <property name="messageSerializer" ref="messageSerializer" />
</bean> </bean>
<bean id="rpcProvider" class="org.apache.cloudstack.framework.messaging.RpcProviderImpl" init-method="initialize"> <bean id="rpcProvider" class="org.apache.cloudstack.framework.rpc.RpcProviderImpl" init-method="initialize">
<constructor-arg ref="transportProvider" /> <constructor-arg ref="transportProvider" />
<property name="messageSerializer" ref="messageSerializer" /> <property name="messageSerializer" ref="messageSerializer" />
</bean> </bean>
<bean id="eventBus" class = "org.apache.cloudstack.framework.messaging.EventBusBase" /> <bean id="eventBus" class = "org.apache.cloudstack.framework.eventbus.EventBusBase" />
</beans> </beans>