パッケージ org.piax.gtrans
クラス RPCInvoker<T extends RPCIf,E extends Endpoint>
java.lang.Object
org.piax.gtrans.RPCInvoker<T,E>
- すべての実装されたインタフェース:
RPCIf
- 直系の既知のサブクラス:
FloodingNode,NodeManager,RingManager,SkipGraph
public class RPCInvoker<T extends RPCIf,E extends Endpoint> extends Object implements RPCIf
ChannelTransportを指定して、そのTransport上でRPCを行うためのクラスである。
RPCは、以下のようにして行う。
int n = rpcInvoker.getStub(AppIf.class,targetObjectId,targetEndpoint).appMethod(arg1,arg2);
ここで、AppIfは、対象のオブジェクトが実装しているインターフェースである。 AppIfは、RPCIfを継承していなければいけない。targetObjectIdは、対象のObjectIdである。 targetEndpointは、対象のオブジェクトが存在するピアを表すEndpointである。Endpointの実際の型は、 このクラスの型パラメータEが示す型でなければいけない。対象は、対象の存在するピアの対応する RPCInvokerに対して、registerRPCObjectを使用して登録されていなければならない。 appMethodは、対象が持つメソッドであり、arg1, arg2は、appMethodの引数であるものとする。 appMethodの返り値の型はintであるとする。 appMethodは、AppIfあるいは、 そのスーパー・インターフェースで宣言されていなければいけない。さらに、対象が呼び出し側と異なるピアに存在する場合は @RemoteCallableアノテーションがついていて、かつRPCExceptionをスローするように宣言されていなければいけない。 例えば、以下の通りである。
import org.piax.gtrans.RemoteCallable;
interface AppIf extends RPCIf {
@RemoteCallable
int appMethod(int a1, String a2) throws RPCException;
}
引数のコピー
RPCでは、引数は、一般にはコピーされるが、保証されない。呼び出されたメソッド内で引数のオブジェクトを変更した場合、
それが呼び出し側に反映されるかどうかは不明であるので注意が必要である。
呼び出された側では、変更しない方が無難である。
oneway RPC
呼び出したメソッドの終了を待つ通常の同期型RPCの他に、終了を待たないoneway RPCが存在する。 oneway RPCでは、呼び出したメソッドの返り値を受け取ることはできない。 @RemoteCallable アノテーションにType.ONEWAYの引数を指定すると
デフォルトではONEWAY RPCとして呼ばれる。
oneway RPCを指定しても実際に、非同期になるかどうかは、
使用しているトランスポートに依存するので、注意が必要である。
動的RPC
RPCは原則として対象のインターフェースを指定して行うが 例外的に対象のインターフェースが、実行時まで不明な場合がある。 例えば、デバッグなどで実行時に人間が、メソッドや引数を指定する場合である。 この場合は、人間はインターフェースを知っているが、呼び出し側のプログラムには インターフェースが存在しないことがある。 このような場合のために、動的な呼び出しを用意している。 以下のように使用する。
try {
Object r = rpcInvoker.rcall(targetObjectId,targetEndpoint,"appMethod",arg1,arg2);
} catch (Throwable t) {
// 例外処理
}
返り値は常にObject型となる。intなど基本型はボクシングが行われてInteger型などになる。
例外は、何が発生するか不明なので、Throwableを受けなければいけない。
その他
getStubには、いくつかバリエーションが存在する。 timeoutを指定できるもの、RPCModeを指定できるもの、 targetObjectId,targetEndpointの代わりにCallerrIdを指定するものが存在する。 timeoutが指定できないものでは、GTransConfigValues.rpcTimeoutが使用される。 RPCModeを指定できるものでは、指定によりoneway RPCかどうかの決定方法を 以下のように変更可能である。- AUTOならば、Annotationにより決定する(デフォルト)
- SYNCならば、常に同期型である
- ONEWAYならば、常にOnewayである
-
ネストされたクラスの概要
ネストされたクラス 修飾子とタイプ クラス 説明 static classRPCInvoker.MethodCall -
フィールドの概要
フィールド 修飾子とタイプ フィールド 説明 Map<E,org.piax.gtrans.RPCInvoker.ChannelPoolEntry>channelPoolprotected booleanisActiveRPCInvokerオブジェクトがアクティブな状態であることを示す。protected ObjectIdobjIdstatic booleanPOOL_CHANNELstatic intPOOL_CHANNEL_SIZEprotected ChannelTransport<E>transprotected TransportIdtransIdstatic booleanUSE_CHANNEL_FOR_ONEWAY -
コンストラクタの概要
コンストラクタ コンストラクタ 説明 RPCInvoker(TransportId rpcId, ChannelTransport<? super E> trans) -
メソッドの概要
修飾子とタイプ メソッド 説明 voidchangeRPCTimeout(RPCIf stub, int timeout)voidchangeTransport(ChannelTransport<?> trans)protected voidcheckActive()RPCInvokerオブジェクトがアクティブな状態であるかどうかをチェックする。static ObjectIdcreateObjId(ChannelTransport<?> trans, ObjectId rpcId)voidfin()EgetEndpoint()RPCIfgetRPCObject(ObjectId objId)PeerIdgetSrcPeerId()RPCで呼ばれた際の呼び出し側を返す。TgetStub(E remotePeer)リモートピア上のこのオブジェクトに対応するRPCInvokerオブジェクトのメソッドを 呼び出すためのstubを返す。TgetStub(E remotePeer, int timeout)リモートピア上のこのオブジェクトに対応するRPCInvokerオブジェクトのメソッドを呼び出すためのstubを返す。<S extends RPCIf>
SgetStub(Class<S> clz, CalleeId cid)リモートピア上の、clz型のインターフェースをを持ち、 cidで指定される オブジェクトのメソッドを呼び出すためのstubを返す。<S extends RPCIf>
SgetStub(Class<S> clz, CalleeId cid, int timeout)リモートピア上の、clz型のインターフェースを持ち、 cidで指定される オブジェクトのメソッドを呼び出すためのstubを返す。<S extends RPCIf>
SgetStub(Class<S> clz, CalleeId cid, int timeout, RPCMode rpcMode)リモートピア上の、clz型のインターフェースを実装し、 cidで指定されるオブジェクトのメソッドを呼び出すためのstubを返す。<S extends RPCIf>
SgetStub(Class<S> clz, CalleeId cid, RPCMode rpcMode)リモートピア上の、clz型のインターフェースを実装し、 cidで指定されるオブジェクトのメソッドを呼び出すためのstubを返す。<S extends RPCIf>
SgetStub(Class<S> clz, ObjectId targetId, E remotePeer)リモートピア上の、clz型のインターフェースを持ち、 targetIdを持つオブジェクトのメソッドを呼び出すためのstubを返す。<S extends RPCIf>
SgetStub(Class<S> clz, ObjectId targetId, E remotePeer, int timeout)リモートピア上の、clz型のインターフェースを持ち、 targetIdを持つオブジェクトのメソッドを呼び出すためのstubを返す。<S extends RPCIf>
SgetStub(Class<S> clz, ObjectId targetId, E remotePeer, int timeout, RPCMode rpcMode)リモートピア上の、clz型のインターフェースを実装し、 targetIdを持つオブジェクトのメソッドを呼び出すためのstubを返す。<S extends RPCIf>
SgetStub(Class<S> clz, ObjectId targetId, E remotePeer, RPCMode rpcMode)リモートピア上の、clz型のインターフェースを実装し、 targetIdを持つオブジェクトのメソッドを呼び出すためのstubを返す。ChannelTransport<E>getTransport()protected ObjectinvokeInReceive(boolean isOneway, RPCIf obj, RPCInvoker.MethodCall mc)booleanisOnline()推奨されていません。protected RPCInvoker.MethodCallnewMethodCall(ObjectId target, E remotePeer, boolean oneway, String method, Object... args)voidoffline()推奨されていません。voidonline()推奨されていません。Objectrcall(CalleeId cid, int timeout, String method, Object... args)リモートピア上の、clz型のインターフェースを実装し、 cidで指定されるオブジェクトのメソッドを動的に呼び出す。Objectrcall(CalleeId cid, int timeout, RPCMode rpcMode, String method, Object... args)cidで指定されるオブジェクトのメソッドを動的に呼び出す。Objectrcall(CalleeId cid, String method, Object... args)Call a remote method on the object specified by cid.Objectrcall(CalleeId cid, RPCMode rpcMode, String method, Object... args)cidで指定されるオブジェクトのメソッドを動的に呼び出す。Objectrcall(ObjectId targetId, E remotePeer, int timeout, String method, Object... args)リモートピア上の、clz型のインターフェースを実装し、 targetIdを持つオブジェクトのメソッドを動的に呼び出す。Objectrcall(ObjectId targetId, E remotePeer, int timeout, RPCMode rpcMode, String method, Object... args)targetIdを持つオブジェクトのメソッドを動的に呼び出す。Objectrcall(ObjectId targetId, E remotePeer, String method, Object... args)リモートピア上の、clz型のインターフェースを実装し、 targetIdを持つオブジェクトのメソッドを動的に呼び出す。Objectrcall(ObjectId targetId, E remotePeer, RPCMode rpcMode, String method, Object... args)リモートピア上の、clz型のインターフェースを実装し、 targetIdを持つオブジェクトのメソッドを動的に呼び出す。protected voidreceiveOneway(RPCInvoker.MethodCall mc)protected ReturnValue<?>receiveSync(RPCInvoker.MethodCall mc)voidregisterRPCObject(ObjectId objId, RPCIf obj)RPCの対象となるオブジェクトを登録する。ReturnValue<?>sendInvoke(ObjectId target, E remotePeer, int timeout, String method, Object... args)send an oneway RPC invocation message.voidsendOnewayInvoke(ObjectId target, E remotePeer, String method, Object... args)send an oneway RPC invocation message.booleanunregisterRPCObject(ObjectId objId, RPCIf obj)RPC対象から抹消する。
-
フィールド詳細
-
POOL_CHANNEL
public static final boolean POOL_CHANNEL- 関連項目:
- 定数フィールド値
-
POOL_CHANNEL_SIZE
public static int POOL_CHANNEL_SIZE -
channelPool
-
USE_CHANNEL_FOR_ONEWAY
public static boolean USE_CHANNEL_FOR_ONEWAY -
transId
-
objId
-
trans
-
isActive
protected volatile boolean isActiveRPCInvokerオブジェクトがアクティブな状態であることを示す。 fin() が呼ばれた場合はfalseとなる。
-
-
コンストラクタの詳細
-
RPCInvoker
public RPCInvoker(TransportId rpcId, ChannelTransport<? super E> trans) throws IdConflictException, IOException
-
-
メソッドの詳細
-
getSrcPeerId
RPCで呼ばれた際の呼び出し側を返す。 同期的local呼び出しでは、変更されないことに注意が 必要である。一度も非同期呼び出しもremote呼び出しも されていない場合はnullを返す。- 戻り値:
- 呼び出し側のPeerId
-
createObjId
-
fin
public void fin() -
checkActive
RPCInvokerオブジェクトがアクティブな状態であるかどうかをチェックする。 fin() が呼ばれてインアクティブな状態である場合は、IllegalStateExceptionがthrowされる。 サブクラスの場合も含め、fin() の後に呼び出されては困る場合のメソッド呼び出しの際のチェックに用いる。- 例外:
IllegalStateException- RPCInvokerオブジェクトがインアクティブな状態である場合
-
changeTransport
-
registerRPCObject
RPCの対象となるオブジェクトを登録する。 RPCで呼び出されるオブジェクトは予め登録する必要がある。- パラメータ:
objId- 対象のObjectIdobj- 対象オブジェクト- 例外:
IdConflictException- thrown if the object ID is already used.
-
unregisterRPCObject
RPC対象から抹消する。- パラメータ:
objId- 対象のObjectIdobj- 対象オブジェクト- 戻り値:
- 削除したらtrue、もともと登録されていない場合はfalseを返す。
-
getRPCObject
-
online
推奨されていません。 -
offline
推奨されていません。 -
isOnline
推奨されていません。 -
getTransport
-
getEndpoint
-
getStub
リモートピア上のこのオブジェクトに対応するRPCInvokerオブジェクトのメソッドを 呼び出すためのstubを返す。- パラメータ:
remotePeer- リモートピアを示すEndpoint- 戻り値:
- RPCのためのstub
-
getStub
リモートピア上のこのオブジェクトに対応するRPCInvokerオブジェクトのメソッドを呼び出すためのstubを返す。- パラメータ:
remotePeer- リモートピアを示すEndpointtimeout- timeout値(msec)- 戻り値:
- RPCのためのstub
-
getStub
public <S extends RPCIf> S getStub(Class<S> clz, ObjectId targetId, E remotePeer, int timeout, RPCMode rpcMode)リモートピア上の、clz型のインターフェースを実装し、 targetIdを持つオブジェクトのメソッドを呼び出すためのstubを返す。- 型パラメータ:
S- A type of RPCIf- パラメータ:
clz- RPC呼び出しの対象となるオブジェクトが実装しているインターフェースtargetId- RPC呼び出しの対象となるオブジェクトのIdremotePeer- リモートピアを示すEndpointtimeout- timeout値(msec)rpcMode- Onewayかどうかを指定する。 AUTOならば、Annotationにより決定する。 SYNCならば、常に同期型である。 ONEWAYならば、常にOnewayである。- 戻り値:
- RPCのためのstub
-
getStub
リモートピア上の、clz型のインターフェースを実装し、 targetIdを持つオブジェクトのメソッドを呼び出すためのstubを返す。- 型パラメータ:
S- A type of RPCIf- パラメータ:
clz- RPC呼び出しの対象となるオブジェクトが実装しているインターフェースtargetId- RPC呼び出しの対象となるオブジェクトのIdremotePeer- リモートピアを示すEndpointrpcMode- Onewayかどうかを指定する。 AUTOならば、Annotationにより決定する。 SYNCならば、常に同期型である。 ONEWAYならば、常にOnewayである。- 戻り値:
- RPCのためのstub
-
getStub
リモートピア上の、clz型のインターフェースを持ち、 targetIdを持つオブジェクトのメソッドを呼び出すためのstubを返す。- 型パラメータ:
S- A type of RPCIf- パラメータ:
clz- RPC呼び出しの対象となるオブジェクトの型targetId- RPC呼び出しの対象となるオブジェクトのIdremotePeer- リモートピアを示すEndpointtimeout- timeout値(msec)- 戻り値:
- RPCのためのstub
-
getStub
リモートピア上の、clz型のインターフェースを持ち、 targetIdを持つオブジェクトのメソッドを呼び出すためのstubを返す。- 型パラメータ:
S- A type of RPCIf- パラメータ:
clz- RPC呼び出しの対象となるオブジェクトの型targetId- RPC呼び出しの対象となるオブジェクトのIdremotePeer- リモートピアを示すEndpoint- 戻り値:
- RPCのためのstub
-
getStub
リモートピア上の、clz型のインターフェースを実装し、 cidで指定されるオブジェクトのメソッドを呼び出すためのstubを返す。- 型パラメータ:
S- A type of RPCIf- パラメータ:
clz- RPC呼び出しの対象となるオブジェクトが実装しているインターフェースcid- RPC呼び出しの対象となるオブジェクトのIdtimeout- timeout値(msec)rpcMode- Onewayかどうかを指定する。 AUTOならば、Annotationにより決定する。 SYNCならば、常に同期型である。 ONEWAYならば、常にOnewayである。- 戻り値:
- RPCのためのstub
-
getStub
リモートピア上の、clz型のインターフェースを実装し、 cidで指定されるオブジェクトのメソッドを呼び出すためのstubを返す。- 型パラメータ:
S- A type of RPCIf- パラメータ:
clz- RPC呼び出しの対象となるオブジェクトが実装しているインターフェースcid- RPC呼び出しの対象となるオブジェクトのIdrpcMode- Onewayかどうかを指定する。 AUTOならば、Annotationにより決定する。 SYNCならば、常に同期型である。 ONEWAYならば、常にOnewayである。- 戻り値:
- RPCのためのstub
-
getStub
リモートピア上の、clz型のインターフェースを持ち、 cidで指定される オブジェクトのメソッドを呼び出すためのstubを返す。- 型パラメータ:
S- A type of RPCIf- パラメータ:
clz- RPC呼び出しの対象となるオブジェクトの型cid- the id of the callee.timeout- timeout値(msec)- 戻り値:
- RPCのためのstub
-
getStub
リモートピア上の、clz型のインターフェースをを持ち、 cidで指定される オブジェクトのメソッドを呼び出すためのstubを返す。- 型パラメータ:
S- A type of RPCIf- パラメータ:
clz- RPC呼び出しの対象となるオブジェクトの型cid- the id of the callee.- 戻り値:
- RPCのためのstub
-
rcall
public Object rcall(ObjectId targetId, E remotePeer, int timeout, RPCMode rpcMode, String method, Object... args) throws ThrowabletargetIdを持つオブジェクトのメソッドを動的に呼び出す。- パラメータ:
targetId- RPC呼び出しの対象となるオブジェクトのIdremotePeer- リモートピアを示すEndpointtimeout- timeout値(msec)rpcMode- Onewayかどうかを指定する。 AUTOならば、Annotationにより決定する。 SYNCならば、常に同期型である。 ONEWAYならば、常にOnewayである。method- the name of the method.args- the arguments for the method.- 戻り値:
- RPCのためのstub
- 例外:
Throwable- exceptions occurred while RPC.
-
rcall
public Object rcall(ObjectId targetId, E remotePeer, RPCMode rpcMode, String method, Object... args) throws Throwableリモートピア上の、clz型のインターフェースを実装し、 targetIdを持つオブジェクトのメソッドを動的に呼び出す。- パラメータ:
targetId- RPC呼び出しの対象となるオブジェクトのIdremotePeer- リモートピアを示すEndpointrpcMode- Onewayかどうかを指定する。 AUTOならば、Annotationにより決定する。 SYNCならば、常に同期型である。 ONEWAYならば、常にOnewayである。method- the name of the method.args- the arguments for the method.- 戻り値:
- RPCのためのstub
- 例外:
Throwable- exceptions occurred while RPC.
-
rcall
public Object rcall(ObjectId targetId, E remotePeer, int timeout, String method, Object... args) throws Throwableリモートピア上の、clz型のインターフェースを実装し、 targetIdを持つオブジェクトのメソッドを動的に呼び出す。- パラメータ:
targetId- RPC呼び出しの対象となるオブジェクトのIdremotePeer- リモートピアを示すEndpointtimeout- timeout値(msec)method- the name of the method.args- the arguments for the method.- 戻り値:
- RPCのためのstub
- 例外:
Throwable- exceptions occurred while RPC.
-
rcall
public Object rcall(ObjectId targetId, E remotePeer, String method, Object... args) throws Throwableリモートピア上の、clz型のインターフェースを実装し、 targetIdを持つオブジェクトのメソッドを動的に呼び出す。- パラメータ:
targetId- RPC呼び出しの対象となるオブジェクトのIdremotePeer- リモートピアを示すEndpointmethod- the name of the method.args- the arguments for the method.- 戻り値:
- RPCのためのstub
- 例外:
Throwable- exceptions occurred while RPC.
-
rcall
public Object rcall(CalleeId cid, int timeout, RPCMode rpcMode, String method, Object... args) throws Throwablecidで指定されるオブジェクトのメソッドを動的に呼び出す。- パラメータ:
cid- the id of the callee.timeout- timeout値(msec)rpcMode- Onewayかどうかを指定する。 AUTOならば、Annotationにより決定する。 SYNCならば、常に同期型である。 ONEWAYならば、常にOnewayである。method- the name of the method.args- the arguments for the method.- 戻り値:
- RPCのためのstub
- 例外:
Throwable- exceptions occurred while RPC.
-
rcall
cidで指定されるオブジェクトのメソッドを動的に呼び出す。- パラメータ:
cid- the id of the callee.rpcMode- Onewayかどうかを指定する。 AUTOならば、Annotationにより決定する。 SYNCならば、常に同期型である。 ONEWAYならば、常にOnewayである。method- the name of the method.args- the arguments for the method.- 戻り値:
- RPCのためのstub
- 例外:
Throwable- exceptions occurred while RPC.
-
rcall
リモートピア上の、clz型のインターフェースを実装し、 cidで指定されるオブジェクトのメソッドを動的に呼び出す。- パラメータ:
cid- the id of the callee.timeout- timeout値(msec)method- the name of the method.args- the arguments for the method.- 戻り値:
- RPCのためのstub
- 例外:
Throwable- exceptions occurred while RPC.
-
rcall
Call a remote method on the object specified by cid.- パラメータ:
cid- the id of the callee.method- the name of the method.args- the arguments for the method.- 戻り値:
- a stub for RPC
- 例外:
Throwable- exceptions occurred while RPC.
-
changeRPCTimeout
-
newMethodCall
protected RPCInvoker.MethodCall newMethodCall(ObjectId target, E remotePeer, boolean oneway, String method, Object... args) -
sendOnewayInvoke
public void sendOnewayInvoke(ObjectId target, E remotePeer, String method, Object... args) throws RPCExceptionsend an oneway RPC invocation message.- パラメータ:
target- the target object ID.remotePeer- the endpoint of the remote peer.method- the name of the method.args- the arguments of the method.- 例外:
RPCException- an exception occurred while the RPC.
-
sendInvoke
public ReturnValue<?> sendInvoke(ObjectId target, E remotePeer, int timeout, String method, Object... args) throws RPCExceptionsend an oneway RPC invocation message.- パラメータ:
target- the target object ID.remotePeer- the endpoint of the remote peer.timeout- the timeout.method- the name of the method.args- the arguments of the method.- 戻り値:
- the return value object of the invocation.
- 例外:
RPCException- an exception occurred while the RPC.
-
invokeInReceive
protected Object invokeInReceive(boolean isOneway, RPCIf obj, RPCInvoker.MethodCall mc) throws NoSuchMethodException, InvocationTargetException -
receiveOneway
-
receiveSync
-