com.alipay.remoting.rpc
Class RpcServer

java.lang.Object
  extended by com.alipay.remoting.RemotingServer
      extended by com.alipay.remoting.rpc.RpcServer

public class RpcServer
extends RemotingServer

Server for Rpc.


Field Summary
protected  RpcRemoting rpcRemoting
          rpc remoting
 
Fields inherited from class com.alipay.remoting.RemotingServer
port
 
Constructor Summary
RpcServer(int port)
          Construct a rpc server.
RpcServer(int port, boolean manageConnection)
          Construct a rpc server.
RpcServer(int port, boolean manageConnection, boolean syncStop)
          Construct a rpc server.
 
Method Summary
 void addConnectionEventProcessor(ConnectionEventType type, ConnectionEventProcessor processor)
          Add processor to process connection event.
protected  void doInit()
          Inject initialize logic here.
protected  boolean doStart()
          Inject start logic here.
protected  boolean doStart(String ip)
          Inject start logic here.
protected  void doStop()
          Notice: only GlobalSwitch.SERVER_MANAGE_CONNECTION_SWITCH switch on, will close all connections.
 RemotingAddressParser getAddressParser()
          Getter method for property addressParser.
 DefaultConnectionManager getConnectionManager()
          Getter method for property connectionManager.
protected  void initRpcRemoting(RpcRemoting rpcRemoting)
          init rpc remoting
 Object invokeSync(Connection conn, Object request, int timeoutMillis)
          Synchronous invocation using a Connection
Notice:
DO NOT modify the request object concurrently when this method is called.
 Object invokeSync(Connection conn, Object request, InvokeContext invokeContext, int timeoutMillis)
          Synchronous invocation with a InvokeContext, common api notice please see invokeSync(Connection, Object, int)
 Object invokeSync(String addr, Object request, int timeoutMillis)
          Synchronous invocation using a string address, address format example - 127.0.0.1:12200?
 Object invokeSync(String addr, Object request, InvokeContext invokeContext, int timeoutMillis)
          Synchronous invocation with a InvokeContext, common api notice please see invokeSync(String, Object, int)
 Object invokeSync(Url url, Object request, int timeoutMillis)
          Synchronous invocation using a parsed Url
Notice:
DO NOT modify the request object concurrently when this method is called.
 Object invokeSync(Url url, Object request, InvokeContext invokeContext, int timeoutMillis)
          Synchronous invocation with a InvokeContext, common api notice please see invokeSync(Url, Object, int)
 void invokeWithCallback(Connection conn, Object request, InvokeCallback invokeCallback, int timeoutMillis)
          Callback invocation using a Connection
You can specify an implementation of InvokeCallback to get the result.
 void invokeWithCallback(Connection conn, Object request, InvokeContext invokeContext, InvokeCallback invokeCallback, int timeoutMillis)
          Callback invocation with a InvokeContext, common api notice please see invokeWithCallback(Connection, Object, InvokeCallback, int)
 void invokeWithCallback(String addr, Object request, InvokeCallback invokeCallback, int timeoutMillis)
          Callback invocation using a string address, address format example - 127.0.0.1:12200?
 void invokeWithCallback(String addr, Object request, InvokeContext invokeContext, InvokeCallback invokeCallback, int timeoutMillis)
          Callback invocation with a InvokeContext, common api notice please see invokeWithCallback(String, Object, InvokeCallback, int)
 void invokeWithCallback(Url url, Object request, InvokeCallback invokeCallback, int timeoutMillis)
          Callback invocation using a parsed Url
You can specify an implementation of InvokeCallback to get the result.
 void invokeWithCallback(Url url, Object request, InvokeContext invokeContext, InvokeCallback invokeCallback, int timeoutMillis)
          Callback invocation with a InvokeContext, common api notice please see invokeWithCallback(Url, Object, InvokeCallback, int)
 RpcResponseFuture invokeWithFuture(Connection conn, Object request, int timeoutMillis)
          Future invocation using a Connection
You can get result use the returned RpcResponseFuture.
 RpcResponseFuture invokeWithFuture(Connection conn, Object request, InvokeContext invokeContext, int timeoutMillis)
          Future invocation with a InvokeContext, common api notice please see invokeWithFuture(Connection, Object, int)
 RpcResponseFuture invokeWithFuture(String addr, Object request, int timeoutMillis)
          Future invocation using a string address, address format example - 127.0.0.1:12200?
 RpcResponseFuture invokeWithFuture(String addr, Object request, InvokeContext invokeContext, int timeoutMillis)
          Future invocation with a InvokeContext, common api notice please see invokeWithFuture(String, Object, int)
 RpcResponseFuture invokeWithFuture(Url url, Object request, int timeoutMillis)
          Future invocation using a parsed Url
You can get result use the returned RpcResponseFuture.
 RpcResponseFuture invokeWithFuture(Url url, Object request, InvokeContext invokeContext, int timeoutMillis)
          Future invocation with a InvokeContext, common api notice please see invokeWithFuture(Url, Object, int)
 boolean isConnected(String remoteAddr)
          check whether a client address connected
 boolean isConnected(Url url)
          check whether a Url connected
 void oneway(Connection conn, Object request)
          One way invocation using a Connection
Notice:
DO NOT modify the request object concurrently when this method is called.
 void oneway(Connection conn, Object request, InvokeContext invokeContext)
          One way invocation with a InvokeContext, common api notice please see oneway(Connection, Object)
 void oneway(String addr, Object request)
          One way invocation using a string address, address format example - 127.0.0.1:12200?
 void oneway(String addr, Object request, InvokeContext invokeContext)
          One way invocation with a InvokeContext, common api notice please see oneway(String, Object)
 void oneway(Url url, Object request)
          One way invocation using a parsed Url
Notice:
DO NOT modify the request object concurrently when this method is called.
 void oneway(Url url, Object request, InvokeContext invokeContext)
          One way invocation with a InvokeContext, common api notice please see oneway(Url, Object)
 void registerDefaultExecutor(byte protocolCode, ExecutorService executor)
          Register default executor service for server.
 void registerProcessor(byte protocolCode, CommandCode cmd, RemotingProcessor<?> processor)
          Register processor for command with the command code.
 void registerUserProcessor(UserProcessor<?> processor)
          Register user processor.
 void setAddressParser(RemotingAddressParser addressParser)
          Setter method for property addressParser.
 
Methods inherited from class com.alipay.remoting.RemotingServer
getPort, init, start, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rpcRemoting

protected RpcRemoting rpcRemoting
rpc remoting

Constructor Detail

RpcServer

public RpcServer(int port)
Construct a rpc server.
Note:
You can only use invoke methods with params Connection, for example invokeSync(Connection, Object, int)
Otherwise UnsupportedOperationException will be thrown.

Parameters:
port -

RpcServer

public RpcServer(int port,
                 boolean manageConnection)
Construct a rpc server.

Parameters:
port -
manageConnection - true to enable connection management feature

RpcServer

public RpcServer(int port,
                 boolean manageConnection,
                 boolean syncStop)
Construct a rpc server.
You can construct a rpc server with synchronous or asynchronous stop strategy by .

Parameters:
port -
manageConnection -
syncStop - true to enable stop in synchronous way
Method Detail

doInit

protected void doInit()
Description copied from class: RemotingServer
Inject initialize logic here.

Specified by:
doInit in class RemotingServer

doStart

protected boolean doStart()
                   throws InterruptedException
Description copied from class: RemotingServer
Inject start logic here.

Specified by:
doStart in class RemotingServer
Throws:
InterruptedException
See Also:
RemotingServer.doStart()

doStart

protected boolean doStart(String ip)
                   throws InterruptedException
Description copied from class: RemotingServer
Inject start logic here.

Specified by:
doStart in class RemotingServer
Throws:
InterruptedException
See Also:
RemotingServer.doStart(String)

doStop

protected void doStop()
Notice: only GlobalSwitch.SERVER_MANAGE_CONNECTION_SWITCH switch on, will close all connections.

Specified by:
doStop in class RemotingServer
See Also:
RemotingServer.doStop()

initRpcRemoting

protected void initRpcRemoting(RpcRemoting rpcRemoting)
init rpc remoting

Parameters:
rpcRemoting -

registerProcessor

public void registerProcessor(byte protocolCode,
                              CommandCode cmd,
                              RemotingProcessor<?> processor)
Description copied from class: RemotingServer
Register processor for command with the command code.

Specified by:
registerProcessor in class RemotingServer
See Also:
RemotingServer.registerProcessor(byte, com.alipay.remoting.CommandCode, com.alipay.remoting.RemotingProcessor)

registerDefaultExecutor

public void registerDefaultExecutor(byte protocolCode,
                                    ExecutorService executor)
Description copied from class: RemotingServer
Register default executor service for server.

Specified by:
registerDefaultExecutor in class RemotingServer
See Also:
RemotingServer.registerDefaultExecutor(byte, ExecutorService)

addConnectionEventProcessor

public void addConnectionEventProcessor(ConnectionEventType type,
                                        ConnectionEventProcessor processor)
Add processor to process connection event.

Parameters:
type -
processor -

registerUserProcessor

public void registerUserProcessor(UserProcessor<?> processor)
Description copied from class: RemotingServer
Register user processor.

Specified by:
registerUserProcessor in class RemotingServer
See Also:
RemotingServer.registerUserProcessor(com.alipay.remoting.rpc.protocol.UserProcessor)

oneway

public void oneway(String addr,
                   Object request)
            throws RemotingException,
                   InterruptedException
One way invocation using a string address, address format example - 127.0.0.1:12200?key1=value1&key2=value2

Notice:

  1. DO NOT modify the request object concurrently when this method is called.
  2. When do invocation, use the string address to find a available client connection, if none then throw exception
  3. Unlike rpc client, address arguments takes no effect here, for rpc server will not create connection.

Parameters:
addr -
request -
Throws:
RemotingException
InterruptedException

oneway

public void oneway(String addr,
                   Object request,
                   InvokeContext invokeContext)
            throws RemotingException,
                   InterruptedException
One way invocation with a InvokeContext, common api notice please see oneway(String, Object)

Parameters:
addr -
request -
invokeContext -
Throws:
RemotingException
InterruptedException

oneway

public void oneway(Url url,
                   Object request)
            throws RemotingException,
                   InterruptedException
One way invocation using a parsed Url

Notice:

  1. DO NOT modify the request object concurrently when this method is called.
  2. When do invocation, use the parsed Url to find a available client connection, if none then throw exception

Parameters:
url -
request -
Throws:
RemotingException
InterruptedException

oneway

public void oneway(Url url,
                   Object request,
                   InvokeContext invokeContext)
            throws RemotingException,
                   InterruptedException
One way invocation with a InvokeContext, common api notice please see oneway(Url, Object)

Parameters:
url -
request -
invokeContext -
Throws:
RemotingException
InterruptedException

oneway

public void oneway(Connection conn,
                   Object request)
            throws RemotingException
One way invocation using a Connection

Notice:
DO NOT modify the request object concurrently when this method is called.

Parameters:
conn -
request -
Throws:
RemotingException

oneway

public void oneway(Connection conn,
                   Object request,
                   InvokeContext invokeContext)
            throws RemotingException
One way invocation with a InvokeContext, common api notice please see oneway(Connection, Object)

Parameters:
conn -
request -
invokeContext -
Throws:
RemotingException

invokeSync

public Object invokeSync(String addr,
                         Object request,
                         int timeoutMillis)
                  throws RemotingException,
                         InterruptedException
Synchronous invocation using a string address, address format example - 127.0.0.1:12200?key1=value1&key2=value2

Notice:

  1. DO NOT modify the request object concurrently when this method is called.
  2. When do invocation, use the string address to find a available client connection, if none then throw exception
  3. Unlike rpc client, address arguments takes no effect here, for rpc server will not create connection.

Parameters:
addr -
request -
timeoutMillis -
Returns:
Object
Throws:
RemotingException
InterruptedException

invokeSync

public Object invokeSync(String addr,
                         Object request,
                         InvokeContext invokeContext,
                         int timeoutMillis)
                  throws RemotingException,
                         InterruptedException
Synchronous invocation with a InvokeContext, common api notice please see invokeSync(String, Object, int)

Parameters:
addr -
request -
invokeContext -
timeoutMillis -
Returns:
Throws:
RemotingException
InterruptedException

invokeSync

public Object invokeSync(Url url,
                         Object request,
                         int timeoutMillis)
                  throws RemotingException,
                         InterruptedException
Synchronous invocation using a parsed Url

Notice:

  1. DO NOT modify the request object concurrently when this method is called.
  2. When do invocation, use the parsed Url to find a available client connection, if none then throw exception

Parameters:
url -
request -
timeoutMillis -
Returns:
Object
Throws:
RemotingException
InterruptedException

invokeSync

public Object invokeSync(Url url,
                         Object request,
                         InvokeContext invokeContext,
                         int timeoutMillis)
                  throws RemotingException,
                         InterruptedException
Synchronous invocation with a InvokeContext, common api notice please see invokeSync(Url, Object, int)

Parameters:
url -
request -
invokeContext -
timeoutMillis -
Returns:
Throws:
RemotingException
InterruptedException

invokeSync

public Object invokeSync(Connection conn,
                         Object request,
                         int timeoutMillis)
                  throws RemotingException,
                         InterruptedException
Synchronous invocation using a Connection

Notice:
DO NOT modify the request object concurrently when this method is called.

Parameters:
conn -
request -
timeoutMillis -
Returns:
Object
Throws:
RemotingException
InterruptedException

invokeSync

public Object invokeSync(Connection conn,
                         Object request,
                         InvokeContext invokeContext,
                         int timeoutMillis)
                  throws RemotingException,
                         InterruptedException
Synchronous invocation with a InvokeContext, common api notice please see invokeSync(Connection, Object, int)

Parameters:
conn -
request -
invokeContext -
timeoutMillis -
Returns:
Throws:
RemotingException
InterruptedException

invokeWithFuture

public RpcResponseFuture invokeWithFuture(String addr,
                                          Object request,
                                          int timeoutMillis)
                                   throws RemotingException,
                                          InterruptedException
Future invocation using a string address, address format example - 127.0.0.1:12200?key1=value1&key2=value2
You can get result use the returned RpcResponseFuture.

Notice:

  1. DO NOT modify the request object concurrently when this method is called.
  2. When do invocation, use the string address to find a available client connection, if none then throw exception
  3. Unlike rpc client, address arguments takes no effect here, for rpc server will not create connection.

Parameters:
addr -
request -
timeoutMillis -
Returns:
RpcResponseFuture
Throws:
RemotingException
InterruptedException

invokeWithFuture

public RpcResponseFuture invokeWithFuture(String addr,
                                          Object request,
                                          InvokeContext invokeContext,
                                          int timeoutMillis)
                                   throws RemotingException,
                                          InterruptedException
Future invocation with a InvokeContext, common api notice please see invokeWithFuture(String, Object, int)

Parameters:
addr -
request -
invokeContext -
timeoutMillis -
Returns:
Throws:
RemotingException
InterruptedException

invokeWithFuture

public RpcResponseFuture invokeWithFuture(Url url,
                                          Object request,
                                          int timeoutMillis)
                                   throws RemotingException,
                                          InterruptedException
Future invocation using a parsed Url
You can get result use the returned RpcResponseFuture.

Notice:

  1. DO NOT modify the request object concurrently when this method is called.
  2. When do invocation, use the parsed Url to find a available client connection, if none then throw exception

Parameters:
url -
request -
timeoutMillis -
Returns:
RpcResponseFuture
Throws:
RemotingException
InterruptedException

invokeWithFuture

public RpcResponseFuture invokeWithFuture(Url url,
                                          Object request,
                                          InvokeContext invokeContext,
                                          int timeoutMillis)
                                   throws RemotingException,
                                          InterruptedException
Future invocation with a InvokeContext, common api notice please see invokeWithFuture(Url, Object, int)

Parameters:
url -
request -
invokeContext -
timeoutMillis -
Returns:
Throws:
RemotingException
InterruptedException

invokeWithFuture

public RpcResponseFuture invokeWithFuture(Connection conn,
                                          Object request,
                                          int timeoutMillis)
                                   throws RemotingException
Future invocation using a Connection
You can get result use the returned RpcResponseFuture.

Notice:
DO NOT modify the request object concurrently when this method is called.

Parameters:
conn -
request -
timeoutMillis -
Returns:
Throws:
RemotingException

invokeWithFuture

public RpcResponseFuture invokeWithFuture(Connection conn,
                                          Object request,
                                          InvokeContext invokeContext,
                                          int timeoutMillis)
                                   throws RemotingException
Future invocation with a InvokeContext, common api notice please see invokeWithFuture(Connection, Object, int)

Parameters:
conn -
request -
invokeContext -
timeoutMillis -
Returns:
Throws:
RemotingException

invokeWithCallback

public void invokeWithCallback(String addr,
                               Object request,
                               InvokeCallback invokeCallback,
                               int timeoutMillis)
                        throws RemotingException,
                               InterruptedException
Callback invocation using a string address, address format example - 127.0.0.1:12200?key1=value1&key2=value2
You can specify an implementation of InvokeCallback to get the result.

Notice:

  1. DO NOT modify the request object concurrently when this method is called.
  2. When do invocation, use the string address to find a available client connection, if none then throw exception
  3. Unlike rpc client, address arguments takes no effect here, for rpc server will not create connection.

Parameters:
addr -
request -
invokeCallback -
timeoutMillis -
Throws:
RemotingException
InterruptedException

invokeWithCallback

public void invokeWithCallback(String addr,
                               Object request,
                               InvokeContext invokeContext,
                               InvokeCallback invokeCallback,
                               int timeoutMillis)
                        throws RemotingException,
                               InterruptedException
Callback invocation with a InvokeContext, common api notice please see invokeWithCallback(String, Object, InvokeCallback, int)

Parameters:
addr -
request -
invokeContext -
invokeCallback -
timeoutMillis -
Throws:
RemotingException
InterruptedException

invokeWithCallback

public void invokeWithCallback(Url url,
                               Object request,
                               InvokeCallback invokeCallback,
                               int timeoutMillis)
                        throws RemotingException,
                               InterruptedException
Callback invocation using a parsed Url
You can specify an implementation of InvokeCallback to get the result.

Notice:

  1. DO NOT modify the request object concurrently when this method is called.
  2. When do invocation, use the parsed Url to find a available client connection, if none then throw exception

Parameters:
url -
request -
invokeCallback -
timeoutMillis -
Throws:
RemotingException
InterruptedException

invokeWithCallback

public void invokeWithCallback(Url url,
                               Object request,
                               InvokeContext invokeContext,
                               InvokeCallback invokeCallback,
                               int timeoutMillis)
                        throws RemotingException,
                               InterruptedException
Callback invocation with a InvokeContext, common api notice please see invokeWithCallback(Url, Object, InvokeCallback, int)

Parameters:
url -
request -
invokeContext -
invokeCallback -
timeoutMillis -
Throws:
RemotingException
InterruptedException

invokeWithCallback

public void invokeWithCallback(Connection conn,
                               Object request,
                               InvokeCallback invokeCallback,
                               int timeoutMillis)
                        throws RemotingException
Callback invocation using a Connection
You can specify an implementation of InvokeCallback to get the result.

Notice:
DO NOT modify the request object concurrently when this method is called.

Parameters:
conn -
request -
invokeCallback -
timeoutMillis -
Throws:
RemotingException

invokeWithCallback

public void invokeWithCallback(Connection conn,
                               Object request,
                               InvokeContext invokeContext,
                               InvokeCallback invokeCallback,
                               int timeoutMillis)
                        throws RemotingException
Callback invocation with a InvokeContext, common api notice please see invokeWithCallback(Connection, Object, InvokeCallback, int)

Parameters:
conn -
request -
invokeCallback -
timeoutMillis -
Throws:
RemotingException

isConnected

public boolean isConnected(String remoteAddr)
check whether a client address connected

Parameters:
remoteAddr -
Returns:

isConnected

public boolean isConnected(Url url)
check whether a Url connected

Parameters:
url -
Returns:

getAddressParser

public RemotingAddressParser getAddressParser()
Getter method for property addressParser.

Returns:
property value of addressParser

setAddressParser

public void setAddressParser(RemotingAddressParser addressParser)
Setter method for property addressParser.

Parameters:
addressParser - value to be assigned to property addressParser

getConnectionManager

public DefaultConnectionManager getConnectionManager()
Getter method for property connectionManager.

Returns:
property value of connectionManager


Copyright © 2018. All rights reserved.