com.alipay.remoting.InvokeCallback Java Examples

The following examples show how to use com.alipay.remoting.InvokeCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RpcInvokeCallbackListener.java    From sofa-bolt with Apache License 2.0 6 votes vote down vote up
/**
 * @see com.alipay.remoting.InvokeCallbackListener#onResponse(com.alipay.remoting.InvokeFuture)
 */
@Override
public void onResponse(InvokeFuture future) {
    InvokeCallback callback = future.getInvokeCallback();
    if (callback != null) {
        CallbackTask task = new CallbackTask(this.getRemoteAddress(), future);
        if (callback.getExecutor() != null) {
            // There is no need to switch classloader, because executor is provided by user.
            try {
                callback.getExecutor().execute(task);
            } catch (RejectedExecutionException e) {
                logger.warn("Callback thread pool busy.");
            }
        } else {
            task.run();
        }
    }
}
 
Example #2
Source File: RpcClient.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public void invokeWithCallback(final Connection conn, final Object request,
                               final InvokeContext invokeContext,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException {
    this.rpcRemoting.invokeWithCallback(conn, request, invokeContext, invokeCallback,
        timeoutMillis);
}
 
Example #3
Source File: RpcServerRemoting.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.alipay.remoting.rpc.RpcRemoting#invokeWithCallback(com.alipay.remoting.Url, java.lang.Object, InvokeContext, com.alipay.remoting.InvokeCallback, int)
 */
@Override
public void invokeWithCallback(Url url, Object request, InvokeContext invokeContext,
                               InvokeCallback invokeCallback, int timeoutMillis)
                                                                                throws RemotingException {
    Connection conn = this.connectionManager.get(url.getUniqueKey());
    if (null == conn) {
        throw new RemotingException("Client address [" + url.getUniqueKey()
                                    + "] not connected yet!");
    }
    this.connectionManager.check(conn);
    this.invokeWithCallback(conn, request, invokeContext, invokeCallback, timeoutMillis);
}
 
Example #4
Source File: RpcClient.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public void invokeWithCallback(final Url url, final Object request,
                               final InvokeContext invokeContext,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException,
                                                                                            InterruptedException {
    this.rpcRemoting.invokeWithCallback(url, request, invokeContext, invokeCallback,
        timeoutMillis);
}
 
Example #5
Source File: RpcClient.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public void invokeWithCallback(final Url url, final Object request,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException,
                                                                                            InterruptedException {
    this.rpcRemoting.invokeWithCallback(url, request, null, invokeCallback, timeoutMillis);
}
 
Example #6
Source File: RpcRemoting.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.alipay.remoting.BaseRemoting#createInvokeFuture(Connection, RemotingCommand, InvokeContext, InvokeCallback)
 */
@Override
protected InvokeFuture createInvokeFuture(Connection conn, RemotingCommand request,
                                          InvokeContext invokeContext,
                                          InvokeCallback invokeCallback) {
    return new DefaultInvokeFuture(request.getId(), new RpcInvokeCallbackListener(
        RemotingUtil.parseRemoteAddress(conn.getChannel())), invokeCallback, request
        .getProtocolCode().getFirstByte(), this.getCommandFactory(), invokeContext);
}
 
Example #7
Source File: RpcClient.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public void invokeWithCallback(final String address, final Object request,
                               final InvokeContext invokeContext,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException,
                                                                                            InterruptedException {
    this.rpcRemoting.invokeWithCallback(address, request, invokeContext, invokeCallback,
        timeoutMillis);
}
 
Example #8
Source File: RpcClient.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public void invokeWithCallback(final String address, final Object request,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException,
                                                                                            InterruptedException {
    this.rpcRemoting.invokeWithCallback(address, request, null, invokeCallback, timeoutMillis);
}
 
Example #9
Source File: DefaultInvokeFuture.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param invokeId invoke id
 * @param callbackListener callback listener
 * @param callback callback
 * @param protocol protocol code
 * @param commandFactory command factory
 */
public DefaultInvokeFuture(int invokeId, InvokeCallbackListener callbackListener,
                           InvokeCallback callback, byte protocol, CommandFactory commandFactory) {
    this.invokeId = invokeId;
    this.callbackListener = callbackListener;
    this.callback = callback;
    this.classLoader = Thread.currentThread().getContextClassLoader();
    this.protocol = protocol;
    this.commandFactory = commandFactory;
}
 
Example #10
Source File: RpcClientRemoting.java    From sofa-bolt with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.alipay.remoting.rpc.RpcRemoting#invokeWithCallback(com.alipay.remoting.Url, java.lang.Object, InvokeContext, com.alipay.remoting.InvokeCallback, int)
 */
@Override
public void invokeWithCallback(Url url, Object request, InvokeContext invokeContext,
                               InvokeCallback invokeCallback, int timeoutMillis)
                                                                                throws RemotingException,
                                                                                InterruptedException {
    final Connection conn = getConnectionAndInitInvokeContext(url, invokeContext);
    this.connectionManager.check(conn);
    this.invokeWithCallback(conn, request, invokeContext, invokeCallback, timeoutMillis);
}
 
Example #11
Source File: DefaultInvokeFuture.java    From sofa-bolt with Apache License 2.0 4 votes vote down vote up
/** 
 * @see com.alipay.remoting.InvokeFuture#getInvokeCallback()
 */
@Override
public InvokeCallback getInvokeCallback() {
    return this.callback;
}
 
Example #12
Source File: RpcClient.java    From sofa-bolt with Apache License 2.0 4 votes vote down vote up
@Override
public void invokeWithCallback(final Connection conn, final Object request,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException {
    this.rpcRemoting.invokeWithCallback(conn, request, null, invokeCallback, timeoutMillis);
}
 
Example #13
Source File: RpcServer.java    From sofa-bolt with Apache License 2.0 3 votes vote down vote up
/**
 * Callback invocation with a {@link InvokeContext}, common api notice please see {@link #invokeWithCallback(Url, Object, InvokeCallback, int)}
 *
 * @param url
 * @param request
 * @param invokeContext
 * @param invokeCallback
 * @param timeoutMillis
 * @throws RemotingException
 * @throws InterruptedException
 */
public void invokeWithCallback(final Url url, final Object request,
                               final InvokeContext invokeContext,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException,
                                                                                            InterruptedException {
    check();
    this.rpcRemoting.invokeWithCallback(url, request, invokeContext, invokeCallback,
        timeoutMillis);
}
 
Example #14
Source File: RpcServer.java    From sofa-bolt with Apache License 2.0 3 votes vote down vote up
/**
 * Callback invocation with a {@link InvokeContext}, common api notice please see {@link #invokeWithCallback(Connection, Object, InvokeCallback, int)}
 *
 * @param conn
 * @param request
 * @param invokeCallback
 * @param timeoutMillis
 * @throws RemotingException
 */
public void invokeWithCallback(final Connection conn, final Object request,
                               final InvokeContext invokeContext,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException {
    this.rpcRemoting.invokeWithCallback(conn, request, invokeContext, invokeCallback,
        timeoutMillis);
}
 
Example #15
Source File: RpcServer.java    From sofa-bolt with Apache License 2.0 3 votes vote down vote up
/**
 * Callback invocation using a parsed {@link Url} <br>
 * You can specify an implementation of {@link InvokeCallback} to get the result.
 * <p>
 * Notice:<br>
 *   <ol>
 *   <li><b>DO NOT modify the request object concurrently when this method is called.</b></li>
 *   <li>When do invocation, use the parsed {@link Url} to find a available client connection, if none then throw exception</li>
 *   </ol>
 *
 * @param url
 * @param request
 * @param invokeCallback
 * @param timeoutMillis
 * @throws RemotingException
 * @throws InterruptedException
 */
public void invokeWithCallback(final Url url, final Object request,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException,
                                                                                            InterruptedException {
    check();
    this.rpcRemoting.invokeWithCallback(url, request, null, invokeCallback, timeoutMillis);
}
 
Example #16
Source File: RpcServer.java    From sofa-bolt with Apache License 2.0 3 votes vote down vote up
/**
 * Callback invocation with a {@link InvokeContext}, common api notice please see {@link #invokeWithCallback(String, Object, InvokeCallback, int)}
 *
 * @param addr
 * @param request
 * @param invokeContext
 * @param invokeCallback
 * @param timeoutMillis
 * @throws RemotingException
 * @throws InterruptedException
 */
public void invokeWithCallback(final String addr, final Object request,
                               final InvokeContext invokeContext,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException,
                                                                                            InterruptedException {
    check();
    this.rpcRemoting.invokeWithCallback(addr, request, invokeContext, invokeCallback,
        timeoutMillis);
}
 
Example #17
Source File: RpcServer.java    From sofa-bolt with Apache License 2.0 3 votes vote down vote up
/**
 * Callback invocation using a string address, address format example - 127.0.0.1:12200?key1=value1&key2=value2 <br>
 * You can specify an implementation of {@link InvokeCallback} to get the result.
 * <p>
 * Notice:<br>
 *   <ol>
 *   <li><b>DO NOT modify the request object concurrently when this method is called.</b></li>
 *   <li>When do invocation, use the string address to find a available client connection, if none then throw exception</li>
 *   <li>Unlike rpc client, address arguments takes no effect here, for rpc server will not create connection.</li>
 *   </ol>
 *
 * @param addr
 * @param request
 * @param invokeCallback
 * @param timeoutMillis
 * @throws RemotingException
 * @throws InterruptedException
 */
public void invokeWithCallback(final String addr, final Object request,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException,
                                                                                            InterruptedException {
    check();
    this.rpcRemoting.invokeWithCallback(addr, request, null, invokeCallback, timeoutMillis);
}
 
Example #18
Source File: RpcRemoting.java    From sofa-bolt with Apache License 2.0 3 votes vote down vote up
/**
 * Rpc invocation with callback.<br>
 * Notice! DO NOT modify the request object concurrently when this method is called.
 * 
 * @param conn
 * @param request
 * @param invokeContext 
 * @param invokeCallback
 * @param timeoutMillis
 * @throws RemotingException
 */
public void invokeWithCallback(final Connection conn, final Object request,
                               final InvokeContext invokeContext,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException {
    RemotingCommand requestCommand = toRemotingCommand(request, conn, invokeContext,
        timeoutMillis);
    preProcessInvokeContext(invokeContext, requestCommand, conn);
    super.invokeWithCallback(conn, requestCommand, invokeCallback, timeoutMillis);
}
 
Example #19
Source File: RpcRemoting.java    From sofa-bolt with Apache License 2.0 3 votes vote down vote up
/**
 * Rpc invocation with callback.<br>
 * Notice! DO NOT modify the request object concurrently when this method is called.
 * 
 * @param addr
 * @param request
 * @param invokeContext 
 * @param invokeCallback
 * @param timeoutMillis
 * @throws RemotingException
 * @throws InterruptedException
 */
public void invokeWithCallback(String addr, Object request, final InvokeContext invokeContext,
                               InvokeCallback invokeCallback, int timeoutMillis)
                                                                                throws RemotingException,
                                                                                InterruptedException {
    Url url = this.addressParser.parse(addr);
    this.invokeWithCallback(url, request, invokeContext, invokeCallback, timeoutMillis);
}
 
Example #20
Source File: DefaultInvokeFuture.java    From sofa-bolt with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor.
 *
 * @param invokeId invoke id
 * @param callbackListener callback listener
 * @param callback callback
 * @param protocol protocol
 * @param commandFactory command factory
 * @param invokeContext invoke context
 */
public DefaultInvokeFuture(int invokeId, InvokeCallbackListener callbackListener,
                           InvokeCallback callback, byte protocol,
                           CommandFactory commandFactory, InvokeContext invokeContext) {
    this(invokeId, callbackListener, callback, protocol, commandFactory);
    this.invokeContext = invokeContext;
}
 
Example #21
Source File: RpcServer.java    From sofa-bolt with Apache License 2.0 2 votes vote down vote up
/**
 * Callback invocation using a {@link Connection} <br>
 * You can specify an implementation of {@link InvokeCallback} to get the result.
 * <p>
 * Notice:<br>
 *   <b>DO NOT modify the request object concurrently when this method is called.</b>
 *
 * @param conn
 * @param request
 * @param invokeCallback
 * @param timeoutMillis
 * @throws RemotingException
 */
public void invokeWithCallback(final Connection conn, final Object request,
                               final InvokeCallback invokeCallback, final int timeoutMillis)
                                                                                            throws RemotingException {
    this.rpcRemoting.invokeWithCallback(conn, request, null, invokeCallback, timeoutMillis);
}
 
Example #22
Source File: RpcRemoting.java    From sofa-bolt with Apache License 2.0 2 votes vote down vote up
/**
 * Rpc invocation with callback.<br>
 * Notice! DO NOT modify the request object concurrently when this method is called.
 * 
 * @param url
 * @param request
 * @param invokeContext
 * @param invokeCallback
 * @param timeoutMillis
 * @throws RemotingException
 * @throws InterruptedException
 */
public abstract void invokeWithCallback(final Url url, final Object request,
                                        final InvokeContext invokeContext,
                                        final InvokeCallback invokeCallback,
                                        final int timeoutMillis) throws RemotingException,
                                                                InterruptedException;