org.ow2.petals.microkernel.container.lifecycle.SharedLibraryLifeCycleImpl Maven / Gradle / Ivy
/**
* Copyright (c) 2007-2012 EBM WebSourcing, 2012-2016 Linagora
*
* This program/library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or (at your
* option) any later version.
*
* This program/library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program/library; If not, see http://www.gnu.org/licenses/
* for the GNU Lesser General Public License version 2.1.
*/
package org.ow2.petals.microkernel.container.lifecycle;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import org.objectweb.fractal.fraclet.annotations.Component;
import org.objectweb.fractal.fraclet.annotations.Interface;
import org.objectweb.fractal.fraclet.annotations.Lifecycle;
import org.objectweb.fractal.fraclet.annotations.Requires;
import org.objectweb.fractal.fraclet.types.Step;
import org.ow2.petals.basisapi.exception.PetalsException;
import org.ow2.petals.jbi.descriptor.original.generated.Jbi.SharedLibrary;
import org.ow2.petals.microkernel.api.container.SharedLibraryBean;
import org.ow2.petals.microkernel.api.container.SharedLibraryLifeCycle;
import org.ow2.petals.microkernel.system.classloader.ClassLoaderService;
import com.ebmwebsourcing.easycommons.log.LoggingUtil;
/**
* The LifeCycle
implementation of the shared library.
* @author Nicolas SALATGE - EBM WebSourcing
*/
@Component(provides = @Interface(name = SharedLibraryLifeCycle.FRACTAL_SRV_ITF_NAME, signature = SharedLibraryLifeCycle.class))
public class SharedLibraryLifeCycleImpl implements SharedLibraryLifeCycle {
/**
* state flag: the shared library is installed.
*/
public static final String INSTALLED = "Installed";
/**
* state flag: the shared library is uninstalled.
*/
public static final String UNINSTALLED = "Uninstalled";
/**
* the state of the shared library.
*/
private String state;
/**
* the log.
*/
private final LoggingUtil log = new LoggingUtil(Logger.getLogger(SharedLibraryLifeCycle.COMPONENT_LOGGER_NAME));
/**
* the shared library.
*/
private SharedLibrary sharedLibrary;
private final List componentNames = new ArrayList();
/**
* the base urls.
*/
private URL[] baseUrls;
/**
* the use parent first.
*/
private boolean useParentFirst;
/**
* the full shared library name in a bean
*/
private SharedLibraryBean bean;
/**
* Platform Component :: Loader Service.
*/
@Requires(name = "classloader")
private ClassLoaderService loaderService;
/**
* The default constructor.
*/
public SharedLibraryLifeCycleImpl() {
super();
this.state = UNINSTALLED;
}
@Override
public void init(final SharedLibrary sharedLibrary, final URL[] baseUrls1,
final boolean useParentFirst) {
this.sharedLibrary = sharedLibrary;
this.baseUrls = baseUrls1.clone();
this.useParentFirst = useParentFirst;
this.bean = new SharedLibraryBean(sharedLibrary.getIdentification().getName(), sharedLibrary.getVersion());
this.state = UNINSTALLED;
}
@Override
public SharedLibraryBean getSharedLibraryBean() {
return this.bean;
}
@Override
public boolean isLoaded() {
return INSTALLED.equals(this.state);
}
@Override
public void loadSharedLibrary() throws PetalsException {
this.log.start();
final String classLoaderId = this.bean.toString();
final List classpathUrls = this.sharedLibrary.getSharedLibraryClassPath()
.getPathElement();
this.loaderService.createSharedLibraryClassLoader(classLoaderId, this.baseUrls,
classpathUrls, this.useParentFirst);
this.state = INSTALLED;
this.log.info("Shared library '" + bean.getName() + "' (" + bean.getVersion() + ") loaded.");
this.log.end();
}
@Override
public void unLoadSharedLibrary() {
this.log.start();
String classLoaderId = this.bean.toString();
this.loaderService.deleteClassLoader(classLoaderId);
this.state = UNINSTALLED;
this.log.end();
}
@Override
public void registerComponent(String componentName) {
this.componentNames.add(componentName);
}
@Override
public void unregisterComponent(String componentName) {
this.componentNames.remove(componentName);
}
@Override
public List getRegisteredComponents() {
return this.componentNames;
}
@Override
public String getState() {
return this.state;
}
/**
* Start of the shared library lifecycle.
*
*/
@Lifecycle(step = Step.START)
public void startFractalComponent() {
this.log.call();
}
/**
* Stop of the shared library lifecycle.
*
*/
@Lifecycle(step = Step.STOP)
public void stopFractalComponent() {
this.log.call();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy