Commit 0e383477b7727b8d4a6d8216b9664a201968cdb9

Authored by Derek Hulley
1 parent 2029aa38aa
Exists in master

Code from svn 5.2.N/root/projects/mbeans rev 132756 (REPO-1577)

... ... @@ -0,0 +1,72 @@
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  2 + <modelVersion>4.0.0</modelVersion>
  3 +
  4 + <parent>
  5 + <groupId>org.alfresco</groupId>
  6 + <artifactId>alfresco-super-pom</artifactId>
  7 + <version>8</version>
  8 + </parent>
  9 + <artifactId>alfresco-mbeans</artifactId>
  10 + <version>6.0-SNAPSHOT</version>
  11 + <name>Alfresco MBeans</name>
  12 + <description>Alfresco mbean utilities</description>
  13 +
  14 + <scm>
  15 + <connection>scm:git:https://gitlab.alfresco.com/platform/alfresco-mbeans.git</connection>
  16 + <developerConnection>scm:git:https://gitlab.alfresco.com/platform/alfresco-mbeans.git</developerConnection>
  17 + <url>https://gitlab.alfresco.com/platform/alfresco-mbeans</url>
  18 + <tag>HEAD</tag>
  19 + </scm>
  20 +
  21 + <distributionManagement>
  22 + <repository>
  23 + <id>alfresco-internal</id>
  24 + <url>https://artifacts.alfresco.com/nexus/content/repositories/releases</url>
  25 + </repository>
  26 + <snapshotRepository>
  27 + <id>alfresco-internal-snapshots</id>
  28 + <url>https://artifacts.alfresco.com/nexus/content/repositories/snapshots</url>
  29 + </snapshotRepository>
  30 + </distributionManagement>
  31 +
  32 + <properties>
  33 + <dependency.spring.version>3.2.16.RELEASE</dependency.spring.version>
  34 + </properties>
  35 +
  36 + <dependencies>
  37 + <dependency>
  38 + <groupId>org.springframework</groupId>
  39 + <artifactId>spring-context</artifactId>
  40 + <version>${dependency.spring.version}</version>
  41 + </dependency>
  42 + </dependencies>
  43 +
  44 + <build>
  45 + <pluginManagement>
  46 + <plugins>
  47 + <plugin>
  48 + <artifactId>maven-release-plugin</artifactId>
  49 + <configuration>
  50 + <autoVersionSubmodules>true</autoVersionSubmodules>
  51 + <tagNameFormat>@{project.version}</tagNameFormat>
  52 + </configuration>
  53 + </plugin>
  54 + </plugins>
  55 + </pluginManagement>
  56 +
  57 + <plugins>
  58 + <plugin>
  59 + <artifactId>maven-jar-plugin</artifactId>
  60 + <version>2.6</version>
  61 + <executions>
  62 + <execution>
  63 + <goals>
  64 + <goal>test-jar</goal>
  65 + </goals>
  66 + </execution>
  67 + </executions>
  68 + </plugin>
  69 + </plugins>
  70 + </build>
  71 +
  72 +</project>
... ...
src/main/java/org/alfresco/mbeans/ConnectorServerFactory.java
... ... @@ -0,0 +1,99 @@
  1 +/*
  2 + * #%L
  3 + * Alfresco MBeans
  4 + * %%
  5 + * Copyright (C) 2005 - 2016 Alfresco Software Limited
  6 + * %%
  7 + * This file is part of the Alfresco software.
  8 + * If the software was purchased under a paid Alfresco license, the terms of
  9 + * the paid license agreement will prevail. Otherwise, the software is
  10 + * provided under the following open source license terms:
  11 + *
  12 + * Alfresco is free software: you can redistribute it and/or modify
  13 + * it under the terms of the GNU Lesser General Public License as published by
  14 + * the Free Software Foundation, either version 3 of the License, or
  15 + * (at your option) any later version.
  16 + *
  17 + * Alfresco is distributed in the hope that it will be useful,
  18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20 + * GNU Lesser General Public License for more details.
  21 + *
  22 + * You should have received a copy of the GNU Lesser General Public License
  23 + * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  24 + * #L%
  25 + */
  26 +package org.alfresco.mbeans;
  27 +
  28 +import java.io.IOException;
  29 +
  30 +import javax.management.JMException;
  31 +
  32 +import org.apache.commons.logging.Log;
  33 +import org.apache.commons.logging.LogFactory;
  34 +import org.springframework.jmx.support.ConnectorServerFactoryBean;
  35 +
  36 +/**
  37 + * Factory that creates a JSR-160 <code>JMXConnectorServer</code>,
  38 + * optionally registers it with the <code>MBeanServer</code> and then starts it.
  39 + *
  40 + * @author Stas Sokolovsky
  41 + */
  42 +public class ConnectorServerFactory extends ConnectorServerFactoryBean
  43 +{
  44 + private static Log logger = LogFactory.getLog(ConnectorServerFactory.class);
  45 +
  46 + private boolean enabled = false;
  47 +
  48 + public boolean isEnabled()
  49 + {
  50 + return enabled;
  51 + }
  52 +
  53 + /**
  54 + * Enables JMX connectivity during initialization, see {@link ConnectorServerFactory#afterPropertiesSet()}
  55 + * @param enabled boolean
  56 + */
  57 + public void setEnabled(boolean enabled)
  58 + {
  59 + this.enabled = enabled;
  60 + }
  61 +
  62 + /**
  63 + * Wraps original initialization method to log errors, rather than having
  64 + * exceptions occur within the Spring framework itself (this would cause the entire webapp to fail)
  65 + *
  66 + * @see org.springframework.jmx.support.ConnectorServerFactoryBean#afterPropertiesSet()
  67 + */
  68 + @Override
  69 + public void afterPropertiesSet() throws JMException, IOException
  70 + {
  71 + try
  72 + {
  73 + if (enabled)
  74 + {
  75 + super.afterPropertiesSet();
  76 +
  77 + if (logger.isInfoEnabled())
  78 + {
  79 + logger.info("Created JMX serverConnector");
  80 + }
  81 + }
  82 + else
  83 + {
  84 + if (logger.isInfoEnabled())
  85 + {
  86 + logger.info("JMX serverConnector is disabled.");
  87 + }
  88 + }
  89 +
  90 + }
  91 + catch (Exception e)
  92 + {
  93 + if (logger.isWarnEnabled())
  94 + {
  95 + logger.warn("JMX ServerConnector can't be initialized due to: ", e);
  96 + }
  97 + }
  98 + }
  99 +}
... ...