[365987] Refactor integration classes to cover more adopter use cases.
diff --git a/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/OSGIFrameworkInstanceBehaviorDelegate.java b/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/OSGIFrameworkInstanceBehaviorDelegate.java
index 973a4ea..83e42ef 100644
--- a/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/OSGIFrameworkInstanceBehaviorDelegate.java
+++ b/plugins/org.eclipse.libra.framework.core/src/org/eclipse/libra/framework/core/OSGIFrameworkInstanceBehaviorDelegate.java
@@ -44,8 +44,8 @@
import org.eclipse.libra.framework.editor.core.IOSGiFrameworkAdmin;
import org.eclipse.libra.framework.editor.core.IOSGiFrameworkConsole;
import org.eclipse.libra.framework.editor.core.model.IBundle;
-import org.eclipse.libra.framework.editor.integration.admin.osgijmx.OSGiJMXFrameworkAdmin;
-import org.eclipse.libra.framework.editor.integration.console.basic.BasicOSGiFrameworkConsole;
+import org.eclipse.libra.framework.editor.integration.admin.osgijmx.LaunchOSGiJMXFrameworkAdmin;
+import org.eclipse.libra.framework.editor.integration.console.basic.LaunchBasicOSGiFrameworkConsole;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.internal.IModulePublishHelper;
@@ -686,14 +686,14 @@
private IOSGiFrameworkAdmin getAdmin() throws CoreException {
if (admin == null) {
- admin = new OSGiJMXFrameworkAdmin(getLaunch());
+ admin = new LaunchOSGiJMXFrameworkAdmin(getLaunch());
}
return admin;
}
private IOSGiFrameworkConsole getConsole() throws CoreException {
if (console == null) {
- console = new BasicOSGiFrameworkConsole(getLaunch());
+ console = new LaunchBasicOSGiFrameworkConsole(getLaunch());
}
return console;
}
diff --git a/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/admin/osgijmx/AbstractOSGiJMXFrameworkAdmin.java b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/admin/osgijmx/AbstractOSGiJMXFrameworkAdmin.java
new file mode 100644
index 0000000..d56d038
--- /dev/null
+++ b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/admin/osgijmx/AbstractOSGiJMXFrameworkAdmin.java
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.libra.framework.editor.integration.admin.osgijmx;
+
+import java.io.IOException;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.JMX;
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.libra.framework.editor.core.IOSGiFrameworkAdmin;
+import org.eclipse.libra.framework.editor.core.model.IBundle;
+import org.eclipse.libra.framework.editor.integration.internal.IntegrationPlugin;
+import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.Bundle;
+import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.PackageExport;
+import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.PackageImport;
+import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.PackagesData;
+import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.ServiceReference;
+import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.ServicesData;
+import org.osgi.framework.Constants;
+import org.osgi.jmx.framework.BundleStateMBean;
+import org.osgi.jmx.framework.FrameworkMBean;
+import org.osgi.jmx.framework.PackageStateMBean;
+import org.osgi.jmx.framework.ServiceStateMBean;
+
+/**
+ * @author Kaloyan Raev
+ */
+public abstract class AbstractOSGiJMXFrameworkAdmin implements IOSGiFrameworkAdmin {
+
+ protected abstract String getHost() throws CoreException;
+
+ protected abstract String getPort() throws CoreException;
+
+ public Map<Long, IBundle> getBundles(IProgressMonitor monitor) throws CoreException {
+ Map<Long, IBundle> map = new HashMap<Long, IBundle>();
+
+ try {
+ MBeanServerConnection connection = getMBeanServerConnection();
+ BundleStateMBean bundleStateMBean = getBundleStateMBean(connection);
+ TabularData bundlesData = bundleStateMBean.listBundles();
+ PackageStateMBean packageStateMBean = getPackageStateMBean(connection);
+ PackagesData packagesData = new PackagesData(packageStateMBean);
+ ServiceStateMBean serviceStateMBean = getServiceStateMBean(connection);
+ ServicesData servicesData = new ServicesData(serviceStateMBean);
+
+ Set keys = bundlesData.keySet();
+ for (Object key : keys) {
+ CompositeData bundleInfo = bundlesData.get(((Collection) key).toArray());
+ String id = bundleInfo.get(BundleStateMBean.IDENTIFIER).toString();
+ String symbolicName = bundleInfo.get(BundleStateMBean.SYMBOLIC_NAME).toString();
+ String version = bundleInfo.get(BundleStateMBean.VERSION).toString();
+ String state = bundleInfo.get(BundleStateMBean.STATE).toString();
+ String location = bundleInfo.get(BundleStateMBean.LOCATION).toString();
+ Bundle bundle = new Bundle(id, symbolicName, version, state, location);
+
+ TabularData headers = (TabularData) bundleInfo.get(BundleStateMBean.HEADERS);
+ Set headerKeys = headers.keySet();
+ for (Object headerKey : headerKeys) {
+ CompositeData headerCData = headers.get(((Collection) headerKey).toArray());
+ String hKey = (String) headerCData.get(BundleStateMBean.KEY);
+ String hValue = (String) headerCData.get(BundleStateMBean.VALUE);
+ bundle.addHeader(hKey, hValue);
+ }
+
+ String[] exportedPackages = (String[]) bundleInfo.get(BundleStateMBean.EXPORTED_PACKAGES);
+ for (String epStr : exportedPackages) {
+ int column = epStr.indexOf(';');
+ String packageName = epStr.substring(0, column);
+ String packageVersion = epStr.substring(column + 1, epStr.length());
+ bundle.addPackageExport(new PackageExport(packageName, packageVersion));
+ }
+
+ String[] importedPackages = (String[]) bundleInfo.get(BundleStateMBean.IMPORTED_PACKAGES);
+ for (String ipStr : importedPackages) {
+ int column = ipStr.indexOf(';');
+ String packageName = ipStr.substring(0, column);
+ String packageVersion = ipStr.substring(column + 1, ipStr.length());
+ String exportingBundleId = packagesData.getExportingBundleId(packageName, packageVersion).toString();
+ bundle.addPackageImport(new PackageImport(packageName, packageVersion, exportingBundleId));
+ }
+
+ Long[] registeredServices = (Long[]) bundleInfo.get(BundleStateMBean.REGISTERED_SERVICES);
+ for (Long regService : registeredServices) {
+ ServicesData.ServiceInfo serviceInfo = servicesData.getService(regService);
+ ServiceReference sr = new ServiceReference(ServiceReference.Type.REGISTERED, serviceInfo.getBundleId(), serviceInfo.getObjectClass());
+ sr.addProperty(Constants.SERVICE_ID, serviceInfo.getServiceId().toString());
+ for (Long usingBundleId : serviceInfo.getUsingBundles()) {
+ sr.addUsingBundle(usingBundleId);
+ }
+ bundle.addRegisteredService(sr);
+ }
+
+ Long[] servicesInUse = (Long[]) bundleInfo.get(BundleStateMBean.SERVICES_IN_USE);
+ for (Long serviceInUse : servicesInUse) {
+ ServicesData.ServiceInfo serviceInfo = servicesData.getService(serviceInUse);
+ ServiceReference sr = new ServiceReference(ServiceReference.Type.IN_USE, serviceInfo.getBundleId(), serviceInfo.getObjectClass());
+ sr.addProperty(Constants.SERVICE_ID, serviceInfo.getServiceId().toString());
+ for (Long usingBundleId : serviceInfo.getUsingBundles()) {
+ sr.addUsingBundle(usingBundleId);
+ }
+ bundle.addUsingService(sr);
+ }
+
+ map.put(Long.parseLong(id), bundle);
+ }
+ } catch (UndeclaredThrowableException e) {
+ if (e.getCause() instanceof InstanceNotFoundException) {
+ throw new CoreException(IntegrationPlugin.newErrorStatus("MBean not found: " + e.getCause().getMessage(), e.getCause()));
+ }
+ throw new CoreException(IntegrationPlugin.newErrorStatus(e));
+ } catch (Exception e) {
+ throw new CoreException(IntegrationPlugin.newErrorStatus(e));
+ }
+
+ return map;
+ }
+
+ public void startBundle(long bundleId) throws CoreException {
+ try {
+ MBeanServerConnection connection = getMBeanServerConnection();
+ FrameworkMBean mbean = getFrameworkMBean(connection);
+ mbean.startBundle(bundleId);
+ } catch (Exception e) {
+ throw new CoreException(IntegrationPlugin.newErrorStatus(e));
+ }
+ }
+
+ public void stopBundle(long bundleId) throws CoreException {
+ try {
+ MBeanServerConnection connection = getMBeanServerConnection();
+ FrameworkMBean mbean = getFrameworkMBean(connection);
+ mbean.stopBundle(bundleId);
+ } catch (Exception e) {
+ throw new CoreException(IntegrationPlugin.newErrorStatus(e));
+ }
+ }
+
+ public void refreshBundle(long bundleId) throws CoreException {
+ try {
+ MBeanServerConnection connection = getMBeanServerConnection();
+ FrameworkMBean mbean = getFrameworkMBean(connection);
+ mbean.refreshBundle(bundleId);
+ } catch (Exception e) {
+ throw new CoreException(IntegrationPlugin.newErrorStatus(e));
+ }
+ }
+
+ public void updateBundle(long bundleId) throws CoreException {
+
+ try {
+ MBeanServerConnection connection = getMBeanServerConnection();
+ FrameworkMBean mbean = getFrameworkMBean(connection);
+ mbean.updateBundle(bundleId);
+ } catch (Exception e) {
+ throw new CoreException(IntegrationPlugin.newErrorStatus(e));
+ }
+ }
+
+ protected MBeanServerConnection getMBeanServerConnection() throws IOException, CoreException {
+ JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + getHost() + ":" + getPort() + "/jmxrmi"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ JMXConnector connector = JMXConnectorFactory.connect(url);
+ return connector.getMBeanServerConnection();
+ }
+
+ protected BundleStateMBean getBundleStateMBean(MBeanServerConnection connection) throws MalformedObjectNameException {
+ ObjectName objectName = new ObjectName("osgi.core:type=bundleState,version=1.5"); //$NON-NLS-1$
+ return JMX.newMBeanProxy(connection, objectName, BundleStateMBean.class);
+ }
+
+ protected PackageStateMBean getPackageStateMBean(MBeanServerConnection connection) throws MalformedObjectNameException {
+ ObjectName objectName = new ObjectName("osgi.core:type=packageState,version=1.5"); //$NON-NLS-1$
+ return JMX.newMBeanProxy(connection, objectName, PackageStateMBean.class);
+ }
+
+ protected ServiceStateMBean getServiceStateMBean(MBeanServerConnection connection) throws MalformedObjectNameException {
+ ObjectName objectName = new ObjectName("osgi.core:type=serviceState,version=1.5"); //$NON-NLS-1$
+ return JMX.newMBeanProxy(connection, objectName, ServiceStateMBean.class);
+ }
+
+ protected FrameworkMBean getFrameworkMBean(MBeanServerConnection connection) throws MalformedObjectNameException {
+ ObjectName objectName = new ObjectName("osgi.core:type=framework,version=1.5"); //$NON-NLS-1$
+ return JMX.newMBeanProxy(connection, objectName, FrameworkMBean.class);
+ }
+
+}
diff --git a/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/admin/osgijmx/LaunchOSGiJMXFrameworkAdmin.java b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/admin/osgijmx/LaunchOSGiJMXFrameworkAdmin.java
new file mode 100644
index 0000000..606557a
--- /dev/null
+++ b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/admin/osgijmx/LaunchOSGiJMXFrameworkAdmin.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.libra.framework.editor.integration.admin.osgijmx;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.libra.framework.editor.integration.internal.IntegrationPlugin;
+
+/**
+ * @author Kaloyan Raev
+ */
+public class LaunchOSGiJMXFrameworkAdmin extends AbstractOSGiJMXFrameworkAdmin {
+
+ private ILaunch launch;
+
+ public LaunchOSGiJMXFrameworkAdmin(ILaunch launch) {
+ this.launch = launch;
+ }
+
+ @Override
+ protected String getHost() throws CoreException {
+ return "localhost";
+ }
+
+ @Override
+ protected String getPort() throws CoreException {
+ return getJmxPort(launch);
+ }
+
+ public static String getJmxPort(ILaunch launch) throws CoreException {
+ String rawVMArgs = IntegrationPlugin.getProcess(launch).getAttribute(IProcess.ATTR_CMDLINE);
+ if (rawVMArgs == null) {
+ throw IntegrationPlugin.newCoreException(Messages.OSGiJMXFrameworkAdmin_CannotGetCmdLineArgs);
+ }
+
+ String port = null;
+ String[] vmArgs = DebugPlugin.parseArguments(rawVMArgs);
+ for (String arg : vmArgs) {
+ if (arg.startsWith("-Dcom.sun.management.jmxremote.port=")) { //$NON-NLS-1$
+ int index = arg.indexOf('=');
+ port = arg.substring(index + 1).trim();
+ }
+ }
+
+ if (port == null) {
+ throw IntegrationPlugin.newCoreException(Messages.OSGiJMXFrameworkAdmin_JmxRemoteNotConfigured);
+ }
+
+ return port;
+ }
+
+}
diff --git a/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/admin/osgijmx/OSGiJMXFrameworkAdmin.java b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/admin/osgijmx/OSGiJMXFrameworkAdmin.java
index df6591c..9d443ce 100644
--- a/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/admin/osgijmx/OSGiJMXFrameworkAdmin.java
+++ b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/admin/osgijmx/OSGiJMXFrameworkAdmin.java
@@ -10,48 +10,12 @@
*******************************************************************************/
package org.eclipse.libra.framework.editor.integration.admin.osgijmx;
-import java.io.IOException;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.management.InstanceNotFoundException;
-import javax.management.JMX;
-import javax.management.MBeanServerConnection;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.TabularData;
-import javax.management.remote.JMXConnector;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.libra.framework.editor.core.IOSGiFrameworkAdmin;
-import org.eclipse.libra.framework.editor.core.model.IBundle;
-import org.eclipse.libra.framework.editor.integration.internal.IntegrationPlugin;
-import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.Bundle;
-import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.PackageExport;
-import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.PackageImport;
-import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.PackagesData;
-import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.ServiceReference;
-import org.eclipse.libra.framework.editor.integration.internal.admin.osgijmx.ServicesData;
-import org.osgi.framework.Constants;
-import org.osgi.jmx.framework.BundleStateMBean;
-import org.osgi.jmx.framework.FrameworkMBean;
-import org.osgi.jmx.framework.PackageStateMBean;
-import org.osgi.jmx.framework.ServiceStateMBean;
/**
* @author Kaloyan Raev
*/
-public class OSGiJMXFrameworkAdmin implements IOSGiFrameworkAdmin {
+public class OSGiJMXFrameworkAdmin extends AbstractOSGiJMXFrameworkAdmin {
private String host;
private String port;
@@ -61,181 +25,14 @@
this.port = port;
}
- public OSGiJMXFrameworkAdmin(ILaunch launch) throws CoreException {
- this("localhost", getJmxPort(launch)); //$NON-NLS-1$
+ @Override
+ protected String getHost() throws CoreException {
+ return host;
}
- public static String getJmxPort(ILaunch launch) throws CoreException {
- String rawVMArgs = IntegrationPlugin.getProcess(launch).getAttribute(IProcess.ATTR_CMDLINE);
- if (rawVMArgs == null) {
- throw IntegrationPlugin.newCoreException(Messages.OSGiJMXFrameworkAdmin_CannotGetCmdLineArgs);
- }
-
- String port = null;
- String[] vmArgs = DebugPlugin.parseArguments(rawVMArgs);
- for (String arg : vmArgs) {
- if (arg.startsWith("-Dcom.sun.management.jmxremote.port=")) { //$NON-NLS-1$
- int index = arg.indexOf('=');
- port = arg.substring(index + 1).trim();
- }
- }
-
- if (port == null) {
- throw IntegrationPlugin.newCoreException(Messages.OSGiJMXFrameworkAdmin_JmxRemoteNotConfigured);
- }
-
+ @Override
+ protected String getPort() throws CoreException {
return port;
}
- public Map<Long, IBundle> getBundles(IProgressMonitor monitor) throws CoreException {
- Map<Long, IBundle> map = new HashMap<Long, IBundle>();
-
- try {
- MBeanServerConnection connection = getMBeanServerConnection();
- BundleStateMBean bundleStateMBean = getBundleStateMBean(connection);
- TabularData bundlesData = bundleStateMBean.listBundles();
- PackageStateMBean packageStateMBean = getPackageStateMBean(connection);
- PackagesData packagesData = new PackagesData(packageStateMBean);
- ServiceStateMBean serviceStateMBean = getServiceStateMBean(connection);
- ServicesData servicesData = new ServicesData(serviceStateMBean);
-
- Set keys = bundlesData.keySet();
- for (Object key : keys) {
- CompositeData bundleInfo = bundlesData.get(((Collection) key).toArray());
- String id = bundleInfo.get(BundleStateMBean.IDENTIFIER).toString();
- String symbolicName = bundleInfo.get(BundleStateMBean.SYMBOLIC_NAME).toString();
- String version = bundleInfo.get(BundleStateMBean.VERSION).toString();
- String state = bundleInfo.get(BundleStateMBean.STATE).toString();
- String location = bundleInfo.get(BundleStateMBean.LOCATION).toString();
- Bundle bundle = new Bundle(id, symbolicName, version, state, location);
-
- TabularData headers = (TabularData) bundleInfo.get(BundleStateMBean.HEADERS);
- Set headerKeys = headers.keySet();
- for (Object headerKey : headerKeys) {
- CompositeData headerCData = headers.get(((Collection) headerKey).toArray());
- String hKey = (String) headerCData.get(BundleStateMBean.KEY);
- String hValue = (String) headerCData.get(BundleStateMBean.VALUE);
- bundle.addHeader(hKey, hValue);
- }
-
- String[] exportedPackages = (String[]) bundleInfo.get(BundleStateMBean.EXPORTED_PACKAGES);
- for (String epStr : exportedPackages) {
- int column = epStr.indexOf(';');
- String packageName = epStr.substring(0, column);
- String packageVersion = epStr.substring(column + 1, epStr.length());
- bundle.addPackageExport(new PackageExport(packageName, packageVersion));
- }
-
- String[] importedPackages = (String[]) bundleInfo.get(BundleStateMBean.IMPORTED_PACKAGES);
- for (String ipStr : importedPackages) {
- int column = ipStr.indexOf(';');
- String packageName = ipStr.substring(0, column);
- String packageVersion = ipStr.substring(column + 1, ipStr.length());
- String exportingBundleId = packagesData.getExportingBundleId(packageName, packageVersion).toString();
- bundle.addPackageImport(new PackageImport(packageName, packageVersion, exportingBundleId));
- }
-
- Long[] registeredServices = (Long[]) bundleInfo.get(BundleStateMBean.REGISTERED_SERVICES);
- for (Long regService : registeredServices) {
- ServicesData.ServiceInfo serviceInfo = servicesData.getService(regService);
- ServiceReference sr = new ServiceReference(ServiceReference.Type.REGISTERED, serviceInfo.getBundleId(), serviceInfo.getObjectClass());
- sr.addProperty(Constants.SERVICE_ID, serviceInfo.getServiceId().toString());
- for (Long usingBundleId : serviceInfo.getUsingBundles()) {
- sr.addUsingBundle(usingBundleId);
- }
- bundle.addRegisteredService(sr);
- }
-
- Long[] servicesInUse = (Long[]) bundleInfo.get(BundleStateMBean.SERVICES_IN_USE);
- for (Long serviceInUse : servicesInUse) {
- ServicesData.ServiceInfo serviceInfo = servicesData.getService(serviceInUse);
- ServiceReference sr = new ServiceReference(ServiceReference.Type.IN_USE, serviceInfo.getBundleId(), serviceInfo.getObjectClass());
- sr.addProperty(Constants.SERVICE_ID, serviceInfo.getServiceId().toString());
- for (Long usingBundleId : serviceInfo.getUsingBundles()) {
- sr.addUsingBundle(usingBundleId);
- }
- bundle.addUsingService(sr);
- }
-
- map.put(Long.parseLong(id), bundle);
- }
- } catch (UndeclaredThrowableException e) {
- if (e.getCause() instanceof InstanceNotFoundException) {
- throw new CoreException(IntegrationPlugin.newErrorStatus("MBean not found: " + e.getCause().getMessage(), e.getCause()));
- }
- throw new CoreException(IntegrationPlugin.newErrorStatus(e));
- } catch (Exception e) {
- throw new CoreException(IntegrationPlugin.newErrorStatus(e));
- }
-
- return map;
- }
-
- public void startBundle(long bundleId) throws CoreException {
- try {
- MBeanServerConnection connection = getMBeanServerConnection();
- FrameworkMBean mbean = getFrameworkMBean(connection);
- mbean.startBundle(bundleId);
- } catch (Exception e) {
- throw new CoreException(IntegrationPlugin.newErrorStatus(e));
- }
- }
-
- public void stopBundle(long bundleId) throws CoreException {
- try {
- MBeanServerConnection connection = getMBeanServerConnection();
- FrameworkMBean mbean = getFrameworkMBean(connection);
- mbean.stopBundle(bundleId);
- } catch (Exception e) {
- throw new CoreException(IntegrationPlugin.newErrorStatus(e));
- }
- }
-
- public void refreshBundle(long bundleId) throws CoreException {
- try {
- MBeanServerConnection connection = getMBeanServerConnection();
- FrameworkMBean mbean = getFrameworkMBean(connection);
- mbean.refreshBundle(bundleId);
- } catch (Exception e) {
- throw new CoreException(IntegrationPlugin.newErrorStatus(e));
- }
- }
-
- public void updateBundle(long bundleId) throws CoreException {
-
- try {
- MBeanServerConnection connection = getMBeanServerConnection();
- FrameworkMBean mbean = getFrameworkMBean(connection);
- mbean.updateBundle(bundleId);
- } catch (Exception e) {
- throw new CoreException(IntegrationPlugin.newErrorStatus(e));
- }
- }
-
- private MBeanServerConnection getMBeanServerConnection() throws IOException {
- JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- JMXConnector connector = JMXConnectorFactory.connect(url);
- return connector.getMBeanServerConnection();
- }
-
- private BundleStateMBean getBundleStateMBean(MBeanServerConnection connection) throws MalformedObjectNameException {
- ObjectName objectName = new ObjectName("osgi.core:type=bundleState,version=1.5"); //$NON-NLS-1$
- return JMX.newMBeanProxy(connection, objectName, BundleStateMBean.class);
- }
-
- private PackageStateMBean getPackageStateMBean(MBeanServerConnection connection) throws MalformedObjectNameException {
- ObjectName objectName = new ObjectName("osgi.core:type=packageState,version=1.5"); //$NON-NLS-1$
- return JMX.newMBeanProxy(connection, objectName, PackageStateMBean.class);
- }
-
- private ServiceStateMBean getServiceStateMBean(MBeanServerConnection connection) throws MalformedObjectNameException {
- ObjectName objectName = new ObjectName("osgi.core:type=serviceState,version=1.5"); //$NON-NLS-1$
- return JMX.newMBeanProxy(connection, objectName, ServiceStateMBean.class);
- }
-
- private FrameworkMBean getFrameworkMBean(MBeanServerConnection connection) throws MalformedObjectNameException {
- ObjectName objectName = new ObjectName("osgi.core:type=framework,version=1.5"); //$NON-NLS-1$
- return JMX.newMBeanProxy(connection, objectName, FrameworkMBean.class);
- }
-
}
diff --git a/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/console/basic/AbstractBasicOSGiFrameworkConsole.java b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/console/basic/AbstractBasicOSGiFrameworkConsole.java
new file mode 100644
index 0000000..3e0ea3b
--- /dev/null
+++ b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/console/basic/AbstractBasicOSGiFrameworkConsole.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.libra.framework.editor.integration.console.basic;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.IStreamListener;
+import org.eclipse.debug.core.model.IStreamMonitor;
+import org.eclipse.debug.core.model.IStreamsProxy;
+import org.eclipse.libra.framework.editor.core.IOSGiFrameworkConsole;
+import org.eclipse.libra.framework.editor.integration.internal.IntegrationPlugin;
+
+/**
+ * @author Kaloyan Raev
+ */
+public abstract class AbstractBasicOSGiFrameworkConsole implements IOSGiFrameworkConsole, IStreamListener {
+
+ private StringBuilder result;
+
+ protected abstract IStreamsProxy getProxy() throws CoreException;
+
+ public synchronized String executeCommand(String command) throws CoreException {
+ result = new StringBuilder();
+
+ try {
+ IStreamsProxy proxy = getProxy();
+ proxy.getOutputStreamMonitor().addListener(this);
+ proxy.write(command + "\n"); //$NON-NLS-1$
+ } catch (IOException e) {
+ throw new CoreException(IntegrationPlugin.newErrorStatus(e));
+ }
+
+ long startTime = System.currentTimeMillis();
+ int size = 0;
+ do {
+ size = result.length();
+ try {
+ wait(10);
+ } catch (InterruptedException e) {
+ throw new CoreException(IntegrationPlugin.newErrorStatus(e));
+ }
+ } while ((result.length() == 0 && System.currentTimeMillis() - startTime < 5000)
+ || result.length() > size);
+
+ return result.toString();
+ }
+
+ public synchronized void streamAppended(String text, IStreamMonitor monitor) {
+ result.append(text);
+ }
+
+}
diff --git a/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/console/basic/BasicOSGiFrameworkConsole.java b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/console/basic/BasicOSGiFrameworkConsole.java
index 3e25bad..e0896e8 100644
--- a/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/console/basic/BasicOSGiFrameworkConsole.java
+++ b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/console/basic/BasicOSGiFrameworkConsole.java
@@ -10,67 +10,27 @@
*******************************************************************************/
package org.eclipse.libra.framework.editor.integration.console.basic;
-import java.io.IOException;
-
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.IStreamListener;
-import org.eclipse.debug.core.model.IStreamMonitor;
import org.eclipse.debug.core.model.IStreamsProxy;
-import org.eclipse.libra.framework.editor.core.IOSGiFrameworkConsole;
-import org.eclipse.libra.framework.editor.integration.internal.IntegrationPlugin;
/**
* @author Kaloyan Raev
*/
-public class BasicOSGiFrameworkConsole implements IOSGiFrameworkConsole, IStreamListener {
+public class BasicOSGiFrameworkConsole extends AbstractBasicOSGiFrameworkConsole {
private IStreamsProxy proxy;
- private StringBuilder result;
+
+ protected BasicOSGiFrameworkConsole() {
+ this.proxy = null;
+ }
public BasicOSGiFrameworkConsole(IStreamsProxy proxy) {
this.proxy = proxy;
- proxy.getOutputStreamMonitor().addListener(this);
}
- public BasicOSGiFrameworkConsole(ILaunch launch) throws CoreException {
- this(getStreamsProxy(launch));
- }
-
- public static IStreamsProxy getStreamsProxy(ILaunch launch) throws CoreException {
- IStreamsProxy proxy = IntegrationPlugin.getProcess(launch).getStreamsProxy();
- if (proxy == null) {
- throw IntegrationPlugin.newCoreException(Messages.BasicOSGiFrameworkConsole_CannotGetInOutStreams);
- }
+ @Override
+ protected IStreamsProxy getProxy() throws CoreException {
return proxy;
}
- public synchronized String executeCommand(String command) throws CoreException {
- result = new StringBuilder();
-
- try {
- proxy.write(command + "\n"); //$NON-NLS-1$
- } catch (IOException e) {
- throw new CoreException(IntegrationPlugin.newErrorStatus(e));
- }
-
- long startTime = System.currentTimeMillis();
- int size = 0;
- do {
- size = result.length();
- try {
- wait(10);
- } catch (InterruptedException e) {
- throw new CoreException(IntegrationPlugin.newErrorStatus(e));
- }
- } while ((result.length() == 0 && System.currentTimeMillis() - startTime < 5000)
- || result.length() > size);
-
- return result.toString();
- }
-
- public synchronized void streamAppended(String text, IStreamMonitor monitor) {
- result.append(text);
- }
-
}
diff --git a/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/console/basic/LaunchBasicOSGiFrameworkConsole.java b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/console/basic/LaunchBasicOSGiFrameworkConsole.java
new file mode 100644
index 0000000..c22211c
--- /dev/null
+++ b/plugins/org.eclipse.libra.framework.editor.integration/src/org/eclipse/libra/framework/editor/integration/console/basic/LaunchBasicOSGiFrameworkConsole.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * SAP AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.libra.framework.editor.integration.console.basic;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.model.IStreamsProxy;
+import org.eclipse.libra.framework.editor.integration.internal.IntegrationPlugin;
+
+/**
+ * @author Kaloyan Raev
+ */
+public class LaunchBasicOSGiFrameworkConsole extends BasicOSGiFrameworkConsole {
+
+ private ILaunch launch;
+
+ public LaunchBasicOSGiFrameworkConsole(ILaunch launch) {
+ super();
+ this.launch = launch;
+ }
+
+ @Override
+ protected IStreamsProxy getProxy() throws CoreException {
+ return getStreamsProxy(launch);
+ }
+
+ public static IStreamsProxy getStreamsProxy(ILaunch launch) throws CoreException {
+ IStreamsProxy proxy = IntegrationPlugin.getProcess(launch).getStreamsProxy();
+ if (proxy == null) {
+ throw IntegrationPlugin.newCoreException(Messages.BasicOSGiFrameworkConsole_CannotGetInOutStreams);
+ }
+ return proxy;
+ }
+
+}