Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 136698 Details for
Bug 274980
[plug-in registry] Investigate possibility of reuse JMX spec in remote monitoring
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
jmx test
patch.txt (text/plain), 40.60 KB, created by
Wojciech Galanciak
on 2009-05-21 14:46:15 EDT
(
hide
)
Description:
jmx test
Filename:
MIME Type:
Creator:
Wojciech Galanciak
Created:
2009-05-21 14:46:15 EDT
Size:
40.60 KB
patch
obsolete
>Index: src/org/eclipse/pde/internal/runtime/registry/model/ConfigurationElement.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/ConfigurationElement.java,v >retrieving revision 1.3 >diff -u -r1.3 ConfigurationElement.java >--- src/org/eclipse/pde/internal/runtime/registry/model/ConfigurationElement.java 25 Apr 2009 23:29:16 -0000 1.3 >+++ src/org/eclipse/pde/internal/runtime/registry/model/ConfigurationElement.java 21 May 2009 18:37:21 -0000 >@@ -24,4 +24,18 @@ > public Attribute[] getElements() { > return elements; > } >+ >+ public ModelObject[] getChildren() { >+ return elements; >+ } >+ >+ public void addChild(ModelObject o) { >+ if (o instanceof Attribute) { >+ // XXX very ineffective >+ Attribute[] tmp = new Attribute[elements.length + 1]; >+ System.arraycopy(elements, 0, tmp, 0, elements.length); >+ tmp[tmp.length - 1] = (Attribute) o; >+ elements = tmp; >+ } >+ } > } >Index: src/org/eclipse/pde/internal/runtime/registry/model/ModelObject.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/ModelObject.java,v >retrieving revision 1.2 >diff -u -r1.2 ModelObject.java >--- src/org/eclipse/pde/internal/runtime/registry/model/ModelObject.java 29 Dec 2008 18:57:23 -0000 1.2 >+++ src/org/eclipse/pde/internal/runtime/registry/model/ModelObject.java 21 May 2009 18:37:21 -0000 >@@ -17,4 +17,13 @@ > public void setModel(RegistryModel model) { > this.model = model; > } >+ >+ >+ public void addChild(ModelObject obj) { >+ // empty >+ } >+ >+ public ModelObject[] getChildren() { >+ return null; >+ } > } >Index: src/org/eclipse/pde/internal/runtime/registry/model/RegistryModel.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/RegistryModel.java,v >retrieving revision 1.7 >diff -u -r1.7 RegistryModel.java >--- src/org/eclipse/pde/internal/runtime/registry/model/RegistryModel.java 23 Mar 2009 15:14:15 -0000 1.7 >+++ src/org/eclipse/pde/internal/runtime/registry/model/RegistryModel.java 21 May 2009 18:37:22 -0000 >@@ -293,7 +293,7 @@ > * > * @param objects > */ >- protected void fireModelChangeEvent(ModelChangeDelta[] delta) { >+ synchronized protected void fireModelChangeEvent(ModelChangeDelta[] delta) { > for (Iterator i = listeners.iterator(); i.hasNext();) { > ModelChangeListener listener = (ModelChangeListener) i.next(); > listener.modelChanged(delta); >Index: src/org/eclipse/pde/internal/runtime/registry/model/ServiceRegistration.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/ServiceRegistration.java,v >retrieving revision 1.5 >diff -u -r1.5 ServiceRegistration.java >--- src/org/eclipse/pde/internal/runtime/registry/model/ServiceRegistration.java 6 Jan 2009 16:59:12 -0000 1.5 >+++ src/org/eclipse/pde/internal/runtime/registry/model/ServiceRegistration.java 21 May 2009 18:37:22 -0000 >@@ -143,4 +143,18 @@ > } > return 0; > } >+ >+ public void addChild(ModelObject obj) { >+ if (obj instanceof Property) { >+ // XXX very ineffective >+ Property[] tmp = new Property[properties.length + 1]; >+ System.arraycopy(properties, 0, tmp, 0, properties.length); >+ tmp[tmp.length - 1] = (Property) obj; >+ properties = tmp; >+ } >+ } >+ >+ public ModelObject[] getChildren() { >+ return properties; >+ } > } >Index: src/org/eclipse/pde/internal/runtime/registry/model/RegistryModelFactory.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/RegistryModelFactory.java,v >retrieving revision 1.2 >diff -u -r1.2 RegistryModelFactory.java >--- src/org/eclipse/pde/internal/runtime/registry/model/RegistryModelFactory.java 23 Oct 2008 18:41:07 -0000 1.2 >+++ src/org/eclipse/pde/internal/runtime/registry/model/RegistryModelFactory.java 21 May 2009 18:37:22 -0000 >@@ -20,6 +20,9 @@ > */ > public class RegistryModelFactory { > >+ public static final String LOCAL = "local"; //$NON-NLS-1$ >+ public static final String REMOTE = "remote"; //$NON-NLS-1$ >+ > /** > * > * @param uri >Index: src/org/eclipse/pde/internal/runtime/registry/model/ModelChangeDelta.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/ModelChangeDelta.java,v >retrieving revision 1.1 >diff -u -r1.1 ModelChangeDelta.java >--- src/org/eclipse/pde/internal/runtime/registry/model/ModelChangeDelta.java 20 Oct 2008 22:10:45 -0000 1.1 >+++ src/org/eclipse/pde/internal/runtime/registry/model/ModelChangeDelta.java 21 May 2009 18:37:21 -0000 >@@ -13,7 +13,7 @@ > /** > * Delta model objects are of type IBundle, IService, IExtension, IExtensionPoint > */ >-public class ModelChangeDelta { >+public class ModelChangeDelta extends ModelObject { > > public static final int ADDED = 0; > public static final int UPDATED = 1; >@@ -25,9 +25,14 @@ > public static final int RESOLVED = 7; > public static final int UNRESOLVED = 8; > >+ // TODO SWITCH from HEAVY ModelChangeDelta carrying whole object, to LIGHT delta - name, type (Bundle/Service/Ext/ExtPt), id > private ModelObject fObject; > private int fFlag; > >+ public ModelChangeDelta() { >+ // empty >+ } >+ > public ModelChangeDelta(ModelObject object, int flag) { > fObject = object; > fFlag = flag; >@@ -40,4 +45,20 @@ > public int getFlag() { > return fFlag; > } >+ >+ public void addChild(ModelObject o) { >+ setModelObject(o); >+ } >+ >+ public ModelObject[] getChildren() { >+ return new ModelObject[] {fObject}; >+ } >+ >+ public void setModelObject(ModelObject fObject) { >+ this.fObject = fObject; >+ } >+ >+ public void setFlag(int flag) { >+ this.fFlag = flag; >+ } > } >Index: src/org/eclipse/pde/internal/runtime/registry/model/RegistryBackend.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/RegistryBackend.java,v >retrieving revision 1.3 >diff -u -r1.3 RegistryBackend.java >--- src/org/eclipse/pde/internal/runtime/registry/model/RegistryBackend.java 13 Feb 2009 15:38:37 -0000 1.3 >+++ src/org/eclipse/pde/internal/runtime/registry/model/RegistryBackend.java 21 May 2009 18:37:22 -0000 >@@ -16,7 +16,7 @@ > > public interface RegistryBackend { > >- public void connect(IProgressMonitor monitor); >+ public boolean connect(IProgressMonitor monitor); > > public void disconnect(); > >Index: src/org/eclipse/pde/internal/runtime/registry/model/Extension.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/Extension.java,v >retrieving revision 1.4 >diff -u -r1.4 Extension.java >--- src/org/eclipse/pde/internal/runtime/registry/model/Extension.java 25 Apr 2009 23:29:16 -0000 1.4 >+++ src/org/eclipse/pde/internal/runtime/registry/model/Extension.java 21 May 2009 18:37:21 -0000 >@@ -119,4 +119,18 @@ > return null; > return model.getBundle(contributor); > } >+ >+ public void addChild(ModelObject o) { >+ if (o instanceof ConfigurationElement) { >+ // XXX very ineffective >+ ConfigurationElement[] tmp = new ConfigurationElement[configurationElements.length + 1]; >+ System.arraycopy(configurationElements, 0, tmp, 0, configurationElements.length); >+ tmp[tmp.length - 1] = (ConfigurationElement) o; >+ configurationElements = tmp; >+ } >+ } >+ >+ public ModelObject[] getChildren() { >+ return configurationElements; >+ } > } >Index: src/org/eclipse/pde/internal/runtime/registry/model/LocalRegistryBackend.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/LocalRegistryBackend.java,v >retrieving revision 1.9 >diff -u -r1.9 LocalRegistryBackend.java >--- src/org/eclipse/pde/internal/runtime/registry/model/LocalRegistryBackend.java 30 Mar 2009 01:50:01 -0000 1.9 >+++ src/org/eclipse/pde/internal/runtime/registry/model/LocalRegistryBackend.java 21 May 2009 18:37:21 -0000 >@@ -32,13 +32,15 @@ > /* (non-Javadoc) > * @see org.eclipse.pde.internal.runtime.registry.model.local.RegistryBackend#connect() > */ >- public void connect(IProgressMonitor monitor) { >+ public boolean connect(IProgressMonitor monitor) { > if (monitor.isCanceled()) >- return; >+ return false; > > PDERuntimePlugin.getDefault().getBundleContext().addBundleListener(this); > Platform.getExtensionRegistry().addListener(this); > PDERuntimePlugin.getDefault().getBundleContext().addServiceListener(this); >+ >+ return true; > } > > /* (non-Javadoc) >@@ -299,6 +301,9 @@ > return null; > } > >+ if (bundleEntry == null) >+ return null; >+ > try { > bundleEntry = FileLocator.resolve(bundleEntry); > } catch (IOException e) { // do nothing >Index: src/org/eclipse/pde/internal/runtime/registry/model/Property.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/model/Property.java,v >retrieving revision 1.2 >diff -u -r1.2 Property.java >--- src/org/eclipse/pde/internal/runtime/registry/model/Property.java 7 Jan 2009 15:36:57 -0000 1.2 >+++ src/org/eclipse/pde/internal/runtime/registry/model/Property.java 21 May 2009 18:37:22 -0000 >@@ -131,4 +131,8 @@ > return name0.compareTo(name1); > } > >+ public String toString() { >+ return "Property(\"" + name + "\", \"" + value + "\")"; >+ } >+ > } >Index: .settings/org.eclipse.jdt.core.prefs >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/.settings/org.eclipse.jdt.core.prefs,v >retrieving revision 1.7 >diff -u -r1.7 org.eclipse.jdt.core.prefs >--- .settings/org.eclipse.jdt.core.prefs 13 Oct 2008 19:58:41 -0000 1.7 >+++ .settings/org.eclipse.jdt.core.prefs 21 May 2009 18:37:20 -0000 >@@ -1,4 +1,4 @@ >-#Mon Oct 13 14:57:59 CDT 2008 >+#Thu May 21 20:21:01 CEST 2009 > eclipse.preferences.version=1 > org.eclipse.jdt.core.builder.cleanOutputFolder=clean > org.eclipse.jdt.core.builder.duplicateResourceTask=warning >@@ -8,17 +8,17 @@ > org.eclipse.jdt.core.circularClasspath=error > org.eclipse.jdt.core.classpath.exclusionPatterns=enabled > org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled >-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled >-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 >+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled >+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 > org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve >-org.eclipse.jdt.core.compiler.compliance=1.4 >+org.eclipse.jdt.core.compiler.compliance=1.5 > org.eclipse.jdt.core.compiler.debug.lineNumber=generate > org.eclipse.jdt.core.compiler.debug.localVariable=generate > org.eclipse.jdt.core.compiler.debug.sourceFile=generate > org.eclipse.jdt.core.compiler.doc.comment.support=enabled > org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000 > org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning >-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning >+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error > org.eclipse.jdt.core.compiler.problem.autoboxing=ignore > org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning > org.eclipse.jdt.core.compiler.problem.deprecation=warning >@@ -26,7 +26,7 @@ > org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled > org.eclipse.jdt.core.compiler.problem.discouragedReference=warning > org.eclipse.jdt.core.compiler.problem.emptyStatement=warning >-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning >+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error > org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore > org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled > org.eclipse.jdt.core.compiler.problem.fieldHiding=warning >@@ -91,7 +91,7 @@ > org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error > org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning > org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning >-org.eclipse.jdt.core.compiler.source=1.3 >+org.eclipse.jdt.core.compiler.source=1.5 > org.eclipse.jdt.core.formatter.align_type_members_on_columns=false > org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 > org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/META-INF/MANIFEST.MF,v >retrieving revision 1.27 >diff -u -r1.27 MANIFEST.MF >--- META-INF/MANIFEST.MF 20 Oct 2008 22:10:47 -0000 1.27 >+++ META-INF/MANIFEST.MF 21 May 2009 18:37:20 -0000 >@@ -18,9 +18,10 @@ > Export-Package: org.eclipse.pde.internal.runtime;x-internal:=true, > org.eclipse.pde.internal.runtime.registry;x-internal:=true, > org.eclipse.pde.internal.runtime.registry.model;x-internal:=true, >+ org.eclipse.pde.internal.runtime.registry.remote.jmx;x-internal:=true, > org.eclipse.pde.internal.runtime.spy;x-internal:=true, > org.eclipse.pde.internal.runtime.spy.dialogs;x-internal:=true, > org.eclipse.pde.internal.runtime.spy.handlers;x-internal:=true, > org.eclipse.pde.internal.runtime.spy.sections;x-internal:=true >-Bundle-RequiredExecutionEnvironment: J2SE-1.4 >+Bundle-RequiredExecutionEnvironment: J2SE-1.5 > Bundle-ActivationPolicy: lazy >Index: src/org/eclipse/pde/internal/runtime/registry/RegistryBrowser.java >=================================================================== >RCS file: /cvsroot/eclipse/pde/ui/org.eclipse.pde.runtime/src/org/eclipse/pde/internal/runtime/registry/RegistryBrowser.java,v >retrieving revision 1.78 >diff -u -r1.78 RegistryBrowser.java >--- src/org/eclipse/pde/internal/runtime/registry/RegistryBrowser.java 20 May 2009 14:13:11 -0000 1.78 >+++ src/org/eclipse/pde/internal/runtime/registry/RegistryBrowser.java 21 May 2009 18:37:21 -0000 >@@ -11,8 +11,11 @@ > *******************************************************************************/ > package org.eclipse.pde.internal.runtime.registry; > >+import java.io.IOException; > import java.util.*; > import java.util.List; >+import javax.management.JMException; >+import javax.management.ObjectName; > import org.eclipse.core.runtime.*; > import org.eclipse.core.runtime.jobs.Job; > import org.eclipse.jface.action.*; >@@ -22,6 +25,8 @@ > import org.eclipse.osgi.util.NLS; > import org.eclipse.pde.internal.runtime.*; > import org.eclipse.pde.internal.runtime.registry.model.*; >+import org.eclipse.pde.internal.runtime.registry.remote.jmx.JmxAgent; >+import org.eclipse.pde.internal.runtime.registry.remote.jmx.JmxModel; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.BusyIndicator; > import org.eclipse.swt.dnd.*; >@@ -158,6 +163,7 @@ > > private void initializeModel() { > model = RegistryModelFactory.getRegistryModel("local"); //$NON-NLS-1$ >+ > fTreeViewer.setInput(model); > listener = new RegistryBrowserModelChangeListener(RegistryBrowser.this); > model.addModelChangeListener(listener); >@@ -170,6 +176,21 @@ > } > }; > initializeModelJob.schedule(); >+ initializeJMXServer(); >+ } >+ >+ public void initializeJMXServer() { >+ JmxAgent agent = new JmxAgent("localhost", 9999); //$NON-NLS-1$ >+ JmxModel jmxModel = new JmxModel(model); >+ try { >+ ObjectName jmxModelName = new ObjectName(agent.getDefaultDomain() + ":type=Bundles"); //$NON-NLS-1$ >+ agent.registryMBean(jmxModel, jmxModelName); >+ agent.startConnectionServer(); >+ } catch (IOException e) { >+ PDERuntimePlugin.log(e); >+ } catch (JMException e) { >+ PDERuntimePlugin.log(e); >+ } > } > > public void init(IViewSite site, IMemento memento) throws PartInitException { >Index: src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxClient.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxClient.java >diff -N src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxClient.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxClient.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,100 @@ >+package org.eclipse.pde.internal.runtime.registry.remote.jmx; >+ >+import java.io.IOException; >+import java.util.Iterator; >+import java.util.Set; >+import javax.management.*; >+import javax.management.remote.*; >+ >+public class JmxClient { >+ >+ protected JMXConnector jmxConnector = null; >+ protected MBeanServerConnection mbServerConnection = null; >+ >+ public JmxClient() { >+ this.createJMXConnector("localhost", 9999); >+ try { >+ this.setMbServerConnection(this.getJmxConnector().getMBeanServerConnection()); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ >+ public void startTestModelInit() { >+ String domains[] = null; >+ try { >+ domains = this.getMbServerConnection().getDomains(); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ for (int i = 0; i < domains.length; i++) { >+ System.out.println("\tDomain[" + i + "] = " + domains[i]); >+ } >+ >+ Set<ObjectName> names = null; >+ try { >+ names = this.getMbServerConnection().queryNames(null, null); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ for (Iterator<ObjectName> i = names.iterator(); i.hasNext();) { >+ ObjectName objName = i.next(); >+ System.out.println("\tObjectName = " + objName); >+ if (objName.getKeyProperty("type").equals("Bundles")) { >+ this.getAttributes(objName, this); >+ } >+ } >+ } >+ >+ private void getAttributes(ObjectName obj, JmxClient client) { >+ try { >+ /*TestClass tc = TestSerialize.deserialize( >+ (String)client.getMbServerConnection().invoke(obj, >+ "returnTest", null, null)); >+ System.out.println(tc.getId());*/ >+ System.out.println(client.getMbServerConnection().invoke(obj, "allBundles", null, null)); >+ System.out.println(); >+ System.out.println(client.getMbServerConnection().invoke(obj, "allServices", null, null)); >+ System.out.println(); >+ System.out.println(client.getMbServerConnection().invoke(obj, "allExtensionPoints", null, null)); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (InstanceNotFoundException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (MBeanException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (ReflectionException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ >+ public MBeanServerConnection getMbServerConnection() { >+ return mbServerConnection; >+ } >+ >+ public void setMbServerConnection(MBeanServerConnection mbServerConnection) { >+ this.mbServerConnection = mbServerConnection; >+ } >+ >+ protected void createJMXConnector(String host, int port) { >+ try { >+ JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/server"); >+ jmxConnector = JMXConnectorFactory.connect(url, null); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ >+ public JMXConnector getJmxConnector() { >+ return jmxConnector; >+ } >+ >+} >Index: src/org/eclipse/pde/internal/runtime/registry/model/ModelSerializer.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/runtime/registry/model/ModelSerializer.java >diff -N src/org/eclipse/pde/internal/runtime/registry/model/ModelSerializer.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/runtime/registry/model/ModelSerializer.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,356 @@ >+package org.eclipse.pde.internal.runtime.registry.model; >+ >+import java.util.*; >+import org.xml.sax.Attributes; >+import org.xml.sax.SAXException; >+import org.xml.sax.helpers.DefaultHandler; >+ >+public class ModelSerializer { >+ >+ private static final String BUNDLE = "bundle"; //$NON-NLS-1$ >+ private static final String USING_BUNDLES = "usingBundles"; //$NON-NLS-1$ >+ private static final String CLASSES = "classes"; //$NON-NLS-1$ >+ private static final String EXTENSION_POINT_UNIQUE_IDENTIFIER = "extensionPointUniqueIdentifier"; //$NON-NLS-1$ >+ private static final String CONTRIBUTOR = "contributor"; //$NON-NLS-1$ >+ private static final String LABEL = "label"; //$NON-NLS-1$ >+ private static final String UNIQUE_IDENTIFIER = "uniqueIdentifier"; //$NON-NLS-1$ >+ private static final String NAMESPACE_IDENTIFIER = "namespaceIdentifier"; //$NON-NLS-1$ >+ private static final String IS_EXPORTED = "isExported"; //$NON-NLS-1$ >+ private static final String LIBRARY = "library"; //$NON-NLS-1$ >+ private static final String ID = "id"; //$NON-NLS-1$ >+ private static final String STATE = "state"; //$NON-NLS-1$ >+ private static final String VERSION = "version"; //$NON-NLS-1$ >+ private static final String IS_ENABLED = "isEnabled"; //$NON-NLS-1$ >+ private static final String LOCATION = "location"; //$NON-NLS-1$ >+ private static final String SYMBOLIC_NAME = "symbolicName"; //$NON-NLS-1$ >+ private static final String VALUE = "value"; //$NON-NLS-1$ >+ private static final String NAME = "name"; //$NON-NLS-1$ >+ private static final String FLAG = "flag"; //$NON-NLS-1$ >+ >+ public static abstract class XMLHandler extends DefaultHandler { >+ >+ private Stack stack = new Stack(); >+ >+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { >+ if (qName.equals("start")) //$NON-NLS-1$ >+ return; >+ >+ ModelObject o = create(qName); >+ if (o == null) >+ return; >+ >+ for (int i = 0; i < attributes.getLength(); i++) { >+ set(o, attributes.getQName(i), attributes.getValue(i)); >+ } >+ >+ if (!(o instanceof ModelChangeDelta)) { >+ ((ModelObject) stack.peek()).addChild(o); >+ } >+ >+ //System.out.println("push " + o); //XXX remove syso >+ stack.push(o); >+ >+ } >+ >+ public void endElement(String uri, String localName, String qName) throws SAXException { >+ if (qName.equals("start")) >+ return; >+ >+ //System.out.print("pop "); //XXX remove syso >+ ModelObject o = (ModelObject) stack.pop(); >+ //System.out.println(o); //XXX remove syso >+ >+ if (o instanceof ModelChangeDelta) { >+ handleDelta((ModelChangeDelta) o); >+ } >+ } >+ >+ public abstract void handleDelta(ModelChangeDelta delta); >+ >+ } >+ >+ protected static void set(ModelObject o, String name, String value) { >+ if (o instanceof Attribute) { >+ Attribute attribute = (Attribute) o; >+ if (NAME.equals(name)) { >+ attribute.setName(value); >+ } else if (VALUE.equals(name)) { >+ attribute.setValue(value); >+ } >+ >+ } else if (o instanceof Bundle) { >+ Bundle bundle = (Bundle) o; >+ >+ if (SYMBOLIC_NAME.equals(name)) { >+ bundle.setSymbolicName(value); >+ } else if (LOCATION.equals(name)) { >+ bundle.setLocation(value); >+ } else if (IS_ENABLED.equals(name)) { >+ bundle.setEnabled(Boolean.valueOf(value).booleanValue()); >+ } else if (VERSION.equals(name)) { >+ bundle.setVersion(value); >+ } else if (STATE.equals(name)) { >+ bundle.setState(Integer.parseInt(value)); >+ } else if (ID.equals(name)) { >+ bundle.setId(Long.parseLong(value)); >+ } >+ >+ } else if (o instanceof BundleLibrary) { >+ BundleLibrary library = (BundleLibrary) o; >+ if (LIBRARY.equals(name)) { >+ library.setLibrary(value); >+ } >+ >+ } else if (o instanceof BundlePrerequisite) { >+ BundlePrerequisite prereq = (BundlePrerequisite) o; >+ if (NAME.equals(name)) { >+ prereq.setName(value); >+ } else if (VERSION.equals(name)) { >+ prereq.setVersion(value); >+ } else if (IS_EXPORTED.equals(name)) { >+ prereq.setExported(Boolean.valueOf(value).booleanValue()); >+ } >+ >+ } else if (o instanceof Extension) { >+ Extension ext = (Extension) o; >+ if (NAMESPACE_IDENTIFIER.equals(name)) { >+ ext.setNamespaceIdentifier(value); >+ } else if (LABEL.equals(name)) { >+ ext.setLabel(value); >+ } else if (EXTENSION_POINT_UNIQUE_IDENTIFIER.equals(name)) { >+ ext.setExtensionPointUniqueIdentifier(value); >+ } else if (CONTRIBUTOR.equals(name)) { >+ ext.setContributor(Long.valueOf(value)); >+ } >+ >+ } else if (o instanceof ExtensionPoint) { >+ ExtensionPoint extPt = (ExtensionPoint) o; >+ if (LABEL.equals(name)) { >+ extPt.setLabel(value); >+ } else if (UNIQUE_IDENTIFIER.equals(name)) { >+ extPt.setUniqueIdentifier(value); >+ } else if (NAMESPACE_IDENTIFIER.equals(name)) { >+ extPt.setNamespaceIdentifier(value); >+ } else if (CONTRIBUTOR.equals(name)) { >+ extPt.setContributor(Long.valueOf(value)); >+ } >+ >+ } else if (o instanceof ServiceRegistration) { >+ ServiceRegistration service = (ServiceRegistration) o; >+ if (ID.equals(name)) { >+ service.setId(Long.parseLong(value)); >+ } else if (BUNDLE.equals(name)) { >+ service.setBundle(value); >+ } else if (USING_BUNDLES.equals(name)) { >+ StringTokenizer st = new StringTokenizer(value, ","); >+ List l = new ArrayList(); >+ while (st.hasMoreTokens()) { >+ l.add(Long.valueOf(st.nextToken())); >+ } >+ long[] ids = new long[l.size()]; >+ for (int i = 0; i < l.size(); i++) { >+ ids[i] = ((Long) l.get(i)).longValue(); >+ } >+ service.setUsingBundles(ids); >+ } else if (CLASSES.equals(name)) { >+ StringTokenizer st = new StringTokenizer(value, ","); >+ List l = new ArrayList(); >+ while (st.hasMoreTokens()) { >+ l.add(st.nextToken()); >+ } >+ >+ ServiceName sn = new ServiceName((String[]) l.toArray(new String[l.size()])); >+ service.setName(sn); >+ } >+ } else if (o instanceof Property) { >+ Property property = (Property) o; >+ if (NAME.equals(name)) { >+ property.setName(value); >+ } else if (VALUE.equals(name)) { >+ property.setValue(value); >+ } >+ >+ } else if (o instanceof ModelChangeDelta) { >+ ModelChangeDelta delta = (ModelChangeDelta) o; >+ >+ if (FLAG.equals(name)) { >+ delta.setFlag(Integer.parseInt(value)); >+ } >+ } >+ } >+ >+ protected static void addAttribute(StringBuffer sb, String name, String value) { >+ if (value == null) >+ return; >+ >+ sb.append(" ").append(name).append("=\"").append(getWritableString(value)).append("\""); >+ } >+ >+ protected static void addAttributes(StringBuffer sb, ModelObject o) { >+ >+ if (o instanceof Attribute) { >+ Attribute attribute = (Attribute) o; >+ addAttribute(sb, NAME, attribute.getName()); >+ addAttribute(sb, VALUE, attribute.getValue()); >+ >+ } else if (o instanceof Bundle) { >+ Bundle bundle = (Bundle) o; >+ >+ addAttribute(sb, SYMBOLIC_NAME, bundle.getSymbolicName()); >+ addAttribute(sb, LOCATION, bundle.getLocation()); >+ addAttribute(sb, IS_ENABLED, Boolean.toString(bundle.isEnabled())); >+ addAttribute(sb, VERSION, bundle.getVersion()); >+ addAttribute(sb, STATE, Integer.toString(bundle.getState())); >+ addAttribute(sb, ID, Long.toString(bundle.getId())); >+ >+ } else if (o instanceof BundleLibrary) { >+ BundleLibrary library = (BundleLibrary) o; >+ addAttribute(sb, LIBRARY, library.getLibrary()); >+ >+ } else if (o instanceof BundlePrerequisite) { >+ BundlePrerequisite prereq = (BundlePrerequisite) o; >+ addAttribute(sb, NAME, prereq.getName()); >+ addAttribute(sb, VERSION, prereq.getVersion()); >+ addAttribute(sb, IS_EXPORTED, Boolean.toString(prereq.isExported())); >+ >+ } else if (o instanceof Extension) { >+ Extension ext = (Extension) o; >+ addAttribute(sb, NAMESPACE_IDENTIFIER, ext.getNamespaceIdentifier()); >+ addAttribute(sb, LABEL, ext.getLabel()); >+ addAttribute(sb, EXTENSION_POINT_UNIQUE_IDENTIFIER, ext.getExtensionPointUniqueIdentifier()); >+ Long id = ext.getContributorId(); >+ if (id != null) >+ addAttribute(sb, CONTRIBUTOR, id.toString()); >+ >+ } else if (o instanceof ExtensionPoint) { >+ ExtensionPoint extPt = (ExtensionPoint) o; >+ addAttribute(sb, LABEL, extPt.getLabel()); >+ addAttribute(sb, UNIQUE_IDENTIFIER, extPt.getUniqueIdentifier()); >+ addAttribute(sb, NAMESPACE_IDENTIFIER, extPt.getNamespaceIdentifier()); >+ Long id = extPt.getContributorId(); >+ if (id != null) >+ addAttribute(sb, CONTRIBUTOR, id.toString()); >+ >+ } else if (o instanceof ServiceRegistration) { >+ ServiceRegistration service = (ServiceRegistration) o; >+ addAttribute(sb, ID, Long.toString(service.getId())); >+ addAttribute(sb, BUNDLE, service.getBundle()); >+ addAttribute(sb, USING_BUNDLES, arrayToString(service.getUsingBundleIds())); >+ addAttribute(sb, CLASSES, arrayToString(service.getName().getClasses())); >+ >+ } else if (o instanceof Property) { >+ Property property = (Property) o; >+ addAttribute(sb, NAME, property.getName()); >+ addAttribute(sb, VALUE, property.getValue()); >+ >+ } else if (o instanceof ModelChangeDelta) { >+ ModelChangeDelta delta = (ModelChangeDelta) o; >+ addAttribute(sb, FLAG, Integer.toString(delta.getFlag())); >+ } >+ } >+ >+ private static String arrayToString(Object[] array) { >+ StringBuffer sb = new StringBuffer(); >+ for (int i = 0; i < array.length; i++) { >+ if (i > 0) >+ sb.append(','); >+ sb.append(array[i]); >+ } >+ >+ return sb.toString(); >+ } >+ >+ private static String arrayToString(long[] array) { >+ StringBuffer sb = new StringBuffer(); >+ for (int i = 0; i < array.length; i++) { >+ if (i > 0) >+ sb.append(','); >+ sb.append(array[i]); >+ } >+ >+ return sb.toString(); >+ } >+ >+ private static ModelObject create(String name) { >+ if (Attribute.class.getName().equals(name)) { >+ return new Attribute(); >+ } else if (Bundle.class.getName().equals(name)) { >+ return new Bundle(); >+ } else if (BundleLibrary.class.getName().equals(name)) { >+ return new BundleLibrary(); >+ } else if (BundlePrerequisite.class.getName().equals(name)) { >+ return new BundlePrerequisite(); >+ } else if (ConfigurationElement.class.getName().equals(name)) { >+ return new ConfigurationElement(); >+ } else if (Extension.class.getName().equals(name)) { >+ return new Extension(); >+ } else if (ExtensionPoint.class.getName().equals(name)) { >+ return new ExtensionPoint(); >+ } else if (ModelChangeDelta.class.getName().equals(name)) { >+ return new ModelChangeDelta(); >+ } else if (ServiceRegistration.class.getName().equals(name)) { >+ return new ServiceRegistration(); >+ } else if (Property.class.getName().equals(name)) { >+ return new Property(); >+ } >+ >+ return null; >+ } >+ >+ public static String serialize(ModelObject o) { >+ return serialize(o, new StringBuffer()); >+ } >+ >+ // XXX From PDEXMLHelper >+ private static String getWritableString(String source) { >+ if (source == null) >+ return ""; //$NON-NLS-1$ >+ StringBuffer buf = new StringBuffer(); >+ for (int i = 0; i < source.length(); i++) { >+ char c = source.charAt(i); >+ switch (c) { >+ case '&' : >+ buf.append("&"); //$NON-NLS-1$ >+ break; >+ case '<' : >+ buf.append("<"); //$NON-NLS-1$ >+ break; >+ case '>' : >+ buf.append(">"); //$NON-NLS-1$ >+ break; >+ case '\'' : >+ buf.append("'"); //$NON-NLS-1$ >+ break; >+ case '\"' : >+ buf.append("""); //$NON-NLS-1$ >+ break; >+ default : >+ buf.append(c); >+ break; >+ } >+ } >+ return buf.toString(); >+ } >+ >+ private static String serialize(ModelObject o, StringBuffer sb) { >+ String className = o.getClass().getName(); >+ sb.append('<').append(className); >+ >+ addAttributes(sb, o); >+ >+ sb.append('>').append('\n'); >+ >+ ModelObject[] children = o.getChildren(); >+ >+ if (children != null) { >+ for (int i = 0; i < children.length; i++) { >+ if (children[i] != null) >+ serialize(children[i], sb); >+ } >+ } >+ >+ sb.append("</").append(className).append('>').append('\n'); //$NON-NLS-1$ >+ >+ return sb.toString(); >+ } >+} >Index: src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxModel.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxModel.java >diff -N src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxModel.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxModel.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+package org.eclipse.pde.internal.runtime.registry.remote.jmx; >+ >+import org.eclipse.pde.internal.runtime.registry.model.*; >+ >+public class JmxModel implements JmxModelMBean { >+ >+ private RegistryModel model; >+ >+ public JmxModel(RegistryModel model) { >+ super(); >+ this.model = model; >+ } >+ >+ public String allBundles() { >+ Bundle[] bundles = model.getBundles(); >+ String result = ""; //$NON-NLS-1$ >+ for (int i = 0; i < bundles.length; i++) { >+ result += ModelSerializer.serialize(bundles[i]); >+ } >+ return result; >+ } >+ >+ public String allServices() { >+ ServiceRegistration[] services = model.getServices(); >+ String result = ""; //$NON-NLS-1$ >+ for (int i = 0; i < services.length; i++) { >+ result += ModelSerializer.serialize(services[i]); >+ } >+ return result; >+ } >+ >+ public String allExtensionPoints() { >+ ExtensionPoint[] exPoints = model.getExtensionPoints(); >+ String result = ""; //$NON-NLS-1$ >+ for (int i = 0; i < exPoints.length; i++) { >+ result += ModelSerializer.serialize(exPoints[i]); >+ } >+ return result; >+ } >+} >Index: src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxAgent.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxAgent.java >diff -N src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxAgent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxAgent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,165 @@ >+package org.eclipse.pde.internal.runtime.registry.remote.jmx; >+ >+import java.io.IOException; >+import java.lang.management.ManagementFactory; >+import java.rmi.RemoteException; >+import java.rmi.registry.LocateRegistry; >+import java.rmi.registry.Registry; >+import java.util.Map; >+import java.util.Map.Entry; >+import javax.management.*; >+import javax.management.remote.*; >+ >+public class JmxAgent { >+ private MBeanServer server = null; >+ private JMXConnectorServer connectionServer = null; >+ Registry registry = null; >+ private boolean isDebug = true; >+ >+ public JmxAgent(String host, int port) { >+ createMBeanServer(); >+ createRMIRegistry(port); >+ createJMXConnectionServer(host, port); >+ } >+ >+ private void createMBeanServer() { >+ print("CREATE the MBeanServer"); //$NON-NLS-1$ >+ server = ManagementFactory.getPlatformMBeanServer(); >+ } >+ >+ private void createJMXConnectionServer(String host, int port) { >+ try { >+ JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/server"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ connectionServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ >+ private void createRMIRegistry(int port) { >+ try { >+ registry = LocateRegistry.createRegistry(port); >+ } catch (RemoteException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ >+ public String getDefaultDomain() { >+ >+ return server.getDefaultDomain(); >+ } >+ >+ public void startConnectionServer() throws IOException { >+ connectionServer.start(); >+ print("connected"); //$NON-NLS-1$ >+ } >+ >+ public void stopConnectionServer() throws IOException { >+ connectionServer.stop(); >+ print("disconnected"); //$NON-NLS-1$ >+ } >+ >+ public void registryMBean(Object mBean, Map<String, String> params) throws JMException { >+ String paramString = ":"; //$NON-NLS-1$ >+ int i = 1; >+ for (Entry<String, String> element : params.entrySet()) { >+ paramString += element.getKey() + "=" + element.getValue(); //$NON-NLS-1$ >+ i++; >+ if (params.size() > i) >+ paramString += ","; //$NON-NLS-1$ >+ } >+ ObjectName on = new ObjectName(server.getDefaultDomain() + paramString); >+ server.registerMBean(mBean, on); >+ print("registered: " + on.toString()); //$NON-NLS-1$ >+ } >+ >+ public void registryMBean(Object mBean, String params) throws JMException { >+ ObjectName on = new ObjectName(server.getDefaultDomain() + ":" + params); //$NON-NLS-1$ >+ server.registerMBean(mBean, on); >+ print("registered: " + on.toString()); //$NON-NLS-1$ >+ } >+ >+ public void registryMBean(Object mBean, ObjectName on) throws JMException { >+ server.registerMBean(mBean, on); >+ print("registered: " + on.toString()); //$NON-NLS-1$ >+ } >+ >+ public void printMBeanInfo(ObjectName objectName, String className) { >+ print("information about: " + objectName.toString()); //$NON-NLS-1$ >+ MBeanInfo info = null; >+ try { >+ info = server.getMBeanInfo(objectName); >+ } catch (Exception e) { >+ print("Could not get MBeanInfo object for " + className); //$NON-NLS-1$ >+ e.printStackTrace(); >+ return; >+ } >+ print("classname: " + info.getClassName()); //$NON-NLS-1$ >+ print("description: " + info.getDescription()); //$NON-NLS-1$ >+ >+ print("attributes: "); //$NON-NLS-1$ >+ MBeanAttributeInfo[] attrInfo = info.getAttributes(); >+ if (attrInfo.length > 0) { >+ for (int i = 0; i < attrInfo.length; i++) { >+ print("\tname: " + attrInfo[i].getName()); //$NON-NLS-1$ >+ print("\tdescription: " + attrInfo[i].getDescription()); //$NON-NLS-1$ >+ print("\ttype: " + attrInfo[i].getType()); //$NON-NLS-1$ >+ print("\treadable: " + attrInfo[i].isReadable()); //$NON-NLS-1$ >+ print("\twritable: " + attrInfo[i].isWritable()); //$NON-NLS-1$ >+ print("\n"); //$NON-NLS-1$ >+ } >+ } else { >+ print("no attributes\n"); //$NON-NLS-1$ >+ } >+ >+ print("constructors: "); //$NON-NLS-1$ >+ MBeanConstructorInfo[] constructorInfo = info.getConstructors(); >+ if (constructorInfo.length > 0) { >+ for (int i = 0; i < constructorInfo.length; i++) { >+ print("\tname: " + constructorInfo[i].getName()); //$NON-NLS-1$ >+ print("\tdescription: " + constructorInfo[i].getDescription()); //$NON-NLS-1$ >+ print("\tparameter number: " + constructorInfo[i].getSignature().length); //$NON-NLS-1$ >+ print("\n"); //$NON-NLS-1$ >+ } >+ } else { >+ print("no constructors\n"); //$NON-NLS-1$ >+ } >+ >+ print("operations: "); //$NON-NLS-1$ >+ MBeanOperationInfo[] opInfo = info.getOperations(); >+ if (opInfo.length > 0) { >+ for (int i = 0; i < opInfo.length; i++) { >+ print("\tname: " + opInfo[i].getName()); //$NON-NLS-1$ >+ print("\tdescription: " + opInfo[i].getDescription()); //$NON-NLS-1$ >+ print("\tparameter number: " + opInfo[i].getSignature().length); //$NON-NLS-1$ >+ print("\n"); //$NON-NLS-1$ >+ } >+ } else { >+ print("no operations\n"); //$NON-NLS-1$ >+ } >+ >+ print("notifications: "); //$NON-NLS-1$ >+ MBeanNotificationInfo[] notifInfo = info.getNotifications(); >+ if (notifInfo.length > 0) { >+ for (int i = 0; i < notifInfo.length; i++) { >+ print("\tname: " + notifInfo[i].getName()); //$NON-NLS-1$ >+ print("\tdescription: " + notifInfo[i].getDescription()); //$NON-NLS-1$ >+ String notifTypes[] = notifInfo[i].getNotifTypes(); >+ for (int j = 0; j < notifTypes.length; j++) { >+ print("\t\ttype:" + notifTypes[j]); //$NON-NLS-1$ >+ } >+ print("\n"); //$NON-NLS-1$ >+ } >+ } else { >+ print("no notifications\n"); //$NON-NLS-1$ >+ } >+ } >+ >+ private void print(String s) { >+ if (isDebug) { >+ System.out.println(s); >+ } >+ } >+} >\ No newline at end of file >Index: src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxModelMBean.java >=================================================================== >RCS file: src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxModelMBean.java >diff -N src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxModelMBean.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/pde/internal/runtime/registry/remote/jmx/JmxModelMBean.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,10 @@ >+package org.eclipse.pde.internal.runtime.registry.remote.jmx; >+ >+ >+public interface JmxModelMBean { >+ public String allBundles(); >+ >+ public String allServices(); >+ >+ public String allExtensionPoints(); >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 274980
:
136698
|
141643
|
141644