Skip to content

Package: ThriftClient

ThriftClient

Coverage

1: /*
2: * Copyright (c) 2012, 2017 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.glassfish.grizzly.thrift.client;
18:
19: import java.net.SocketAddress;
20:
21: import org.apache.thrift.TServiceClient;
22:
23: /**
24: * The thrift client's interface
25: * <p>
26: * By {@link #addServer} and {@link #removeServer}, servers can be added and
27: * removed dynamically in this thrift client. In other words, the managed server
28: * list can be changed in runtime by APIs. By {@link #execute}, user can execute
29: * custom service(For more information, please see
30: * {@link ThriftClientCallback}'s javadoc).
31: *
32: * @author Bongjae Chang
33: */
34: public interface ThriftClient<T extends TServiceClient> extends ThriftClientLifecycle {
35:
36: <U> U execute(final ThriftClientCallback<T, U> callback) throws Exception;
37:
38: /**
39: * Return the name of the thrift client.
40: *
41: * @return the name of the thrift client.
42: */
43: String getName();
44:
45: /**
46: * Add a specific server in this thrift client
47: *
48: * @param serverAddress a specific server's {@link java.net.SocketAddress} to be
49: * added
50: * @return true if the given {@code serverAddress} is added successfully
51: */
52: boolean addServer(final SocketAddress serverAddress);
53:
54: /**
55: * Remove the given server in this thrift client
56: *
57: * @param serverAddress the specific server's {@link java.net.SocketAddress} to
58: * be removed in this thrift client
59: */
60: void removeServer(final SocketAddress serverAddress);
61:
62: /**
63: * Check if this thrift client contains the given server
64: *
65: * @param serverAddress the specific server's {@link java.net.SocketAddress} to
66: * be checked
67: * @return true if this thrift client already contains the given
68: * {@code serverAddress}
69: */
70: boolean isInServerList(final SocketAddress serverAddress);
71: }