org.jboss.as.ejb3.component.singleton.SingletonComponent Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This 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 software 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 software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.ejb3.component.singleton;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import javax.ejb.LockType;
import org.jboss.as.ee.component.BasicComponentInstance;
import org.jboss.as.ee.component.Component;
import org.jboss.as.ejb3.logging.EjbLogger;
import org.jboss.as.ejb3.component.DefaultAccessTimeoutService;
import org.jboss.as.ejb3.component.EJBBusinessMethod;
import org.jboss.as.ejb3.component.allowedmethods.AllowedMethodsInformation;
import org.jboss.as.ejb3.component.session.SessionBeanComponent;
import org.jboss.as.ejb3.concurrency.AccessTimeoutDetails;
import org.jboss.as.server.CurrentServiceContainer;
import org.jboss.invocation.Interceptor;
import org.jboss.msc.service.ServiceContainer;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import static org.jboss.as.ejb3.logging.EjbLogger.ROOT_LOGGER;
/**
* {@link Component} representing a {@link javax.ejb.Singleton} EJB.
*
* @author Jaikiran Pai
*/
public class SingletonComponent extends SessionBeanComponent {
private volatile SingletonComponentInstance singletonComponentInstance;
private final boolean initOnStartup;
private final Map beanLevelLockType;
private final Map methodLockTypes;
private final Map methodAccessTimeouts;
private final List dependsOn;
private final DefaultAccessTimeoutService defaultAccessTimeoutProvider;
/**
* We can't lock on this
because the {@link org.jboss.as.ee.component.BasicComponent#waitForComponentStart()}
* also synchronizes on it, and calls {@link #wait()}.
*/
private final Object creationLock = new Object();
/**
* A spec compliant {@link EJBReadWriteLock}
*/
private final ReadWriteLock readWriteLock = new EJBReadWriteLock();
/**
* Construct a new instance.
*
* @param singletonComponentCreateService
* the component configuration
* @param dependsOn
*/
public SingletonComponent(final SingletonComponentCreateService singletonComponentCreateService, final List dependsOn) {
super(singletonComponentCreateService);
this.dependsOn = dependsOn;
this.initOnStartup = singletonComponentCreateService.isInitOnStartup();
this.beanLevelLockType = singletonComponentCreateService.getBeanLockType();
this.methodLockTypes = singletonComponentCreateService.getMethodApplicableLockTypes();
this.methodAccessTimeouts = singletonComponentCreateService.getMethodApplicableAccessTimeouts();
this.defaultAccessTimeoutProvider = singletonComponentCreateService.getDefaultAccessTimeoutService();
}
@Override
protected BasicComponentInstance instantiateComponentInstance(Interceptor preDestroyInterceptor, Map methodInterceptors, Map