org.glassfish.concurrent.runtime.deployer.ManagedThreadFactoryDeployer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of payara-client Show documentation
Show all versions of payara-client Show documentation
Appclient for Payara Server
The newest version!
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.concurrent.runtime.deployer;
import com.sun.enterprise.config.serverbeans.Application;
import com.sun.enterprise.config.serverbeans.Resource;
import com.sun.enterprise.config.serverbeans.Resources;
import org.glassfish.api.logging.LogHelper;
import org.glassfish.concurrent.LogFacade;
import org.glassfish.concurrent.config.ManagedThreadFactory;
import org.glassfish.concurrent.runtime.ConcurrentRuntime;
import org.glassfish.resourcebase.resources.api.ResourceConflictException;
import org.glassfish.resourcebase.resources.api.ResourceDeployer;
import org.glassfish.resourcebase.resources.api.ResourceDeployerInfo;
import org.glassfish.resourcebase.resources.api.ResourceInfo;
import org.glassfish.resourcebase.resources.naming.ResourceNamingService;
import org.glassfish.resourcebase.resources.util.ResourceUtil;
import org.glassfish.resources.naming.SerializableObjectRefAddr;
import org.jvnet.hk2.annotations.Service;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import javax.naming.NamingException;
import javax.naming.RefAddr;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
@Service
@ResourceDeployerInfo(ManagedThreadFactory.class)
@Singleton
public class ManagedThreadFactoryDeployer implements ResourceDeployer {
@Inject
private ResourceNamingService namingService;
@Inject
ConcurrentRuntime concurrentRuntime;
// logger for this deployer
private static Logger _logger = LogFacade.getLogger();
@Override
public void deployResource(Object resource, String applicationName, String moduleName) throws Exception {
ManagedThreadFactory ManagedThreadFactoryRes = (ManagedThreadFactory) resource;
if (ManagedThreadFactoryRes == null) {
_logger.log(Level.WARNING, LogFacade.DEPLOY_ERROR_NULL_CONFIG, "ManagedThreadFactory");
return;
}
String jndiName = ManagedThreadFactoryRes.getJndiName();
if(_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "ManagedThreadFactoryDeployer.deployResource() : jndi-name ["+jndiName+"]");
}
ResourceInfo resourceInfo = new ResourceInfo(ManagedThreadFactoryRes.getJndiName(), applicationName, moduleName);
ManagedThreadFactoryConfig config = new ManagedThreadFactoryConfig(ManagedThreadFactoryRes);
javax.naming.Reference ref= new javax.naming.Reference(
jakarta.enterprise.concurrent.ManagedThreadFactory.class.getName(),
"org.glassfish.concurrent.runtime.deployer.ConcurrentObjectFactory",
null);
RefAddr addr = new SerializableObjectRefAddr(ManagedThreadFactoryConfig.class.getName(), config);
ref.add(addr);
RefAddr resAddr = new SerializableObjectRefAddr(ResourceInfo.class.getName(), resourceInfo);
ref.add(resAddr);
try {
// Publish the object ref
namingService.publishObject(resourceInfo, ref, true);
} catch (NamingException ex) {
LogHelper.log(_logger, Level.SEVERE, LogFacade.UNABLE_TO_BIND_OBJECT, ex, "ManagedThreadFactory", jndiName);
}
}
@Override
public void deployResource(Object resource) throws Exception {
ManagedThreadFactory ManagedThreadFactoryResource =
(ManagedThreadFactory) resource;
ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(ManagedThreadFactoryResource);
deployResource(resource, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
@Override
public void undeployResource(Object resource) throws Exception {
ManagedThreadFactory ManagedThreadFactoryResource =
(ManagedThreadFactory) resource;
ResourceInfo resourceInfo = ResourceUtil.getResourceInfo(ManagedThreadFactoryResource);
undeployResource(resource, resourceInfo.getApplicationName(), resourceInfo.getModuleName());
}
@Override
public void undeployResource(Object resource, String applicationName, String moduleName) throws Exception {
ManagedThreadFactory managedThreadFactoryRes = (ManagedThreadFactory) resource;
ResourceInfo resourceInfo = new ResourceInfo(managedThreadFactoryRes.getJndiName(), applicationName, moduleName);
namingService.unpublishObject(resourceInfo, managedThreadFactoryRes.getJndiName());
// stop the runtime object
concurrentRuntime.shutdownManagedThreadFactory(managedThreadFactoryRes.getJndiName());
}
@Override
public void redeployResource(Object resource) throws Exception {
undeployResource(resource);
deployResource(resource);
}
@Override
public void enableResource(Object resource) throws Exception {
deployResource(resource);
}
@Override
public void disableResource(Object resource) throws Exception {
undeployResource(resource);
}
@Override
public boolean handles(Object resource) {
return resource instanceof ManagedThreadFactory;
}
@Override
public boolean supportsDynamicReconfiguration() {
return false;
}
@Override
public Class[] getProxyClassesForDynamicReconfiguration() {
return new Class[0];
}
@Override
public boolean canDeploy(boolean postApplicationDeployment, Collection allResources, Resource resource) {
if (handles(resource)) {
if (!postApplicationDeployment) {
return true;
}
}
return false;
}
@Override
public void validatePreservedResource(Application oldApp, Application newApp, Resource resource, Resources allResources) throws ResourceConflictException {
// do nothing
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy