blob: bdacd67661702f10f1f624d5ef7dc834f2fdffcb [file] [log] [blame]
Jordan Haltermanb8cace72018-07-02 17:39:21 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cluster;
17
18import org.onosproject.store.service.Serializer;
19
20/**
21 * Manages remote proxy services and instances.
22 * <p>
23 * This service can be used to make arbitrary method calls on remote objects in ONOS. The objects on which the methods
24 * are called are referred to as <em>services</em> and are made available to the proxy service by
25 * {@link #registerProxyService(Class, Object, Serializer) registering} a service instance. Services must implement
26 * an <em>interface</em> which can be used to construct a Java proxy. Proxy interfaces may define either synchronous
27 * or asynchronous methods. Synchronous proxy methods will be blocked, and asynchronous proxy methods (which must
28 * return {@link java.util.concurrent.CompletableFuture}) will be proxied using asynchronous intra-cluster
29 * communication. To make a remote call on a proxy service, get an instance of the {@link ProxyFactory} for the service
30 * type using {@link #getProxyFactory(Class, Serializer)}. The proxy factory is responsible for constructing proxy
31 * instances for each node in the cluster. Once a proxy instance is constructed, calls on the proxy instance will be
32 * transparently serialized and sent to the associated peer and be executed on the proxy service registered by that
33 * peer.
34 */
35public interface ProxyService {
36
37 /**
38 * Returns a new proxy factory for the given type.
39 * <p>
40 * The proxy {@code type} passed to this method must be an interface. The proxy factory can be used to construct
41 * proxy instances for different nodes in the cluster.
42 *
43 * @param type the proxy type
44 * @param serializer the proxy serializer
45 * @param <T> the proxy type
46 * @return the proxy factory
47 * @throws IllegalArgumentException if the {@code type} is not an interface
48 */
49 <T> ProxyFactory<T> getProxyFactory(Class<T> type, Serializer serializer);
50
51 /**
52 * Registers a proxy service.
53 * <p>
54 * The proxy {@code type} passed to this method must be an interface. The {@code proxy} should be an implementation
55 * of that interface on which methods will be called when proxy calls from other nodes are received.
56 *
57 * @param type the proxy type
58 * @param proxy the proxy service
59 * @param serializer the proxy serializer
60 * @param <T> the proxy type
61 * @throws IllegalArgumentException if the {@code type} is not an interface
62 */
63 <T> void registerProxyService(Class<? super T> type, T proxy, Serializer serializer);
64
65 /**
66 * Unregisters the proxy service of the given type.
67 * <p>
68 * Once the proxy service has been unregistered, calls to the proxy instance on this node will fail.
69 *
70 * @param type the proxy service type to unregister
71 */
72 void unregisterProxyService(Class<?> type);
73
74}