Package com.yahoo.jrt
Class Target
- java.lang.Object
-
- com.yahoo.jrt.Target
-
public abstract class Target extends Object
A Target represents a connection endpoint with RPC capabilities. Each such connection has a client and a server side. The client side is the one initiating the connection. RPC requests may be invoked across the connection from both the client and the server side.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
addWatcher(TargetWatcher watcher)
Add a watcher to this target.abstract void
close()
Close this target.Exception
getConnectionLostReason()
Obtain the low-level reason behind losing the connection for which this target is an endpoint.Object
getContext()
Obtain the application context associated with this target.abstract Optional<SecurityContext>
getSecurityContext()
abstract void
invokeAsync(Request req, double timeout, RequestWaiter waiter)
Invoke a request on this target and let the completion be signalled with a callback.abstract void
invokeSync(Request req, double timeout)
Invoke a request on this target and wait for it to return.abstract boolean
invokeVoid(Request req)
Invoke a request on this target, but ignore the return value(s).abstract boolean
isClient()
Check if this target represents the client side of a connection.abstract boolean
isServer()
Check if this target represents the server side of a connection.abstract boolean
isValid()
Check if this target is still valid for invocations.abstract boolean
removeWatcher(TargetWatcher watcher)
Remove a watcher from this target.void
setContext(Object context)
Set the application context associated with this target.
-
-
-
Method Detail
-
setContext
public void setContext(Object context)
Set the application context associated with this target.- Parameters:
context
- application context
-
getContext
public Object getContext()
Obtain the application context associated with this target.- Returns:
- application context
-
isValid
public abstract boolean isValid()
Check if this target is still valid for invocations.- Returns:
- true if this target is still valid
-
getConnectionLostReason
public Exception getConnectionLostReason()
Obtain the low-level reason behind losing the connection for which this target is an endpoint. If the target is still valid or if the target became invalid because it was closed, this method will return null. In other cases this method may or may not return an exception indicating why the connection was lost. Also, if an exception is returned, its nature may vary based on implementation details across platforms.- Returns:
- exception causing connection loss or null
-
getSecurityContext
public abstract Optional<SecurityContext> getSecurityContext()
- Returns:
- the security context associated with this target, or empty if no connection or is insecure.
-
isClient
public abstract boolean isClient()
Check if this target represents the client side of a connection.- Returns:
- true if this is a client-side target
-
isServer
public abstract boolean isServer()
Check if this target represents the server side of a connection.- Returns:
- true if this is a server-side target
-
invokeSync
public abstract void invokeSync(Request req, double timeout)
Invoke a request on this target and wait for it to return.- Parameters:
req
- the requesttimeout
- timeout in seconds
-
invokeAsync
public abstract void invokeAsync(Request req, double timeout, RequestWaiter waiter)
Invoke a request on this target and let the completion be signalled with a callback.- Parameters:
req
- the requesttimeout
- timeout in secondswaiter
- callback handler
-
invokeVoid
public abstract boolean invokeVoid(Request req)
Invoke a request on this target, but ignore the return value(s). The success or failure of the invocation is also ignored. However, the return value gives a little hint by indicating whether the invocation has been attempted at all.- Parameters:
req
- the request- Returns:
- false if the invocation was not attempted due to the target being invalid
-
addWatcher
public abstract boolean addWatcher(TargetWatcher watcher)
Add a watcher to this target. A watcher is notified if the target becomes invalid. If the target is already invalid when this method is invoked, no operation is performed and false is returned. Multiple adds of the same watcher has no additional effect.- Parameters:
watcher
- the watcher to be added- Returns:
- true if the add operation was performed
-
removeWatcher
public abstract boolean removeWatcher(TargetWatcher watcher)
Remove a watcher from this target. If the target is already invalid when this method is invoked, no operation is performed and false is returned. Multiple removes of the same watcher has no additional effect.- Parameters:
watcher
- the watcher to be removed- Returns:
- true if the remove operation was performed
- See Also:
addWatcher(com.yahoo.jrt.TargetWatcher)
-
close
public abstract void close()
Close this target. Note that the close operation is asynchronous. If you need to wait for the target to become invalid, use theTransport.sync
method.
-
-