Home » geronimo-2.2-source-release » org.apache.geronimo.farm.plugin » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    *  http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied.  See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   
   20   package org.apache.geronimo.farm.plugin;
   21   
   22   import java.io.IOException;
   23   import java.util.Set;
   24   
   25   import javax.persistence.Entity;
   26   import javax.persistence.Id;
   27   import javax.persistence.Transient;
   28   import javax.persistence.NamedQuery;
   29   import javax.persistence.GeneratedValue;
   30   import javax.persistence.ManyToOne;
   31   import javax.persistence.FetchType;
   32   import javax.persistence.CascadeType;
   33   import javax.persistence.JoinColumn;
   34   import javax.management.remote.JMXConnector;
   35   
   36   import org.apache.geronimo.farm.config.ExtendedJMXConnectorInfo;
   37   import org.apache.geronimo.farm.config.NodeInfo;
   38   import org.apache.geronimo.farm.config.BasicExtendedJMXConnectorInfo;
   39   import org.apache.geronimo.gbean.AbstractName;
   40   import org.apache.geronimo.gbean.AbstractNameQuery;
   41   import org.apache.geronimo.kernel.Kernel;
   42   import org.apache.geronimo.kernel.KernelRegistry;
   43   import org.apache.geronimo.kernel.config.ConfigurationManager;
   44   import org.apache.geronimo.system.plugin.PluginInstaller;
   45   
   46   /**
   47    * @version $Rev:$ $Date:$
   48    */
   49   @Entity(name="node")
   50   @NamedQuery(name = "nodeByName", query = "SELECT a FROM node a WHERE a.name = :name")
   51   public class JpaNodeInfo implements NodeInfo {
   52       @Id
   53       private String name;
   54       private String userName;
   55       private String password;
   56       private String protocol;
   57       private String host;
   58       private int port = -1;
   59       private String urlPath;
   60       private boolean local;
   61   
   62       @ManyToOne(fetch= FetchType.EAGER, cascade={CascadeType.PERSIST})
   63       @JoinColumn(
   64           name="cluster", referencedColumnName="name"
   65       )
   66       private JpaClusterInfo cluster;
   67   
   68       @Transient
   69       private Kernel kernel;
   70       @Transient
   71       private PluginInstaller pluginInstaller;
   72       @Transient
   73       private JMXConnector jmxConnector;
   74       @Transient
   75       private ConfigurationManager configurationManager;
   76   
   77       public JpaNodeInfo() {
   78       }
   79   
   80       public JpaNodeInfo(NodeInfo nodeInfo) {
   81           this.name = nodeInfo.getName();
   82           ExtendedJMXConnectorInfo connectorInfo = nodeInfo.getConnectorInfo();
   83           userName = connectorInfo.getUsername();
   84           password = connectorInfo.getPassword();
   85           protocol = connectorInfo.getProtocol();
   86           host = connectorInfo.getHost();
   87           port = connectorInfo.getPort();
   88           urlPath = connectorInfo.getUrlPath();
   89           local = connectorInfo.isLocal();
   90       }
   91   
   92       public JpaClusterInfo getCluster() {
   93           return cluster;
   94       }
   95   
   96       public void setCluster(JpaClusterInfo cluster) {
   97           this.cluster = cluster;
   98       }
   99   
  100       public String getName() {
  101           return name;
  102       }
  103   
  104       public void setName(String name) {
  105           this.name = name;
  106       }
  107   
  108       public ExtendedJMXConnectorInfo getConnectorInfo() {
  109           return new BasicExtendedJMXConnectorInfo(userName,  password,  protocol,  host,  port,  urlPath, local);
  110       }
  111   
  112       public void setConnectorInfo(String userName, String password, String protocol, String host, int port, String urlPath, boolean local) {
  113           this.userName = userName;
  114           this.password = password;
  115           this.protocol = protocol;
  116           this.host = host;
  117           this.port = port;
  118           this.urlPath = urlPath;
  119           this.local = local;
  120       }
  121   
  122       public Kernel newKernel() throws IOException {
  123           if (kernel == null) {
  124               if (local) {
  125                   kernel = KernelRegistry.getSingleKernel();
  126               } else {
  127                   ExtendedJMXConnectorInfo connectorInfo = getConnectorInfo();
  128                   jmxConnector = connectorInfo.connect();
  129                   return connectorInfo.newKernel(jmxConnector);
  130               }
  131           }
  132           return kernel;
  133       }
  134   
  135       public synchronized PluginInstaller getPluginInstaller() throws IOException {
  136           if (pluginInstaller != null) {
  137               return pluginInstaller;
  138           }
  139           Kernel kernel = newKernel();
  140           Set<AbstractName> set = kernel.listGBeans(new AbstractNameQuery(PluginInstaller.class.getName()));
  141           for (AbstractName name : set) {
  142               pluginInstaller = kernel.getProxyManager().createProxy(name, PluginInstaller.class);
  143               return pluginInstaller;
  144           }
  145           throw new IllegalStateException("No plugin installer found");
  146       }
  147   
  148       public synchronized ConfigurationManager getConfigurationManager() throws IOException {
  149           if (configurationManager != null) {
  150               return configurationManager;
  151           }
  152           Kernel kernel = newKernel();
  153           Set<AbstractName> set = kernel.listGBeans(new AbstractNameQuery(ConfigurationManager.class.getName()));
  154           for (AbstractName name : set) {
  155               configurationManager = kernel.getProxyManager().createProxy(name, ConfigurationManager.class);
  156               return configurationManager;
  157           }
  158           throw new IllegalStateException("No plugin installer found");
  159       }
  160   
  161       public synchronized void disconnect() throws IOException {
  162           if (kernel != null) {
  163               if (pluginInstaller != null) {
  164                   kernel.getProxyManager().destroyProxy(pluginInstaller);
  165                   pluginInstaller = null;
  166               }
  167               if (!local) {
  168                   jmxConnector.close();
  169                   jmxConnector = null;
  170               }
  171               kernel = null;
  172           }
  173       }
  174   
  175   }

Home » geronimo-2.2-source-release » org.apache.geronimo.farm.plugin » [javadoc | source]