/controller-client/src/main/java/org/jboss/as/controller/client/ModelControllerClient.java

https://bitbucket.org/cprenzberg/wildfly · Java · 342 lines · 73 code · 32 blank · 237 comment · 0 complexity · 344050540d8666ba61a9dba5762a2752 MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.controller.client;
  23. import java.io.Closeable;
  24. import java.io.IOException;
  25. import java.net.InetAddress;
  26. import java.net.UnknownHostException;
  27. import java.util.Map;
  28. import javax.net.ssl.SSLContext;
  29. import javax.security.auth.callback.CallbackHandler;
  30. import org.jboss.as.controller.client.impl.ClientConfigurationImpl;
  31. import org.jboss.as.controller.client.impl.RemotingModelControllerClient;
  32. import org.jboss.dmr.ModelNode;
  33. import org.jboss.threads.AsyncFuture;
  34. /**
  35. * A client for an application server management model controller.
  36. *
  37. * @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
  38. * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
  39. * @author Brian Stansberry (c) 2011 Red Hat Inc.
  40. */
  41. public interface ModelControllerClient extends Closeable {
  42. /**
  43. * Execute an operation synchronously.
  44. *
  45. * @param operation the operation to execute
  46. * @return the result of the operation
  47. * @throws IOException if an I/O error occurs while executing the operation
  48. */
  49. ModelNode execute(ModelNode operation) throws IOException;
  50. /**
  51. * Execute an operation synchronously.
  52. *
  53. * Note that associated input-streams have to be closed by the caller, after the
  54. * operation completed {@link OperationAttachments#isAutoCloseStreams()}.
  55. *
  56. * @param operation the operation to execute
  57. * @return the result of the operation
  58. * @throws IOException if an I/O error occurs while executing the operation
  59. */
  60. ModelNode execute(Operation operation) throws IOException;
  61. /**
  62. * Execute an operation synchronously, optionally receiving progress reports.
  63. *
  64. * @param operation the operation to execute
  65. * @param messageHandler the message handler to use for operation progress reporting, or {@code null} for none
  66. * @return the result of the operation
  67. * @throws IOException if an I/O error occurs while executing the operation
  68. */
  69. ModelNode execute(ModelNode operation, OperationMessageHandler messageHandler) throws IOException;
  70. /**
  71. * Execute an operation synchronously, optionally receiving progress reports.
  72. *
  73. * Note that associated input-streams have to be closed by the caller, after the
  74. * operation completed {@link OperationAttachments#isAutoCloseStreams()}.
  75. *
  76. * @param operation the operation to execute
  77. * @param messageHandler the message handler to use for operation progress reporting, or {@code null} for none
  78. * @return the result of the operation
  79. * @throws IOException if an I/O error occurs while executing the operation
  80. */
  81. ModelNode execute(Operation operation, OperationMessageHandler messageHandler) throws IOException;
  82. /**
  83. * Execute an operation.
  84. *
  85. * @param operation the operation to execute
  86. * @param messageHandler the message handler to use for operation progress reporting, or {@code null} for none
  87. * @return the future result of the operation
  88. */
  89. AsyncFuture<ModelNode> executeAsync(ModelNode operation, OperationMessageHandler messageHandler);
  90. /**
  91. * Execute an operation.
  92. *
  93. * Note that associated input-streams have to be closed by the caller, after the
  94. * operation completed {@link OperationAttachments#isAutoCloseStreams()}.
  95. *
  96. * @param operation the operation to execute
  97. * @param messageHandler the message handler to use for operation progress reporting, or {@code null} for none
  98. * @return the future result of the operation
  99. */
  100. AsyncFuture<ModelNode> executeAsync(Operation operation, OperationMessageHandler messageHandler);
  101. class Factory {
  102. /**
  103. * Create a client instance for a remote address and port.
  104. *
  105. * @param address the address of the remote host
  106. * @param port the port
  107. * @return A model controller client
  108. */
  109. public static ModelControllerClient create(final InetAddress address, final int port) {
  110. return create(ClientConfigurationImpl.create(address, port));
  111. }
  112. /**
  113. * Create a client instance for a remote address and port.
  114. *
  115. * @param protocol The prototcol to use. If this is http-remoting or https-remoting http upgrade will be used rather than the native remote protocol
  116. * @param address the address of the remote host
  117. * @param port the port
  118. * @return A model controller client
  119. */
  120. public static ModelControllerClient create(final String protocol, final InetAddress address, final int port) {
  121. return create(ClientConfigurationImpl.create(protocol, address, port));
  122. }
  123. /**
  124. * Create a client instance for a remote address and port.
  125. *
  126. * @param address the address of the remote host
  127. * @param port the port
  128. * @param handler CallbackHandler to obtain authentication information for the call.
  129. * @return A model controller client
  130. */
  131. public static ModelControllerClient create(final InetAddress address, final int port, final CallbackHandler handler) {
  132. return create(ClientConfigurationImpl.create(address, port, handler));
  133. }
  134. /**
  135. * Create a client instance for a remote address and port.
  136. *
  137. * @param protocol The prototcol to use. If this is http-remoting or https-remoting http upgrade will be used rather than the native remote protocol
  138. * @param address the address of the remote host
  139. * @param port the port
  140. * @param handler CallbackHandler to obtain authentication information for the call.
  141. * @return A model controller client
  142. */
  143. public static ModelControllerClient create(final String protocol, final InetAddress address, final int port, final CallbackHandler handler) {
  144. return create(ClientConfigurationImpl.create(protocol, address, port, handler));
  145. }
  146. /**
  147. * Create a client instance for a remote address and port.
  148. *
  149. * @param address the address of the remote host
  150. * @param port the port
  151. * @param handler CallbackHandler to obtain authentication information for the call.
  152. * @param saslOptions Additional options to be passed to the SASL mechanism.
  153. * @return A model controller client
  154. */
  155. public static ModelControllerClient create(final InetAddress address, final int port, final CallbackHandler handler, final Map<String, String> saslOptions) {
  156. return create(ClientConfigurationImpl.create(address, port, handler, saslOptions));
  157. }
  158. /**
  159. * Create a client instance for a remote address and port.
  160. *
  161. * @param protocol The prototcol to use. If this is http-remoting or https-remoting http upgrade will be used
  162. * @param address the address of the remote host
  163. * @param port the port
  164. * @param handler CallbackHandler to obtain authentication information for the call.
  165. * @param saslOptions Additional options to be passed to the SASL mechanism.
  166. * @return A model controller client
  167. */
  168. public static ModelControllerClient create(final String protocol, final InetAddress address, final int port, final CallbackHandler handler, final Map<String, String> saslOptions) {
  169. return create(ClientConfigurationImpl.create(protocol, address, port, handler, saslOptions));
  170. }
  171. /**
  172. * Create a client instance for a remote address and port.
  173. *
  174. * @param hostName the remote host
  175. * @param port the port
  176. * @return A model controller client
  177. * @throws UnknownHostException if the host cannot be found
  178. */
  179. public static ModelControllerClient create(final String hostName, final int port) throws UnknownHostException {
  180. return create(ClientConfigurationImpl.create(hostName, port));
  181. }
  182. /**
  183. * Create a client instance for a remote address and port.
  184. *
  185. * @param protocol The prototcol to use. If this is http-remoting or https-remoting http upgrade will be used rather than the native remote protocol
  186. * @param hostName the remote host
  187. * @param port the port
  188. * @return A model controller client
  189. * @throws UnknownHostException if the host cannot be found
  190. */
  191. public static ModelControllerClient create(final String protocol, final String hostName, final int port) throws UnknownHostException {
  192. return create(ClientConfigurationImpl.create(protocol, hostName, port));
  193. }
  194. /**
  195. * Create a client instance for a remote address and port and CallbackHandler.
  196. *
  197. * @param hostName the remote host
  198. * @param port the port
  199. * @param handler CallbackHandler to obtain authentication information for the call.
  200. * @return A model controller client
  201. * @throws UnknownHostException if the host cannot be found
  202. */
  203. public static ModelControllerClient create(final String hostName, final int port, final CallbackHandler handler) throws UnknownHostException {
  204. return create(ClientConfigurationImpl.create(hostName, port, handler));
  205. }
  206. /**
  207. * Create a client instance for a remote address and port and CallbackHandler.
  208. *
  209. * @param protocol The prototcol to use. If this is http-remoting or https-remoting http upgrade will be used rather than the native remote protocol
  210. * @param hostName the remote host
  211. * @param port the port
  212. * @param handler CallbackHandler to obtain authentication information for the call.
  213. * @return A model controller client
  214. * @throws UnknownHostException if the host cannot be found
  215. */
  216. public static ModelControllerClient create(final String protocol, final String hostName, final int port, final CallbackHandler handler) throws UnknownHostException {
  217. return create(ClientConfigurationImpl.create(protocol, hostName, port, handler));
  218. }
  219. /**
  220. * Create a client instance for a remote address and port and CallbackHandler.
  221. *
  222. * @param hostName the remote host
  223. * @param port the port
  224. * @param handler CallbackHandler to obtain authentication information for the call.
  225. * @param sslContext a pre-initialised SSLContext
  226. * @return A model controller client
  227. * @throws UnknownHostException if the host cannot be found
  228. */
  229. public static ModelControllerClient create(final String hostName, final int port, final CallbackHandler handler, final SSLContext sslContext) throws UnknownHostException {
  230. return create(ClientConfigurationImpl.create(hostName, port, handler, sslContext));
  231. }
  232. /**
  233. * Create a client instance for a remote address and port and CallbackHandler.
  234. *
  235. * @param protocol The prototcol to use. If this is http-remoting or https-remoting http upgrade will be used rather than the native remote protocol
  236. * @param hostName the remote host
  237. * @param port the port
  238. * @param handler CallbackHandler to obtain authentication information for the call.
  239. * @param sslContext a pre-initialised SSLContext
  240. * @return A model controller client
  241. * @throws UnknownHostException if the host cannot be found
  242. */
  243. public static ModelControllerClient create(final String protocol, final String hostName, final int port, final CallbackHandler handler, final SSLContext sslContext) throws UnknownHostException {
  244. return create(ClientConfigurationImpl.create(protocol, hostName, port, handler, sslContext));
  245. }
  246. /**
  247. * Create a client instance for a remote address and port and CallbackHandler.
  248. *
  249. * @param hostName the remote host
  250. * @param port the port
  251. * @param handler CallbackHandler to obtain authentication information for the call.
  252. * @param sslContext a pre-initialised SSLContext
  253. * @return A model controller client
  254. * @throws UnknownHostException if the host cannot be found
  255. */
  256. public static ModelControllerClient create(final String hostName, final int port, final CallbackHandler handler, final SSLContext sslContext, final int connectionTimeout) throws UnknownHostException {
  257. return create(ClientConfigurationImpl.create(hostName, port, handler, sslContext, connectionTimeout));
  258. }
  259. /**
  260. * Create a client instance for a remote address and port and CallbackHandler.
  261. *
  262. * @param protocol The prototcol to use. If this is http-remoting or https-remoting http upgrade will be used rather than the native remote protocol
  263. * @param hostName the remote host
  264. * @param port the port
  265. * @param handler CallbackHandler to obtain authentication information for the call.
  266. * @param sslContext a pre-initialised SSLContext
  267. * @return A model controller client
  268. * @throws UnknownHostException if the host cannot be found
  269. */
  270. public static ModelControllerClient create(final String protocol, final String hostName, final int port, final CallbackHandler handler, final SSLContext sslContext, final int connectionTimeout) throws UnknownHostException {
  271. return create(ClientConfigurationImpl.create(protocol, hostName, port, handler, sslContext, connectionTimeout));
  272. }
  273. /**
  274. * Create a client instance for a remote address and port and CallbackHandler.
  275. *
  276. * @param hostName the remote host
  277. * @param port the port
  278. * @param handler CallbackHandler to obtain authentication information for the call.
  279. * @param saslOptions Additional options to be passed to the SASL mechanism.
  280. * @return A model controller client
  281. * @throws UnknownHostException if the host cannot be found
  282. */
  283. public static ModelControllerClient create(final String hostName, final int port, final CallbackHandler handler, final Map<String, String> saslOptions) throws UnknownHostException {
  284. return create(ClientConfigurationImpl.create(hostName, port, handler, saslOptions));
  285. }
  286. /**
  287. * Create a client instance for a remote address and port and CallbackHandler.
  288. *
  289. * @param protocol The prototcol to use. If this is http-remoting or https-remoting http upgrade will be used rather than the native remote protocol
  290. * @param hostName the remote host
  291. * @param port the port
  292. * @param handler CallbackHandler to obtain authentication information for the call.
  293. * @param saslOptions Additional options to be passed to the SASL mechanism.
  294. * @return A model controller client
  295. * @throws UnknownHostException if the host cannot be found
  296. */
  297. public static ModelControllerClient create(final String protocol, final String hostName, final int port, final CallbackHandler handler, final Map<String, String> saslOptions) throws UnknownHostException {
  298. return create(ClientConfigurationImpl.create(protocol, hostName, port, handler, saslOptions));
  299. }
  300. /**
  301. * Create a client instance based on the client configuration.
  302. *
  303. * @param configuration the controller client configuration
  304. * @return the client
  305. */
  306. public static ModelControllerClient create(final ModelControllerClientConfiguration configuration) {
  307. return new RemotingModelControllerClient(configuration);
  308. }
  309. }
  310. }