mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Refactor and finalize framework IPC java package structure
This commit is contained in:
parent
e998ee59f6
commit
01a4a51abf
@ -17,13 +17,14 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.async;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class AsyncCallbackDispatcher implements AsyncCompletionCallback {
|
||||
private static Map<Class<?>, Map<String, Method>> s_handlerCache = new HashMap<Class<?>, Map<String, Method>>();
|
||||
@ -16,7 +16,8 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.async;
|
||||
|
||||
|
||||
public interface AsyncCallbackDriver {
|
||||
public void performCompletionCallback(AsyncCallbackDispatcher dispatcher);
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.async;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.async;
|
||||
|
||||
public interface AsyncCompletionCallback <T> {
|
||||
void complete(T resultObject);
|
||||
@ -16,7 +16,8 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.async;
|
||||
|
||||
|
||||
public class InplaceAsyncCallbackDriver implements AsyncCallbackDriver {
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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
|
||||
@ -16,10 +16,10 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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.messaging.TransportMultiplexier;
|
||||
import org.apache.cloudstack.framework.eventbus.EventBusBase;
|
||||
import org.apache.cloudstack.framework.transport.TransportMultiplexier;
|
||||
|
||||
public class ClientEventBus extends EventBusBase implements TransportMultiplexier {
|
||||
|
||||
@ -16,9 +16,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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 {
|
||||
|
||||
@ -16,12 +16,12 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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.messaging.TransportEndpoint;
|
||||
import org.apache.cloudstack.framework.messaging.TransportEndpointSite;
|
||||
import org.apache.cloudstack.framework.messaging.TransportProvider;
|
||||
import org.apache.cloudstack.framework.serializer.MessageSerializer;
|
||||
import org.apache.cloudstack.framework.transport.TransportEndpoint;
|
||||
import org.apache.cloudstack.framework.transport.TransportEndpointSite;
|
||||
import org.apache.cloudstack.framework.transport.TransportProvider;
|
||||
|
||||
public class ClientTransportProvider implements TransportProvider {
|
||||
|
||||
@ -17,7 +17,9 @@
|
||||
* 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 {
|
||||
void setMessageSerializer(MessageSerializer messageSerializer);
|
||||
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.eventbus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -26,6 +26,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.framework.serializer.MessageSerializer;
|
||||
|
||||
public class EventBusBase implements EventBus {
|
||||
|
||||
private Gate _gate;
|
||||
@ -17,7 +17,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.eventbus;
|
||||
|
||||
|
||||
public class EventBusEndpoint {
|
||||
private EventBus _eventBus;
|
||||
@ -16,13 +16,14 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.eventbus;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class EventDispatcher implements Subscriber {
|
||||
private static Map<Class<?>, Method> s_handlerCache = new HashMap<Class<?>, Method>();
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.eventbus;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.eventbus;
|
||||
|
||||
public enum PublishScope {
|
||||
LOCAL, GLOBAL
|
||||
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.eventbus;
|
||||
|
||||
public interface Subscriber {
|
||||
void onPublishEvent(String senderAddress, String subject, Object args);
|
||||
@ -16,7 +16,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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")
|
||||
public class RpcCallRequestPdu {
|
||||
@ -16,7 +16,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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")
|
||||
public class RpcCallResponsePdu {
|
||||
@ -16,13 +16,14 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class RpcCallbackDispatcher {
|
||||
|
||||
private static Map<Class<?>, Map<String, Method>> s_handlerCache = new HashMap<Class<?>, Map<String, Method>>();
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -16,7 +16,8 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
|
||||
public interface RpcCallbackListener<T> {
|
||||
void onSuccess(T result);
|
||||
@ -16,7 +16,8 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
|
||||
public interface RpcClientCall {
|
||||
final static int DEFAULT_RPC_TIMEOUT = 10000;
|
||||
@ -16,13 +16,14 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class RpcClientCallImpl implements RpcClientCall {
|
||||
|
||||
private String _command;
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
public class RpcException extends RuntimeException {
|
||||
private static final long serialVersionUID = -3164514701087423787L;
|
||||
@ -16,7 +16,8 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
|
||||
public class RpcIOException extends RpcException {
|
||||
|
||||
@ -16,7 +16,11 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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 {
|
||||
final static String RPC_MULTIPLEXIER = "rpc";
|
||||
@ -16,13 +16,20 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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 static final String RPC_MULTIPLEXIER = "rpc";
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
public interface RpcServerCall {
|
||||
String getCommand();
|
||||
@ -16,7 +16,8 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
|
||||
public class RpcServerCallImpl implements RpcServerCall {
|
||||
|
||||
@ -16,13 +16,14 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class RpcServiceDispatcher implements RpcServiceEndpoint {
|
||||
|
||||
private static Map<Class<?>, Map<String, Method>> s_handlerCache = new HashMap<Class<?>, Map<String, Method>>();
|
||||
@ -16,7 +16,8 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
|
||||
public interface RpcServiceEndpoint {
|
||||
/*
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -16,7 +16,8 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.rpc;
|
||||
|
||||
|
||||
public class RpcTimeoutException extends RpcException {
|
||||
|
||||
@ -16,7 +16,8 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.serializer;
|
||||
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.serializer;
|
||||
|
||||
public interface MessageSerializer {
|
||||
<T>String serializeTo(Class<?> clz, T object);
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.serializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -32,6 +32,7 @@ import java.util.Set;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
|
||||
//
|
||||
// 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
|
||||
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.serializer;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -16,10 +16,10 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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.messaging.TransportMultiplexier;
|
||||
import org.apache.cloudstack.framework.eventbus.EventBusBase;
|
||||
import org.apache.cloudstack.framework.transport.TransportMultiplexier;
|
||||
|
||||
public class ServerEventBus extends EventBusBase implements TransportMultiplexier {
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging.server;
|
||||
package org.apache.cloudstack.framework.server;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -24,13 +24,13 @@ import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.cloudstack.framework.messaging.MessageSerializer;
|
||||
import org.apache.cloudstack.framework.messaging.TransportAddress;
|
||||
import org.apache.cloudstack.framework.messaging.TransportDataPdu;
|
||||
import org.apache.cloudstack.framework.messaging.TransportEndpoint;
|
||||
import org.apache.cloudstack.framework.messaging.TransportEndpointSite;
|
||||
import org.apache.cloudstack.framework.messaging.TransportPdu;
|
||||
import org.apache.cloudstack.framework.messaging.TransportProvider;
|
||||
import org.apache.cloudstack.framework.serializer.MessageSerializer;
|
||||
import org.apache.cloudstack.framework.transport.TransportAddress;
|
||||
import org.apache.cloudstack.framework.transport.TransportDataPdu;
|
||||
import org.apache.cloudstack.framework.transport.TransportEndpoint;
|
||||
import org.apache.cloudstack.framework.transport.TransportEndpointSite;
|
||||
import org.apache.cloudstack.framework.transport.TransportPdu;
|
||||
import org.apache.cloudstack.framework.transport.TransportProvider;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
@ -17,7 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.transport;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.transport;
|
||||
|
||||
public interface TransportAddressMapper {
|
||||
String getAddress();
|
||||
@ -16,7 +16,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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")
|
||||
public class TransportDataPdu extends TransportPdu {
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.transport;
|
||||
|
||||
public interface TransportEndpoint extends TransportMultiplexier {
|
||||
void onAttachConfirm(boolean bSuccess, String endpointAddress);
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.transport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.transport;
|
||||
|
||||
public interface TransportMultiplexier {
|
||||
public void onTransportMessage(String senderEndpointAddress, String targetEndpointAddress,
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
package org.apache.cloudstack.framework.transport;
|
||||
|
||||
public class TransportPdu {
|
||||
protected String _sourceAddress;
|
||||
@ -16,7 +16,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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 {
|
||||
void setMessageSerializer(MessageSerializer messageSerializer);
|
||||
@ -16,17 +16,19 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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 {
|
||||
AsyncSampleCallee _driver;
|
||||
|
||||
public void createVolume(Object realParam, AsyncCompletionCallback<TestVolume> callback) {
|
||||
public void createVolume(Object realParam, AsyncCompletionCallback<String> callback) {
|
||||
|
||||
// async executed logic
|
||||
{
|
||||
|
||||
TestVolume resultObject = new TestVolume();
|
||||
String resultObject = new String();
|
||||
callback.complete(resultObject);
|
||||
|
||||
}
|
||||
@ -16,14 +16,18 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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 {
|
||||
AsyncSampleCallee _ds = new AsyncSampleCallee();
|
||||
AsyncCallbackDriver _callbackDriver;
|
||||
|
||||
public void MethodThatWillCallAsyncMethod() {
|
||||
TestVolume vol = new TestVolume();
|
||||
Object vol = new Object();
|
||||
_ds.createVolume(vol,
|
||||
new AsyncCallbackDispatcher(this)
|
||||
.setOperationName("volume.create")
|
||||
@ -33,9 +37,9 @@ public class AsyncSampleEventDrivenStyleCaller {
|
||||
|
||||
@AsyncCallbackHandler(operationName="volume.create")
|
||||
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) {
|
||||
@ -16,18 +16,20 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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 {
|
||||
AsyncSampleCallee _ds;
|
||||
|
||||
public void MethodThatWillCallAsyncMethod() {
|
||||
TestVolume vol = new TestVolume();
|
||||
String vol = new String();
|
||||
|
||||
_ds.createVolume(vol,
|
||||
new AsyncCompletionCallback<TestVolume>() {
|
||||
new AsyncCompletionCallback<String>() {
|
||||
@Override
|
||||
public void complete(TestVolume resultObject) {
|
||||
public void complete(String resultObject) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@ -16,13 +16,20 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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 {
|
||||
RpcProvider _rpcProvider;
|
||||
|
||||
public void AsyncCallRpcService() {
|
||||
TestCommand cmd = new TestCommand();
|
||||
String cmd = new String();
|
||||
_rpcProvider.newCall("host-2").setCommand("TestCommand").setCommandArg(cmd).setTimeout(10000)
|
||||
.setCallbackDispatcherTarget(this)
|
||||
.setContextParam("origCmd", cmd) // save context object for callback handler
|
||||
@ -32,9 +39,9 @@ public class ClientOnlyEventDrivenStyle {
|
||||
@RpcCallbackHandler(command="TestCommand")
|
||||
public void OnAsyncCallRpcServiceCallback(RpcClientCall call) {
|
||||
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) {
|
||||
|
||||
@ -16,18 +16,25 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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 {
|
||||
|
||||
RpcProvider _rpcProvider;
|
||||
|
||||
public void AsyncCallRpcService() {
|
||||
TestCommand cmd = new TestCommand();
|
||||
String cmd = new String();
|
||||
_rpcProvider.newCall("host-2").setCommand("TestCommand").setCommandArg(cmd).setTimeout(10000)
|
||||
.addCallbackListener(new RpcCallbackListener<TestCommandAnswer>() {
|
||||
.addCallbackListener(new RpcCallbackListener<String>() {
|
||||
@Override
|
||||
public void onSuccess(TestCommandAnswer result) {
|
||||
public void onSuccess(String result) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,11 +44,11 @@ public class ClientOnlyListenerStyle {
|
||||
}
|
||||
|
||||
public void SyncCallRpcService() {
|
||||
TestCommand cmd = new TestCommand();
|
||||
String cmd = new String();
|
||||
RpcClientCall call = _rpcProvider.newCall("host-2").setCommand("TestCommand").setCommandArg(cmd).setTimeout(10000).apply();
|
||||
|
||||
try {
|
||||
TestCommandAnswer answer = call.get();
|
||||
String answer = call.get();
|
||||
} catch (RpcTimeoutException e) {
|
||||
|
||||
} catch (RpcIOException e) {
|
||||
@ -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) {
|
||||
}
|
||||
}
|
||||
@ -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() {
|
||||
}
|
||||
}
|
||||
@ -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 {
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
package org.apache.cloudstack.framework.messaging;
|
||||
|
||||
public class TestVolume {
|
||||
|
||||
}
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging.server;
|
||||
package org.apache.cloudstack.framework.sampleserver;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging.server;
|
||||
package org.apache.cloudstack.framework.sampleserver;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging.server;
|
||||
package org.apache.cloudstack.framework.sampleserver;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@ -24,15 +24,15 @@ import java.util.TimerTask;
|
||||
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.RpcCallbackListener;
|
||||
import org.apache.cloudstack.framework.messaging.RpcException;
|
||||
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.apache.cloudstack.framework.eventbus.EventBus;
|
||||
import org.apache.cloudstack.framework.eventbus.EventDispatcher;
|
||||
import org.apache.cloudstack.framework.eventbus.EventHandler;
|
||||
import org.apache.cloudstack.framework.rpc.RpcCallbackListener;
|
||||
import org.apache.cloudstack.framework.rpc.RpcException;
|
||||
import org.apache.cloudstack.framework.rpc.RpcProvider;
|
||||
import org.apache.cloudstack.framework.rpc.RpcServerCall;
|
||||
import org.apache.cloudstack.framework.rpc.RpcServiceDispatcher;
|
||||
import org.apache.cloudstack.framework.rpc.RpcServiceHandler;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -16,18 +16,18 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging.server;
|
||||
package org.apache.cloudstack.framework.sampleserver;
|
||||
|
||||
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.apache.cloudstack.framework.eventbus.EventBus;
|
||||
import org.apache.cloudstack.framework.eventbus.EventDispatcher;
|
||||
import org.apache.cloudstack.framework.eventbus.EventHandler;
|
||||
import org.apache.cloudstack.framework.rpc.RpcProvider;
|
||||
import org.apache.cloudstack.framework.rpc.RpcServerCall;
|
||||
import org.apache.cloudstack.framework.rpc.RpcServiceDispatcher;
|
||||
import org.apache.cloudstack.framework.rpc.RpcServiceHandler;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -16,9 +16,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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")
|
||||
public class SampleStoragePrepareAnswer {
|
||||
@ -16,9 +16,9 @@
|
||||
* specific language governing permissions and limitations
|
||||
* 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")
|
||||
public class SampleStoragePrepareCommand {
|
||||
@ -16,30 +16,30 @@
|
||||
<context:annotation-config />
|
||||
<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" >
|
||||
<property name="packages">
|
||||
<list>
|
||||
<value>org.apache.cloudstack.framework.messaging</value>
|
||||
<value>org.apache.cloudstack.framework</value>
|
||||
</list>
|
||||
</property>
|
||||
</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" />
|
||||
</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="nodeId" value="Node1" />
|
||||
<property name="messageSerializer" ref="messageSerializer" />
|
||||
</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" />
|
||||
<property name="messageSerializer" ref="messageSerializer" />
|
||||
</bean>
|
||||
|
||||
<bean id="eventBus" class = "org.apache.cloudstack.framework.messaging.EventBusBase" />
|
||||
<bean id="eventBus" class = "org.apache.cloudstack.framework.eventbus.EventBusBase" />
|
||||
|
||||
</beans>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user