You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/06/21 17:00:06 UTC
svn commit: r416002 [1/2] - in
/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi:
container/ deployment/impl/ framework/ loaders/
Author: gnodet
Date: Wed Jun 21 08:00:03 2006
New Revision: 416002
URL: http://svn.apache.org/viewvc?rev=416002&view=rev
Log:
SM-465: improve support for shared libraries
Import XBEAN-22 patch until it is released
Added:
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SharedLibrary.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SharedLibraryMBean.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/AbstractResourceHandle.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/AbstractUrlResourceLocation.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DestroyableClassLoader.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DirectoryResourceHandle.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DirectoryResourceLocation.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/IoUtil.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/JarFileClassLoader.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/JarFileUrlConnection.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/JarFileUrlStreamHandler.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/JarResourceHandle.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/JarResourceLocation.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/MultiParentClassLoader.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/NamedClassLoader.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ResourceEnumeration.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ResourceFinder.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ResourceHandle.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ResourceLocation.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ThreadContextClassLoaderFactoryBean.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/UnionEnumeration.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/UrlResourceFinder.java
Removed:
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderService.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/InstallationClassLoader.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ParentFirstClassLoader.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/SelfFirstClassLoader.java
Modified:
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/deployment/impl/ComponentElementProcessor.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsService.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentMBeanImpl.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentRegistry.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationContextImpl.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationService.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallerMBeanImpl.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java
incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderUtil.java
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/container/JBIContainer.java Wed Jun 21 08:00:03 2006
@@ -53,6 +53,7 @@
import org.apache.servicemix.components.util.PojoLifecycleAdaptor;
import org.apache.servicemix.components.util.PojoSupport;
import org.apache.servicemix.id.IdGenerator;
+import org.apache.servicemix.jbi.deployment.SharedLibraryList;
import org.apache.servicemix.jbi.event.ComponentListener;
import org.apache.servicemix.jbi.event.EndpointListener;
import org.apache.servicemix.jbi.event.ExchangeEvent;
@@ -425,7 +426,7 @@
* @throws DeploymentException
*/
public void installArchive(String url) throws DeploymentException {
- installationService.install(url, true);
+ installationService.install(url, null, true);
}
/**
@@ -804,7 +805,11 @@
* @throws JBIException
*/
public Logger getLogger(String suffix, String resourceBundleName) throws MissingResourceException, JBIException {
- return Logger.getLogger(suffix, resourceBundleName);
+ try {
+ return Logger.getLogger(suffix, resourceBundleName);
+ } catch (IllegalArgumentException e) {
+ throw new JBIException("A logger can not be created using resource bundle " + resourceBundleName);
+ }
}
/**
@@ -943,7 +948,7 @@
* @throws JBIException
*/
public ObjectName activateComponent(Component component, ActivationSpec activationSpec) throws JBIException {
- return activateComponent(component, "POJO Component", activationSpec, true, false, false);
+ return activateComponent(component, "POJO Component", activationSpec, true, false, false, null);
}
/**
@@ -959,12 +964,13 @@
* @throws JBIException
*/
public ObjectName activateComponent(File installDir, Component component, String description,
- ComponentContextImpl context, boolean binding, boolean service) throws JBIException {
+ ComponentContextImpl context, boolean binding, boolean service,
+ String[] sharedLibraries) throws JBIException {
ComponentNameSpace cns = context.getComponentNameSpace();
ActivationSpec activationSpec = new ActivationSpec();
activationSpec.setComponent(component);
activationSpec.setComponentName(cns.getName());
- return activateComponent(installDir, component, description, context, activationSpec, false, binding, service);
+ return activateComponent(installDir, component, description, context, activationSpec, false, binding, service, sharedLibraries);
}
/**
@@ -978,13 +984,14 @@
* @throws JBIException
*/
public ObjectName activateComponent(Component component, String description, ActivationSpec activationSpec,
- boolean pojo, boolean binding, boolean service) throws JBIException {
+ boolean pojo, boolean binding, boolean service,
+ String[] sharedLibraries) throws JBIException {
ComponentNameSpace cns = new ComponentNameSpace(getName(), activationSpec.getComponentName());
if (registry.getComponent(cns) != null) {
throw new JBIException("A component is already registered for " + cns);
}
ComponentContextImpl context = new ComponentContextImpl(this, cns);
- return activateComponent(new File("."), component, description, context, activationSpec, pojo, binding, service);
+ return activateComponent(new File("."), component, description, context, activationSpec, pojo, binding, service, sharedLibraries);
}
/**
@@ -1000,7 +1007,9 @@
* @throws JBIException
*/
public ObjectName activateComponent(File installationDir, Component component, String description,
- ComponentContextImpl context, ActivationSpec activationSpec, boolean pojo, boolean binding, boolean service)
+ ComponentContextImpl context, ActivationSpec activationSpec,
+ boolean pojo, boolean binding, boolean service,
+ String[] sharedLibraries)
throws JBIException {
ObjectName result = null;
ComponentNameSpace cns = new ComponentNameSpace(getName(), activationSpec.getComponentName());
@@ -1008,7 +1017,7 @@
log.info("Activating component for: " + cns + " with service: " + activationSpec.getService() + " component: "
+ component);
}
- ComponentMBeanImpl lcc = registry.registerComponent(cns, description, component, binding, service);
+ ComponentMBeanImpl lcc = registry.registerComponent(cns, description, component, binding, service, sharedLibraries);
if (lcc != null) {
lcc.setPojo(pojo);
ComponentEnvironment env = environmentContext.registerComponent(context.getEnvironment(),lcc);
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/deployment/impl/ComponentElementProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/deployment/impl/ComponentElementProcessor.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/deployment/impl/ComponentElementProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/deployment/impl/ComponentElementProcessor.java Wed Jun 21 08:00:03 2006
@@ -49,7 +49,7 @@
Element property = addPropertyElement(element, "sharedLibraries");
Element list = addElement(property, "list");
- DocumentFragment fragment = element.getOwnerDocument().createDocumentFragment();
+ DocumentFragment fragment = null;
Node current = element.getFirstChild();
while (current != null) {
@@ -59,6 +59,9 @@
String uri = node.getNamespaceURI();
if (!JbiNamespaceProcessor.JBI_NAMESPACE.equals(uri) && node != property) {
element.removeChild(node);
+ if (fragment == null) {
+ fragment = element.getOwnerDocument().createDocumentFragment();
+ }
fragment.appendChild(node);
}
else if ("shared-library".equals(node.getNodeName())) {
@@ -70,15 +73,17 @@
}
}
- Element descriptorProperty = addPropertyElement(element, "descriptorExtension");
- descriptorProperty.setAttribute("ref", "installationDescriptorExtension");
-
- // lets find all elements which are not in the JBI namespace
- Map propertiesMap = new HashMap();
- propertiesMap.put("descriptorExtension", fragment);
- RootBeanDefinition definition = new RootBeanDefinition(InstallationDescriptorExtension.class, new MutablePropertyValues(propertiesMap));
- beanDefinitionReader.getBeanFactory().registerBeanDefinition("installationDescriptorExtension", definition);
-
+ if (fragment != null) {
+ Element descriptorProperty = addPropertyElement(element, "descriptorExtension");
+ descriptorProperty.setAttribute("ref", "installationDescriptorExtension");
+
+ // lets find all elements which are not in the JBI namespace
+ Map propertiesMap = new HashMap();
+ propertiesMap.put("descriptorExtension", fragment);
+ RootBeanDefinition definition = new RootBeanDefinition(InstallationDescriptorExtension.class, new MutablePropertyValues(propertiesMap));
+ beanDefinitionReader.getBeanFactory().registerBeanDefinition("installationDescriptorExtension", definition);
+ }
+
super.processElement(element, beanDefinitionReader);
}
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsService.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsService.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsService.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsService.java Wed Jun 21 08:00:03 2006
@@ -17,11 +17,13 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import javax.jbi.JBIException;
+import javax.jbi.management.LifeCycleMBean;
import javax.management.JMException;
import javax.management.MBeanOperationInfo;
@@ -61,7 +63,7 @@
*/
public String installComponent(String file, Properties props) throws Exception {
try {
- container.getInstallationService().install(file);
+ container.getInstallationService().install(file, props, false);
return ManagementSupport.createSuccessMessage("installComponent", file);
} catch (Exception e) {
throw ManagementSupport.failure("installComponent", file, e);
@@ -75,6 +77,13 @@
* @return
*/
public String uninstallComponent(String name) throws Exception {
+ ComponentMBeanImpl comp = container.getComponent(name);
+ if (comp == null) {
+ throw ManagementSupport.failure("uninstallComponent", "Component '" + name + "' is not installed.");
+ }
+ if (!comp.isShutDown()) {
+ throw ManagementSupport.failure("uninstallComponent", "Component '" + name + "' is not shut down.");
+ }
boolean success = container.getInstallationService().unloadInstaller(name, true);
if (success) {
return success("uninstallComponent", name);
@@ -100,6 +109,26 @@
* @return
*/
public String uninstallSharedLibrary(String name) throws Exception {
+ // Check that the library is installed
+ SharedLibrary sl = container.getRegistry().getSharedLibrary(name);
+ if (sl == null) {
+ throw ManagementSupport.failure("uninstallSharedLibrary", "Shared library '" + name + "' is not installed.");
+ }
+ // Check that it is not used by a running component
+ Collection components = container.getRegistry().getComponents();
+ for (Iterator iter = components.iterator(); iter.hasNext();) {
+ ComponentMBeanImpl comp = (ComponentMBeanImpl) iter.next();
+ if (!comp.isShutDown()) {
+ String[] sls = comp.getSharedLibraries();
+ if (sls != null) {
+ for (int i = 0; i < sls.length; i++) {
+ if (name.equals(sls[i])) {
+ throw ManagementSupport.failure("uninstallSharedLibrary", "Shared library '" + name + "' is used by component '" + comp.getName() + "'.");
+ }
+ }
+ }
+ }
+ }
boolean success = container.getInstallationService().uninstallSharedLibrary(name);
if (success) {
return success("uninstallSharedLibrary", name);
@@ -249,6 +278,16 @@
String requiredState,
String sharedLibraryName,
String serviceAssemblyName) throws Exception {
+ // validate requiredState
+ if (requiredState != null && requiredState.length() > 0) {
+ if (!LifeCycleMBean.UNKNOWN.equalsIgnoreCase(requiredState) &&
+ !LifeCycleMBean.SHUTDOWN.equalsIgnoreCase(requiredState) &&
+ !LifeCycleMBean.STOPPED.equalsIgnoreCase(requiredState) &&
+ !LifeCycleMBean.STARTED.equalsIgnoreCase(requiredState)) {
+ throw ManagementSupport.failure("listComponents", "Required state '" + requiredState + "' is not a valid state.");
+ }
+ }
+ // Get components
Collection connectors = container.getRegistry().getComponents();
List components = new ArrayList();
for (Iterator iter = connectors.iterator(); iter.hasNext();) {
@@ -266,7 +305,7 @@
continue;
}
// Check status
- if (requiredState != null && requiredState.length() > 0 && !requiredState.equals(component.getCurrentState())) {
+ if (requiredState != null && requiredState.length() > 0 && !requiredState.equalsIgnoreCase(component.getCurrentState())) {
continue;
}
// Check shared library
@@ -297,7 +336,7 @@
buffer.append("<component-info-list xmlns='http://java.sun.com/xml/ns/jbi/component-info-list' version='1.0'>\n");
for (Iterator iter = components.iterator(); iter.hasNext();) {
ComponentMBeanImpl component = (ComponentMBeanImpl) iter.next();
- buffer.append(" <component-info>");
+ buffer.append(" <component-info");
if (!component.isBinding() && component.isService()) {
buffer.append(" type='service-engine'");
} else if (component.isBinding() && !component.isService()) {
@@ -308,7 +347,7 @@
if (component.getDescription() != null) {
buffer.append(" <description>");
buffer.append(component.getDescription());
- buffer.append("<description>\n");
+ buffer.append("</description>\n");
}
buffer.append(" </component-info>\n");
}
@@ -324,8 +363,37 @@
* @return
*/
public String listSharedLibraries(String componentName, String sharedLibraryName) throws Exception {
- // TODO Auto-generated method stub
- return null;
+ Collection libs;
+ if (sharedLibraryName != null) {
+ SharedLibrary sl = container.getRegistry().getSharedLibrary(sharedLibraryName);
+ if (sl == null) {
+ libs = Collections.EMPTY_LIST;
+ } else {
+ libs = Collections.singletonList(sl);
+ }
+ } else if (componentName != null) {
+ // TODO: handle componentName
+ libs = container.getRegistry().getSharedLibraries();
+ } else {
+ libs = container.getRegistry().getSharedLibraries();
+ }
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<?xml version='1.0'?>\n");
+ buffer.append("<component-info-list xmlns='http://java.sun.com/xml/ns/jbi/component-info-list' version='1.0'>\n");
+ for (Iterator iter = libs.iterator(); iter.hasNext();) {
+ SharedLibrary sl = (SharedLibrary) iter.next();
+ buffer.append(" <component-info type='shared-library' name='")
+ .append(sl.getName())
+ .append("' state='Started'>");
+ if (sl.getDescription() != null) {
+ buffer.append(" <description>");
+ buffer.append(sl.getDescription());
+ buffer.append("</description>\n");
+ }
+ buffer.append(" </component-info>\n");
+ }
+ buffer.append("</component-info-list>");
+ return buffer.toString();
}
/**
@@ -358,7 +426,7 @@
StringBuffer buffer = new StringBuffer();
buffer.append("<?xml version='1.0'?>\n");
- buffer.append("<service-assembly-info-list xmlns='http://java.sun.com/xml/ns/jbi/component-info-list' version='1.0'>\n");
+ buffer.append("<service-assembly-info-list xmlns='http://java.sun.com/xml/ns/jbi/service-assembly-info-list' version='1.0'>\n");
for (Iterator iter = assemblies.iterator(); iter.hasNext();) {
ServiceAssemblyLifeCycle sa = (ServiceAssemblyLifeCycle) iter.next();
buffer.append(" <service-assembly-info");
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AutoDeploymentService.java Wed Jun 21 08:00:03 2006
@@ -218,7 +218,7 @@
entry.type = "component";
entry.name = componentName;
installationService.unloadInstaller(componentName, true);
- installationService.install(tmpDir, root, autoStart);
+ installationService.install(tmpDir, null, root, autoStart);
checkPendingSAs();
} else if (root.getSharedLibrary() != null) {
String libraryName = root.getSharedLibrary().getIdentification().getName();
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentMBeanImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentMBeanImpl.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentMBeanImpl.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentMBeanImpl.java Wed Jun 21 08:00:03 2006
@@ -34,6 +34,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.container.ActivationSpec;
import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.deployment.SharedLibraryList;
import org.apache.servicemix.jbi.event.ComponentEvent;
import org.apache.servicemix.jbi.event.ComponentListener;
import org.apache.servicemix.jbi.management.AttributeInfoHelper;
@@ -71,6 +72,7 @@
private boolean binding;
private boolean service;
private File stateFile;
+ private String[] sharedLibraries;
/**
* Construct with it's id and delivery channel Id
@@ -87,7 +89,8 @@
String description,
Component component,
boolean binding,
- boolean service) {
+ boolean service,
+ String[] sharedLibraries) {
this.componentName = name;
this.container = container;
this.component = component;
@@ -96,6 +99,7 @@
this.service = service;
this.componentStatsMBean = new ComponentStats(this);
this.messagingStats = new MessagingStats(name.getName());
+ this.sharedLibraries = sharedLibraries;
}
/**
@@ -658,6 +662,13 @@
public boolean isEngine() {
return service;
+ }
+
+ /**
+ * @return the sharedLibraries
+ */
+ public String[] getSharedLibraries() {
+ return sharedLibraries;
}
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentRegistry.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentRegistry.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentRegistry.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/ComponentRegistry.java Wed Jun 21 08:00:03 2006
@@ -25,6 +25,8 @@
import javax.jbi.JBIException;
import javax.jbi.component.Component;
+import org.apache.servicemix.jbi.deployment.SharedLibraryList;
+
/**
* Registry for Components
*
@@ -55,10 +57,11 @@
String description,
Component component,
boolean binding,
- boolean service) {
+ boolean service,
+ String[] sharedLibraries) {
ComponentMBeanImpl result = null;
if (!idMap.containsKey(name)) {
- result = new ComponentMBeanImpl(registry.getContainer(), name, description, component, binding, service);
+ result = new ComponentMBeanImpl(registry.getContainer(), name, description, component, binding, service, sharedLibraries);
idMap.put(name, result);
}
return result;
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationContextImpl.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationContextImpl.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationContextImpl.java Wed Jun 21 08:00:03 2006
@@ -17,6 +17,7 @@
import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
+import org.apache.servicemix.jbi.deployment.SharedLibraryList;
import org.w3c.dom.DocumentFragment;
import javax.jbi.component.Bootstrap;
@@ -44,9 +45,21 @@
private boolean binding;
private boolean engine;
private boolean install = true;
-
-
-
+ private String[] sharedLibraries;
+
+ /**
+ * @return the sharedLibraries
+ */
+ public String[] getSharedLibraries() {
+ return sharedLibraries;
+ }
+
+ /**
+ * @param sharedLibraries the sharedLibraries to set
+ */
+ public void setSharedLibraries(String[] sharedLibraries) {
+ this.sharedLibraries = sharedLibraries;
+ }
/**
* Get the name of the class that implements the {@link Component}interface for this component. This must be the
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationService.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationService.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationService.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallationService.java Wed Jun 21 08:00:03 2006
@@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
@@ -46,25 +47,27 @@
import org.apache.servicemix.jbi.deployment.InstallationDescriptorExtension;
import org.apache.servicemix.jbi.deployment.SharedLibrary;
import org.apache.servicemix.jbi.deployment.SharedLibraryList;
-import org.apache.servicemix.jbi.loaders.ClassLoaderService;
-import org.apache.servicemix.jbi.loaders.InstallationClassLoader;
+import org.apache.servicemix.jbi.loaders.JarFileClassLoader;
import org.apache.servicemix.jbi.management.BaseSystemService;
import org.apache.servicemix.jbi.management.ManagementContext;
import org.apache.servicemix.jbi.management.OperationInfoHelper;
import org.apache.servicemix.jbi.management.ParameterHelper;
import org.apache.servicemix.jbi.util.FileUtil;
+import org.apache.servicemix.jbi.util.FileVersionUtil;
import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
/**
* Installation Service - installs/uninstalls archives
*
* @version $Revision$
*/
public class InstallationService extends BaseSystemService implements InstallationServiceMBean {
+
private static final Log log=LogFactory.getLog(InstallationService.class);
+
private EnvironmentContext environmentContext;
private ManagementContext managementContext;
- private ClassLoaderService classLoaderService=new ClassLoaderService();
private Map installers=new ConcurrentHashMap();
private Map nonLoadedInstallers = new ConcurrentHashMap();
@@ -164,13 +167,14 @@
installationContext.setComponentDescription(descriptor.getIdentification().getDescription());
installationContext.setInstallRoot(installationDir);
installationContext.setComponentClassName(descriptor.getComponentClassName());
+ installationContext.setSharedLibraries(getSharedLibraries(descriptor.getSharedLibraries()));
ClassPath cp = descriptor.getComponentClassPath();
if (cp != null) {
installationContext.setClassPathElements(cp.getPathElements());
}
// now build the ComponentContext
File componentRoot = environmentContext.getComponentRootDir(componentName);
- ComponentContextImpl context = buildComponentContext(componentRoot, componentName);
+ ComponentContextImpl context = buildComponentContext(componentRoot, installationDir, componentName);
installationContext.setContext(context);
InstallationDescriptorExtension desc = descriptor.getDescriptorExtension();
if (desc != null) {
@@ -181,18 +185,24 @@
// now we must initialize the boot strap class
String bootstrapClassName = descriptor.getBootstrapClassName();
ClassPath bootStrapClassPath = descriptor.getBootstrapClassPath();
- InstallationClassLoader bootstrapLoader = null;
+ ClassLoader bootstrapLoader = null;
if (bootstrapClassName != null && bootstrapClassName.length() > 0) {
boolean parentFirst = descriptor.isBootstrapClassLoaderDelegationParentFirst();
- bootstrapLoader = classLoaderService.buildClassLoader(
- installationDir, bootStrapClassPath.getPathElements(), parentFirst);
+ bootstrapLoader = buildClassLoader(
+ installationDir,
+ bootStrapClassPath.getPathElements(),
+ parentFirst,
+ null);
}
SharedLibraryList[] lists = descriptor.getSharedLibraries();
String componentClassName = descriptor.getComponentClassName();
ClassPath componentClassPath = descriptor.getComponentClassPath();
boolean parentFirst = descriptor.isComponentClassLoaderDelegationParentFirst();
- ClassLoader componentClassLoader = classLoaderService.buildClassLoader(installationDir, componentClassPath
- .getPathElements(), parentFirst, lists);
+ ClassLoader componentClassLoader = buildClassLoader(
+ installationDir,
+ componentClassPath.getPathElements(),
+ parentFirst,
+ lists);
InstallerMBeanImpl installer = new InstallerMBeanImpl(container,
installationContext, componentClassLoader,
componentClassName, bootstrapLoader,
@@ -210,7 +220,7 @@
* @return - true if the operation was successful, otherwise false.
*/
public boolean unloadInstaller(String componentName, boolean isToBeDeleted) {
- boolean result=false;
+ boolean result = false;
try {
container.getBroker().suspend();
InstallerMBeanImpl installer = (InstallerMBeanImpl) installers.remove(componentName);
@@ -268,7 +278,7 @@
public boolean uninstallSharedLibrary(String aSharedLibName) {
// TODO: should check existence of shared library
// and that it is not currently in use
- classLoaderService.removeSharedLibrary(aSharedLibName);
+ container.getRegistry().unregisterSharedLibrary(aSharedLibName);
environmentContext.removeSharedLibraryDirectory(aSharedLibName);
return true;
}
@@ -295,35 +305,18 @@
* Install an archive
*
* @param location
- * @throws DeploymentException
- */
- public void install(String location) throws DeploymentException {
- install(location,false);
- }
-
- public void install(String location, Properties props) throws DeploymentException {
- install(location, props, false);
- }
-
- /**
- * Install an archive
- *
- * @param location
+ * @param props
* @param autoStart
* @throws DeploymentException
*/
- public void install(String location, boolean autoStart) throws DeploymentException {
- install(location, null, autoStart);
- }
-
public void install(String location, Properties props, boolean autoStart) throws DeploymentException {
- File tmpDir=AutoDeploymentService.unpackLocation(environmentContext.getTmpDir(),location);
- if(tmpDir!=null){
- Descriptor root=DescriptorFactory.buildDescriptor(tmpDir);
- if(root!=null){
+ File tmpDir = AutoDeploymentService.unpackLocation(environmentContext.getTmpDir(),location);
+ if (tmpDir != null) {
+ Descriptor root = DescriptorFactory.buildDescriptor(tmpDir);
+ if (root != null) {
install(tmpDir, props, root, autoStart);
}else{
- log.error("Could not find Descriptor from: "+location);
+ log.error("Could not find Descriptor from: " + location);
}
}else{
log.warn("location: "+location+" isn't valid");
@@ -338,56 +331,51 @@
* @param autoStart
* @throws DeploymentException
*/
- protected void install(File tmpDir, Descriptor root, boolean autoStart) throws DeploymentException {
- install(tmpDir, null, root, autoStart);
- }
-
protected void install(File tmpDir, Properties props, Descriptor root, boolean autoStart) throws DeploymentException {
if (root.getComponent() != null) {
String componentName = root.getComponent().getIdentification().getName();
- if (!installers.containsKey(componentName)) {
- InstallerMBeanImpl installer = doInstallArchive(tmpDir,root);
- if (installer != null) {
- try {
- if (props != null && props.size() > 0) {
- ObjectName on = installer.getInstallerConfigurationMBean();
- if (on == null ) {
- log.warn("Could not find installation configuration MBean. Installation properties will be ignored.");
- } else {
- MBeanServer mbs = managementContext.getMBeanServer();
- for (Iterator it = props.keySet().iterator(); it.hasNext();) {
- String key = (String) it.next();
- String val = props.getProperty(key);
- try {
- mbs.setAttribute(on, new Attribute(key, val));
- } catch (JMException e) {
- throw new DeploymentException("Could not set installation property: (" + key + " = " + val, e);
- }
+ if (installers.containsKey(componentName)) {
+ throw new DeploymentException("Component " + componentName + " is already installed");
+ }
+ InstallerMBeanImpl installer = doInstallArchive(tmpDir,root);
+ if (installer != null) {
+ try {
+ if (props != null && props.size() > 0) {
+ ObjectName on = installer.getInstallerConfigurationMBean();
+ if (on == null ) {
+ log.warn("Could not find installation configuration MBean. Installation properties will be ignored.");
+ } else {
+ MBeanServer mbs = managementContext.getMBeanServer();
+ for (Iterator it = props.keySet().iterator(); it.hasNext();) {
+ String key = (String) it.next();
+ String val = props.getProperty(key);
+ try {
+ mbs.setAttribute(on, new Attribute(key, val));
+ } catch (JMException e) {
+ throw new DeploymentException("Could not set installation property: (" + key + " = " + val, e);
}
}
}
- installer.install();
- } catch(JBIException e) {
- throw new DeploymentException(e);
}
- if (autoStart) {
- try{
- ComponentMBeanImpl lcc = container.getComponent(componentName);
- if (lcc != null) {
- lcc.start();
- }else{
- log.warn("No ComponentConnector found for Component "+componentName);
- }
- }catch(JBIException e){
- String errStr="Failed to start Component: "+componentName;
- log.error(errStr,e);
- throw new DeploymentException(e);
+ installer.install();
+ } catch(JBIException e) {
+ throw new DeploymentException(e);
+ }
+ if (autoStart) {
+ try{
+ ComponentMBeanImpl lcc = container.getComponent(componentName);
+ if (lcc != null) {
+ lcc.start();
+ }else{
+ log.warn("No ComponentConnector found for Component "+componentName);
}
+ }catch(JBIException e){
+ String errStr="Failed to start Component: "+componentName;
+ log.error(errStr,e);
+ throw new DeploymentException(e);
}
- installers.put(componentName,installer);
}
- }else{
- log.warn("Component "+componentName+" is already installed");
+ installers.put(componentName,installer);
}
}
}
@@ -429,27 +417,28 @@
return installer;
}
- protected String doInstallSharedLibrary(File tmpDirectory,SharedLibrary descriptor) throws DeploymentException{
- String result=null;
- if(descriptor!=null){
- try{
- result=descriptor.getIdentification().getName();
- File installationDir=environmentContext.createSharedLibraryDirectory(result);
- if(installationDir.exists()){
- FileUtil.deleteFile(installationDir);
- }
- if(!tmpDirectory.renameTo(installationDir)){
+ protected String doInstallSharedLibrary(File tmpDirectory, SharedLibrary descriptor) throws DeploymentException{
+ String result = null;
+ if (descriptor != null) {
+ File installationDir = null;
+ try {
+ result = descriptor.getIdentification().getName();
+ File rootDir = environmentContext.createSharedLibraryDirectory(result);
+ installationDir = FileVersionUtil.getNewVersionDirectory(rootDir);
+ if (!tmpDirectory.renameTo(installationDir)) {
throw new DeploymentException("Unable to rename " + tmpDirectory + " to " + installationDir);
}
if (log.isDebugEnabled()) {
log.debug("Moved " + tmpDirectory + " to " + installationDir);
}
- classLoaderService.addSharedLibrary(installationDir, descriptor);
- }catch(IOException e){
- log.error("Deployment of Shared Library failed",e);
+ container.getRegistry().registerSharedLibrary(descriptor, installationDir);
+ } catch (Exception e) {
+ log.error("Deployment of Shared Library failed", e);
// remove any files created for installation
- environmentContext.removeComponentRootDirectory(descriptor.getIdentification().getName());
+ FileUtil.deleteFile(installationDir);
throw new DeploymentException(e);
+ } finally {
+ FileUtil.deleteFile(tmpDirectory);
}
}
return result;
@@ -490,12 +479,14 @@
installationContext.setComponentDescription(descriptor.getIdentification().getDescription());
installationContext.setInstallRoot(installationDir);
installationContext.setComponentClassName(descriptor.getComponentClassName());
+ installationContext.setSharedLibraries(getSharedLibraries(descriptor.getSharedLibraries()));
ClassPath cp=descriptor.getComponentClassPath();
if(cp!=null){
installationContext.setClassPathElements(cp.getPathElements());
}
// now build the ComponentContext
- installationContext.setContext(buildComponentContext(componentRoot,name));
+ ComponentContextImpl context = buildComponentContext(componentRoot, installationDir, name);
+ installationContext.setContext(context);
InstallationDescriptorExtension desc=descriptor.getDescriptorExtension();
if(desc!=null){
installationContext.setDescriptorExtension(desc.getDescriptorExtension());
@@ -505,18 +496,24 @@
// now we must initialize the boot strap class
String bootstrapClassName=descriptor.getBootstrapClassName();
ClassPath bootStrapClassPath=descriptor.getBootstrapClassPath();
- InstallationClassLoader bootstrapLoader=null;
+ ClassLoader bootstrapLoader=null;
if(bootstrapClassName!=null&&bootstrapClassName.length()>0){
boolean parentFirst=descriptor.isBootstrapClassLoaderDelegationParentFirst();
- bootstrapLoader=classLoaderService.buildClassLoader(installationDir,bootStrapClassPath
- .getPathElements(),parentFirst);
+ bootstrapLoader = buildClassLoader(
+ installationDir,
+ bootStrapClassPath.getPathElements(),
+ parentFirst,
+ null);
}
SharedLibraryList[] lists=descriptor.getSharedLibraries();
String componentClassName=descriptor.getComponentClassName();
ClassPath componentClassPath=descriptor.getComponentClassPath();
boolean parentFirst=descriptor.isComponentClassLoaderDelegationParentFirst();
- ClassLoader componentClassLoader=classLoaderService.buildClassLoader(installationDir,componentClassPath
- .getPathElements(),parentFirst,lists);
+ ClassLoader componentClassLoader = buildClassLoader(
+ installationDir,
+ componentClassPath.getPathElements(),
+ parentFirst,
+ lists);
result=new InstallerMBeanImpl(container,installationContext,componentClassLoader,componentClassName,
bootstrapLoader,bootstrapClassName, false);
// create an MBean for the installer
@@ -545,26 +542,29 @@
* @return true/false
*/
protected boolean containsSharedLibrary(String name){
- return classLoaderService.containsSharedLibrary(name);
+ return container.getRegistry().getSharedLibrary(name) != null;
}
protected void buildSharedLibs(){
// walk through shared libaries and add then to the ClassLoaderService
- File top=environmentContext.getSharedLibDir();
- if(top!=null&&top.exists()&&top.isDirectory()){
- // directory structure is sharedlibraries/<lib name>stuff ...
- File[] files=top.listFiles();
- if(files!=null){
- for(int i=0;i<files.length;i++){
- if(files[i].isDirectory()){
- Descriptor root=DescriptorFactory.buildDescriptor(files[i]);
- if(root!=null){
- SharedLibrary sl=root.getSharedLibrary();
- if(sl!=null){
- try{
- classLoaderService.addSharedLibrary(files[i],sl);
- }catch(MalformedURLException e){
- log.error("Failed to initialize sharted library",e);
+ File top = environmentContext.getSharedLibDir();
+ if (top != null && top.exists() && top.isDirectory()) {
+ // directory structure is sharedlibraries/<lib name>/version_x/stuff ...
+ File[] files = top.listFiles();
+ if (files != null) {
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ File dir = FileVersionUtil.getLatestVersionDirectory(files[i]);
+ if (dir != null) {
+ Descriptor root = DescriptorFactory.buildDescriptor(dir);
+ if (root != null) {
+ SharedLibrary sl = root.getSharedLibrary();
+ if (sl != null) {
+ try {
+ container.getRegistry().registerSharedLibrary(sl, dir);
+ } catch (Exception e) {
+ log.error("Failed to initialize sharted library", e);
+ }
}
}
}
@@ -630,7 +630,7 @@
}
}
- protected ComponentContextImpl buildComponentContext(File componentRoot,String name) throws IOException{
+ protected ComponentContextImpl buildComponentContext(File componentRoot, File installRoot, String name) throws IOException{
ComponentNameSpace cns=new ComponentNameSpace(container.getName(),name);
ComponentContextImpl context=new ComponentContextImpl(container,cns);
ComponentEnvironment env=new ComponentEnvironment();
@@ -638,8 +638,77 @@
File privateWorkspace=environmentContext.createWorkspaceDirectory(name);
env.setWorkspaceRoot(privateWorkspace);
env.setComponentRoot(componentRoot);
+ env.setInstallRoot(installRoot);
context.setEnvironment(env);
return context;
+ }
+
+ /**
+ * Buld a Custom ClassLoader
+ *
+ * @param dir
+ * @param classPathNames
+ * @param parentFirst
+ * @param list
+ * @return ClassLoader
+ * @throws MalformedURLException
+ * @throws MalformedURLException
+ * @throws DeploymentException
+ */
+ protected ClassLoader buildClassLoader(
+ File dir,
+ String[] classPathNames,
+ boolean parentFirst,
+ SharedLibraryList[] list) throws MalformedURLException, DeploymentException {
+
+ // Make the current ClassLoader the parent
+ ClassLoader[] parents;
+
+ // Create a new parent if there are some shared libraries
+ if (list != null && list.length > 0) {
+ parents = new ClassLoader[list.length];
+ for (int i = 0; i < parents.length; i++) {
+ String name = list[i].getName();
+ org.apache.servicemix.jbi.framework.SharedLibrary sl =
+ container.getRegistry().getSharedLibrary(name);
+ if (sl == null) {
+ throw new DeploymentException("Shared library " + name + " is not installed");
+ }
+ parents[i] = sl.getClassLoader();
+ }
+ } else {
+ parents = new ClassLoader[] { getClass().getClassLoader() };
+ }
+
+ URL[] urls = new URL[classPathNames.length];
+ for (int i = 0; i < classPathNames.length; i++) {
+ File file = new File(dir, classPathNames[i]);
+ if (!file.exists()) {
+ throw new DeploymentException("Unable to add File " + file
+ + " to class path as it doesn't exist: "
+ + file.getAbsolutePath());
+ }
+ urls[i] = file.toURL();
+ }
+
+ return new JarFileClassLoader(
+ "Componnent ClassLoader",
+ urls,
+ parents,
+ !parentFirst,
+ new String[0],
+ new String[] { "java.", "javax." });
+ }
+
+ protected String[] getSharedLibraries(SharedLibraryList[] sharedLibraries) {
+ if (sharedLibraries == null || sharedLibraries.length == 0) {
+ return null;
+ }
+ String[] names = new String[sharedLibraries.length];
+ for (int i = 0; i < names.length; i++) {
+ names[i] = sharedLibraries[i].getName();
+ }
+ return names;
}
}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallerMBeanImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallerMBeanImpl.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallerMBeanImpl.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/InstallerMBeanImpl.java Wed Jun 21 08:00:03 2006
@@ -154,7 +154,7 @@
if (componentClass != null){
Component component = (Component) componentClass.newInstance();
result = container.activateComponent(context.getInstallRootAsDir(), component, context.getComponentDescription(),(ComponentContextImpl) context.getContext(), context
- .isBinding(), context.isEngine());
+ .isBinding(), context.isEngine(), context.getSharedLibraries());
}
else {
String err = "component class " + context.getComponentClassName() + " not found";
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Registry.java Wed Jun 21 08:00:03 2006
@@ -41,6 +41,7 @@
import org.apache.servicemix.jbi.container.SubscriptionSpec;
import org.apache.servicemix.jbi.deployment.ServiceAssembly;
import org.apache.servicemix.jbi.deployment.ServiceUnit;
+import org.apache.servicemix.jbi.deployment.SharedLibraryList;
import org.apache.servicemix.jbi.management.BaseSystemService;
import org.apache.servicemix.jbi.messaging.MessageExchangeImpl;
import org.apache.servicemix.jbi.servicedesc.AbstractServiceEndpoint;
@@ -68,8 +69,10 @@
private EndpointRegistry endpointRegistry;
private SubscriptionRegistry subscriptionRegistry;
private ServiceAssemblyRegistry serviceAssemblyRegistry;
+ private Map sharedLibraries;
private Map serviceUnits;
private List pendingAssemblies;
+ private List pendingComponents;
/**
* Constructor
@@ -81,6 +84,8 @@
this.serviceAssemblyRegistry = new ServiceAssemblyRegistry(this);
this.serviceUnits = new ConcurrentHashMap();
this.pendingAssemblies = new CopyOnWriteArrayList();
+ this.sharedLibraries = new ConcurrentHashMap();
+ this.pendingComponents = new CopyOnWriteArrayList();
}
/**
@@ -393,8 +398,9 @@
String description,
Component component,
boolean binding,
- boolean service) throws JBIException {
- return componentRegistry.registerComponent(name,description, component, binding, service);
+ boolean service,
+ String[] sharedLibraries) throws JBIException {
+ return componentRegistry.registerComponent(name,description, component, binding, service, sharedLibraries);
}
/**
@@ -698,6 +704,40 @@
}
}
}
+
+ public void registerSharedLibrary(org.apache.servicemix.jbi.deployment.SharedLibrary sl,
+ File installationDir) {
+ SharedLibrary library = new SharedLibrary(sl, installationDir);
+ this.sharedLibraries.put(library.getName(), library);
+ try {
+ ObjectName objectName = getContainer().getManagementContext().createObjectName(library);
+ getContainer().getManagementContext().registerMBean(objectName, library, SharedLibraryMBean.class);
+ } catch (JMException e) {
+ log.error("Could not register MBean for service unit", e);
+ }
+ checkPendingComponents();
+ }
+
+ public void unregisterSharedLibrary(String name) {
+ // TODO: check for components depending on this library,
+ // shutdown them and add them to the list of pending components
+ SharedLibrary sl = (SharedLibrary) this.sharedLibraries.remove(name);
+ if (sl != null) {
+ try {
+ getContainer().getManagementContext().unregisterMBean(sl);
+ } catch (JBIException e) {
+ log.error("Could not unregister MBean for shared library", e);
+ }
+ }
+ }
+
+ public SharedLibrary getSharedLibrary(String name) {
+ return (SharedLibrary) sharedLibraries.get(name);
+ }
+
+ public Collection getSharedLibraries() {
+ return sharedLibraries.values();
+ }
public void registerEndpointConnection(QName fromSvc, String fromEp, QName toSvc, String toEp, String link) throws JBIException {
endpointRegistry.registerEndpointConnection(fromSvc, fromEp, toSvc, toEp, link);
@@ -763,6 +803,33 @@
log.error("Error trying to restore service assembly state", e);
}
}
+ }
+ }
+
+ public void checkPendingComponents() {
+ try {
+ getContainer().getWorkManager().scheduleWork(new Work() {
+ public void release() {
+ }
+ public void run() {
+ startPendingComponents();
+ }
+ });
+ } catch (WorkException e) {
+ log.error("Could not schedule work", e);
+ }
+ }
+
+ public void addPendingComponent(ComponentMBeanImpl comp) {
+ if (!pendingComponents.contains(comp)) {
+ pendingComponents.add(comp);
+ }
+ }
+
+ protected synchronized void startPendingComponents() {
+ for (Iterator iter = pendingComponents.iterator(); iter.hasNext();) {
+ ComponentMBeanImpl comp = (ComponentMBeanImpl) iter.next();
+ // TODO: restore component state if
}
}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SharedLibrary.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SharedLibrary.java?rev=416002&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SharedLibrary.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SharedLibrary.java Wed Jun 21 08:00:03 2006
@@ -0,0 +1,102 @@
+package org.apache.servicemix.jbi.framework;
+
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.management.JMException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanOperationInfo;
+
+import org.apache.servicemix.jbi.deployment.ClassPath;
+import org.apache.servicemix.jbi.loaders.JarFileClassLoader;
+import org.apache.servicemix.jbi.management.AttributeInfoHelper;
+import org.apache.servicemix.jbi.management.MBeanInfoProvider;
+
+public class SharedLibrary implements SharedLibraryMBean, MBeanInfoProvider {
+
+ private org.apache.servicemix.jbi.deployment.SharedLibrary library;
+ private File installationDir;
+ private ClassLoader classLoader;
+
+ public SharedLibrary(org.apache.servicemix.jbi.deployment.SharedLibrary library,
+ File installationDir) {
+ this.library = library;
+ this.installationDir = installationDir;
+ this.classLoader = createClassLoader();
+ }
+
+ /**
+ * @return the library
+ */
+ public org.apache.servicemix.jbi.deployment.SharedLibrary getLibrary() {
+ return library;
+ }
+
+ public ClassLoader getClassLoader() {
+ return this.classLoader;
+ }
+
+ protected ClassLoader createClassLoader() {
+ boolean parentFirst = library.isParentFirstClassLoaderDelegation();
+ // Make the current ClassLoader the parent
+ ClassLoader parent = getClass().getClassLoader();
+
+ ClassPath cp = library.getSharedLibraryClassPath();
+ String[] classPathNames = cp.getPathElements();
+ URL[] urls = new URL[classPathNames.length];
+ for (int i = 0; i < classPathNames.length; i++) {
+ File file = new File(installationDir, classPathNames[i]);
+ try {
+ urls[i] = file.toURL();
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException(classPathNames[i], e);
+ }
+ }
+ return new JarFileClassLoader(
+ getName(),
+ urls,
+ parent,
+ !parentFirst,
+ new String[0],
+ new String[] { "java.", "javax." });
+ }
+
+ public String getDescription() {
+ return library.getIdentification().getDescription();
+ }
+
+ public String getName() {
+ return library.getIdentification().getName();
+ }
+
+ public Object getObjectToManage() {
+ return this;
+ }
+
+ public MBeanAttributeInfo[] getAttributeInfos() throws JMException {
+ AttributeInfoHelper helper = new AttributeInfoHelper();
+ helper.addAttribute(getObjectToManage(), "name", "name of the service unit");
+ helper.addAttribute(getObjectToManage(), "description", "description of the service unit");
+ return helper.getAttributeInfos();
+ }
+
+ public MBeanOperationInfo[] getOperationInfos() throws JMException {
+ return null;
+ }
+
+ public String getSubType() {
+ return null;
+ }
+
+ public String getType() {
+ return "SharedLibrary";
+ }
+
+ public void setPropertyChangeListener(PropertyChangeListener l) {
+ // We do not fire property events, so need to keep
+ // a reference
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SharedLibraryMBean.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SharedLibraryMBean.java?rev=416002&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SharedLibraryMBean.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/SharedLibraryMBean.java Wed Jun 21 08:00:03 2006
@@ -0,0 +1,5 @@
+package org.apache.servicemix.jbi.framework;
+
+public interface SharedLibraryMBean {
+
+}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/AbstractResourceHandle.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/AbstractResourceHandle.java?rev=416002&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/AbstractResourceHandle.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/AbstractResourceHandle.java Wed Jun 21 08:00:03 2006
@@ -0,0 +1,63 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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 org.apache.servicemix.jbi.loaders;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.cert.Certificate;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public abstract class AbstractResourceHandle implements ResourceHandle {
+ public byte[] getBytes() throws IOException {
+ InputStream in = getInputStream();
+ try {
+ byte[] bytes = IoUtil.getBytes(in);
+ return bytes;
+ } finally {
+ IoUtil.close(in);
+ }
+ }
+
+ public Manifest getManifest() throws IOException {
+ return null;
+ }
+
+ public Certificate[] getCertificates() {
+ return null;
+ }
+
+ public Attributes getAttributes() throws IOException {
+ Manifest m = getManifest();
+ if (m == null) {
+ return null;
+ }
+
+ String entry = getUrl().getFile();
+ return m.getAttributes(entry);
+ }
+
+ public void close() {
+ }
+
+ public String toString() {
+ return "[" + getName() + ": " + getUrl() + "; code source: " + getCodeSourceUrl() + "]";
+ }
+}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/AbstractUrlResourceLocation.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/AbstractUrlResourceLocation.java?rev=416002&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/AbstractUrlResourceLocation.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/AbstractUrlResourceLocation.java Wed Jun 21 08:00:03 2006
@@ -0,0 +1,53 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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 org.apache.servicemix.jbi.loaders;
+
+import java.net.URL;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public abstract class AbstractUrlResourceLocation implements ResourceLocation {
+ private final URL codeSource;
+
+ public AbstractUrlResourceLocation(URL codeSource) {
+ this.codeSource = codeSource;
+ }
+
+ public final URL getCodeSource() {
+ return codeSource;
+ }
+
+ public void close() {
+ }
+
+ public final boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ AbstractUrlResourceLocation that = (AbstractUrlResourceLocation) o;
+ return codeSource.equals(that.codeSource);
+ }
+
+ public final int hashCode() {
+ return codeSource.hashCode();
+ }
+
+ public final String toString() {
+ return "[" + getClass().getName() + ": " + codeSource + "]";
+ }
+}
Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderUtil.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderUtil.java?rev=416002&r1=416001&r2=416002&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderUtil.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/ClassLoaderUtil.java Wed Jun 21 08:00:03 2006
@@ -1,23 +1,25 @@
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
*
- * Licensed 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
+ * Licensed 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
+ * 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.
+ * 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 org.apache.servicemix.jbi.loaders;
import java.util.Map;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.beans.Introspector;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
@@ -28,8 +30,6 @@
* @author Dain Sundstrom
* @version $Id$
* @since 2.0
- *
- * TODO: this has been copied from xbean-server
*/
public final class ClassLoaderUtil {
private ClassLoaderUtil() {
@@ -47,6 +47,7 @@
clearSunSoftCache(ObjectOutputStream.class, "subclassAudits");
clearSunSoftCache(ObjectStreamClass.class, "localDescs");
clearSunSoftCache(ObjectStreamClass.class, "reflectors");
+ Introspector.flushCaches();
}
/**
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DestroyableClassLoader.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DestroyableClassLoader.java?rev=416002&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DestroyableClassLoader.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DestroyableClassLoader.java Wed Jun 21 08:00:03 2006
@@ -0,0 +1,33 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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 org.apache.servicemix.jbi.loaders;
+
+/**
+ * DestroyableClassLoader is a mixin interface for a ClassLoader that add a destroy method to propertly cleanup a
+ * classloader then dereferenced by the server.
+ *
+ * @author Dain Sundstrom
+ * @version $Id$
+ * @since 2.0
+ */
+public interface DestroyableClassLoader {
+ /**
+ * Destroys the clasloader releasing all resources. After this mehtod is called, the class loader will no longer
+ * load any classes or resources.
+ */
+ void destroy();
+}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DirectoryResourceHandle.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DirectoryResourceHandle.java?rev=416002&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DirectoryResourceHandle.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DirectoryResourceHandle.java Wed Jun 21 08:00:03 2006
@@ -0,0 +1,97 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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 org.apache.servicemix.jbi.loaders;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.security.cert.Certificate;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public class DirectoryResourceHandle extends AbstractResourceHandle {
+ private final String name;
+ private final File file;
+ private final Manifest manifest;
+ private final URL url;
+ private final URL codeSource;
+
+ public DirectoryResourceHandle(String name, File file, File codeSource, Manifest manifest) throws MalformedURLException {
+ this.name = name;
+ this.file = file;
+ this.codeSource = codeSource.toURL();
+ this.manifest = manifest;
+ url = file.toURL();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ public URL getCodeSourceUrl() {
+ return codeSource;
+ }
+
+ public boolean isDirectory() {
+ return file.isDirectory();
+ }
+
+ public InputStream getInputStream() throws IOException {
+ if (file.isDirectory()) {
+ return new IoUtil.EmptyInputStream();
+ }
+ return new FileInputStream(file);
+ }
+
+ public int getContentLength() {
+ if (file.isDirectory() || file.length() > Integer.MAX_VALUE) {
+ return -1;
+ } else {
+ return (int) file.length();
+ }
+ }
+
+ public Manifest getManifest() throws IOException {
+ return manifest;
+ }
+
+ public Attributes getAttributes() throws IOException {
+ if (manifest == null) {
+ return null;
+ }
+ return manifest.getAttributes(getName());
+ }
+
+ /**
+ * Always return null. This could be implementd by verifing the signatures
+ * in the manifest file against the actual file, but we don't need this right now.
+ * @return null
+ */
+ public Certificate[] getCertificates() {
+ return null;
+ }
+}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DirectoryResourceLocation.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DirectoryResourceLocation.java?rev=416002&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DirectoryResourceLocation.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/DirectoryResourceLocation.java Wed Jun 21 08:00:03 2006
@@ -0,0 +1,79 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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 org.apache.servicemix.jbi.loaders;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.jar.Manifest;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public class DirectoryResourceLocation extends AbstractUrlResourceLocation {
+ private final File baseDir;
+ private boolean manifestLoaded = false;
+ private Manifest manifest;
+
+ public DirectoryResourceLocation(File baseDir) throws MalformedURLException {
+ super(baseDir.toURL());
+ this.baseDir = baseDir;
+ }
+
+ public ResourceHandle getResourceHandle(String resourceName) {
+ File file = new File(baseDir, resourceName);
+ if (!file.exists()) {
+ return null;
+ }
+
+ try {
+ ResourceHandle resourceHandle = new DirectoryResourceHandle(resourceName, file, baseDir, getManifestSafe());
+ return resourceHandle;
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+
+ public Manifest getManifest() throws IOException {
+ if (!manifestLoaded) {
+ File manifestFile = new File(baseDir, "META-INF/MANIFEST.MF");
+
+ if (manifestFile.isFile() && manifestFile.canRead()) {
+ FileInputStream in = null;
+ try {
+ in = new FileInputStream(manifestFile);
+ manifest = new Manifest(in);
+ } finally {
+ IoUtil.close(in);
+ }
+ }
+ manifestLoaded = true;
+ }
+ return manifest;
+ }
+
+ private Manifest getManifestSafe() {
+ Manifest manifest = null;
+ try {
+ manifest = getManifest();
+ } catch (IOException e) {
+ // ignore
+ }
+ return manifest;
+ }
+}
Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/IoUtil.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/IoUtil.java?rev=416002&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/IoUtil.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/loaders/IoUtil.java Wed Jun 21 08:00:03 2006
@@ -0,0 +1,145 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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 org.apache.servicemix.jbi.loaders;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.jar.JarFile;
+
+/**
+ * @version $Rev: 410741 $ $Date: 2006-06-01 06:35:48 +0200 (Thu, 01 Jun 2006) $
+ */
+public final class IoUtil {
+ private IoUtil() {
+ }
+
+ public static byte[] getBytes(InputStream inputStream) throws IOException {
+ try {
+ byte[] buffer = new byte[4096];
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ for (int count = inputStream.read(buffer); count >= 0; count = inputStream.read(buffer)) {
+ out.write(buffer, 0, count);
+ }
+ byte[] bytes = out.toByteArray();
+ return bytes;
+ } finally {
+ close(inputStream);
+ }
+ }
+
+ public static void flush(OutputStream thing) {
+ if (thing != null) {
+ try {
+ thing.flush();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void flush(Writer thing) {
+ if (thing != null) {
+ try {
+ thing.flush();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void close(JarFile thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void close(InputStream thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void close(OutputStream thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void close(Reader thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static void close(Writer thing) {
+ if (thing != null) {
+ try {
+ thing.close();
+ } catch(Exception ignored) {
+ }
+ }
+ }
+
+ public static final class EmptyInputStream extends InputStream {
+ public int read() {
+ return -1;
+ }
+
+ public int read(byte b[]) {
+ return -1;
+ }
+
+ public int read(byte b[], int off, int len) {
+ return -1;
+ }
+
+ public long skip(long n) {
+ return 0;
+ }
+
+ public int available() {
+ return 0;
+ }
+
+ public void close() {
+ }
+
+ public synchronized void mark(int readlimit) {
+ }
+
+ public synchronized void reset() {
+ }
+
+ public boolean markSupported() {
+ return false;
+ }
+ }
+}