PageRenderTime 46ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/jmx/src/main/java/org/jboss/as/jmx/RemotingConnectorService.java

https://bitbucket.org/cprenzberg/wildfly
Java | 99 lines | 58 code | 15 blank | 26 comment | 4 complexity | 9750f300148098903ff74f5cc08dc57e MD5 | raw file
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2012, 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.jmx;
  23. import java.io.IOException;
  24. import javax.management.MBeanServer;
  25. import org.jboss.as.controller.ServiceVerificationHandler;
  26. import org.jboss.as.remoting.RemotingServices;
  27. import org.jboss.as.remoting.management.ManagementRemotingServices;
  28. import org.jboss.msc.service.Service;
  29. import org.jboss.msc.service.ServiceBuilder;
  30. import org.jboss.msc.service.ServiceController;
  31. import org.jboss.msc.service.ServiceName;
  32. import org.jboss.msc.service.ServiceTarget;
  33. import org.jboss.msc.service.StartContext;
  34. import org.jboss.msc.service.StartException;
  35. import org.jboss.msc.service.StopContext;
  36. import org.jboss.msc.value.InjectedValue;
  37. import org.jboss.remoting3.Endpoint;
  38. import org.jboss.remotingjmx.RemotingConnectorServer;
  39. /**
  40. * The remote connector services
  41. *
  42. * @author Stuart Douglas
  43. */
  44. public class RemotingConnectorService implements Service<RemotingConnectorServer> {
  45. public static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("jmx", "remoting-connector-ref");
  46. private RemotingConnectorServer server;
  47. private final InjectedValue<MBeanServer> mBeanServer = new InjectedValue<MBeanServer>();
  48. private final InjectedValue<Endpoint> endpoint = new InjectedValue<Endpoint>();
  49. @Override
  50. public synchronized void start(final StartContext context) throws StartException {
  51. server = new RemotingConnectorServer(mBeanServer.getValue(), endpoint.getValue());
  52. try {
  53. server.start();
  54. } catch (IOException e) {
  55. throw new StartException(e);
  56. }
  57. }
  58. @Override
  59. public synchronized void stop(final StopContext context) {
  60. try {
  61. server.stop();
  62. } catch (IOException e) {
  63. throw new RuntimeException(e);
  64. }
  65. }
  66. @Override
  67. public synchronized RemotingConnectorServer getValue() throws IllegalStateException, IllegalArgumentException {
  68. return server;
  69. }
  70. public static ServiceController<?> addService(final ServiceTarget target, final ServiceVerificationHandler verificationHandler, final boolean useManagementEndpoint) {
  71. final RemotingConnectorService service = new RemotingConnectorService();
  72. final ServiceBuilder<RemotingConnectorServer> builder = target.addService(SERVICE_NAME, service);
  73. builder.addDependency(MBeanServerService.SERVICE_NAME, MBeanServer.class, service.mBeanServer);
  74. if(useManagementEndpoint) {
  75. builder.addDependency(ManagementRemotingServices.MANAGEMENT_ENDPOINT, Endpoint.class, service.endpoint);
  76. } else {
  77. builder.addDependency(RemotingServices.SUBSYSTEM_ENDPOINT, Endpoint.class, service.endpoint);
  78. }
  79. if (verificationHandler != null) {
  80. builder.addListener(verificationHandler);
  81. }
  82. return builder.install();
  83. }
  84. }