Navigation Menu

Skip to content

Commit

Permalink
Second part of fixing #249, move plugin registry counter to hawtio-we…
Browse files Browse the repository at this point in the history
…b and take out the requirement for a blueprint reference list for registering plugins, can just pure JMX instead
  • Loading branch information
gashcrumb committed Apr 15, 2013
1 parent 97991f1 commit ec4724c
Show file tree
Hide file tree
Showing 17 changed files with 274 additions and 325 deletions.
11 changes: 5 additions & 6 deletions hawtio-karaf/src/main/resources/features.xml
Expand Up @@ -2,22 +2,20 @@
<features name='hawtio-${project.version}'>

<feature name="hawtio" version="${project.version}" resolver="(obr)">
<details>Installs the main hawtio war file, an MBean helper for OSGi and an MBean helper to get JSON Schema out of Java objects</details>
<feature>war</feature>
<feature>hawtio-plugin-registry</feature>
<bundle>mvn:io.hawt/hawtio-web/${project.version}/war</bundle>
<bundle>mvn:io.hawt/hawtio-osgi-jmx/${project.version}</bundle>
<bundle>mvn:io.hawt/hawtio-json-schema-mbean/${project.version}</bundle>
</feature>

<feature name="hawtio-plugin-registry" version="${project.version}" resolver="(obr)">
<bundle>mvn:io.hawt/hawtio-plugin-registry/${project.version}</bundle>
<bundle>mvn:io.hawt/hawtio-web/${project.version}/war</bundle>
</feature>

<feature name="hawtio-maven-indexer" version="${project.version}" resolver="(obr)">
<details>Installs the hawtio maven indexer service as a separate bundle</details>
<bundle>fab:mvn:io.hawt/hawtio-maven-indexer/${project.version}</bundle>
</feature>

<feature name="hawtio-git" version="${project.version}" resolver="(obr)">
<details>Installs the hawtio git service as a separate bundle</details>

<config>
hawtio.config.dir=./git
Expand Down Expand Up @@ -48,6 +46,7 @@
</feature>

<feature name="hawtio-plugin-example" version="${project.version}" resolver="(obr)">
<details>A simple example plugin for hawtio</details>
<feature>war</feature>
<bundle>mvn:io.hawt/simple-plugin/${project.version}/war</bundle>
</feature>
Expand Down
4 changes: 1 addition & 3 deletions hawtio-plugin-example/simple-plugin/pom.xml
Expand Up @@ -21,7 +21,6 @@
<plugin-scripts>app/js/simplePlugin.js</plugin-scripts>

<fuse.osgi.import>
io.hawt.web.plugin,
*;resolution:=optional
</fuse.osgi.import>
<!--
Expand All @@ -35,9 +34,8 @@

<dependency>
<groupId>io.hawt</groupId>
<artifactId>hawtio-plugin-registry</artifactId>
<artifactId>hawtio-plugin-mbean</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

</dependencies>
Expand Down
Expand Up @@ -17,13 +17,11 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">

<bean id="plugin" class="io.hawt.web.plugin.SimplePlugin">
<bean id="plugin" class="io.hawt.web.plugin.HawtioPlugin" init-method="init" destroy-method="destroy">
<property name="name" value="${plugin-name}"/>
<property name="context" value="${plugin-context}"/>
<property name="domain" value="${plugin-domain}"/>
<property name="scripts" value="${plugin-scripts}"/>
</bean>

<service ref="plugin" interface="io.hawt.web.plugin.Plugin"/>

</blueprint>
11 changes: 2 additions & 9 deletions hawtio-plugin-registry/pom.xml → hawtio-plugin-mbean/pom.xml
Expand Up @@ -7,14 +7,12 @@
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>hawtio-plugin-registry</artifactId>
<artifactId>hawtio-plugin-mbean</artifactId>
<packaging>bundle</packaging>
<name>${project.artifactId}</name>
<description>hawtio :: Plugin Registry Backend</description>
<description>hawtio :: Plugin MBean</description>

<properties>
<context>/hawtio/plugin_registry</context>

<fuse.osgi.export>
io.hawt.web.plugin
</fuse.osgi.export>
Expand All @@ -23,9 +21,6 @@
javax.management,
*;resolution:=optional
</fuse.osgi.import>
<fuse.osgi.private.pkg>
io.hawt.web.plugin.internal
</fuse.osgi.private.pkg>

<slf4j-version>1.6.1</slf4j-version>

Expand Down Expand Up @@ -64,8 +59,6 @@

<Export-Package>${fuse.osgi.export}</Export-Package>
<Import-Package>${fuse.osgi.import}</Import-Package>
<DynamicImport-Package>${fuse.osgi.dynamic}</DynamicImport-Package>
<Private-Package>${fuse.osgi.private.pkg}</Private-Package>

<Bundle-Name>${project.description}</Bundle-Name>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
Expand Down
128 changes: 128 additions & 0 deletions hawtio-plugin-mbean/src/main/java/io/hawt/web/plugin/HawtioPlugin.java
@@ -0,0 +1,128 @@
/*
* Copyright 2012 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version
* 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package io.hawt.web.plugin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;

/**
*
*/
public class HawtioPlugin implements HawtioPluginMBean {

private static final transient Logger LOG = LoggerFactory.getLogger(HawtioPlugin.class);

private String name;
private String context;
private String domain;
private String scripts[];

private ObjectName objectName = null;
private MBeanServer mBeanServer = null;

public HawtioPlugin() {

}

public void init() {
try {
if (objectName == null) {
objectName = getObjectName();
}

if (mBeanServer == null) {
mBeanServer = ManagementFactory.getPlatformMBeanServer();
}

if (mBeanServer.isRegistered(objectName)) {
// Update of existing plugin
LOG.info("Unregistering existing plugin " + objectName);
mBeanServer.unregisterMBean(objectName);
}

LOG.debug("Registering plugin " + objectName);
mBeanServer.registerMBean(this, objectName);


} catch (Throwable t) {
LOG.error("Failed to register plugin: ", t);
}
}

public void destroy() {
try {
if (mBeanServer != null) {
LOG.debug("Unregistering plugin " + objectName);
mBeanServer.unregisterMBean(objectName);
}
} catch (Throwable t) {
LOG.error("Failed to register plugin: ", t);
}
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return this.name;
}

public void setContext(String context) {
this.context = context;
}

public String getContext() {
return this.context;
}

public void setDomain(String domain) {
this.domain = domain;
}

public String getDomain() {
return this.domain;
}

public void setScripts(String[] scripts) {
this.scripts = scripts;
}

public void setScripts(String scripts) {
String[] temp = scripts.split(",");

for (int i=0; i>temp.length; i++) {
temp[i] = temp[i].trim();
}

this.scripts = temp;
}

public String[] getScripts() {
return this.scripts;
}

protected ObjectName getObjectName() throws MalformedObjectNameException {
return new ObjectName("hawtio:type=plugin,name=" + getName());
}

}
Expand Up @@ -14,9 +14,9 @@
* permissions and limitations under the License.
*/

package io.hawt.web.plugin.internal;
package io.hawt.web.plugin;

public interface PluginMBean extends io.hawt.web.plugin.Plugin {
public interface HawtioPluginMBean extends io.hawt.web.plugin.Plugin {

}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit ec4724c

Please sign in to comment.