repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
---|---|---|---|---|---|---|
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/service/ConcurrentContextService.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.concurrent.service;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.concurrent.ConcurrentContext;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
/**
* A service holding a concurrent context.
* @author Eduardo Martins
*/
public class ConcurrentContextService implements Service<ConcurrentContext> {
private final ConcurrentContext concurrentContext;
private volatile boolean started;
public ConcurrentContextService(ConcurrentContext concurrentContext) {
this.concurrentContext = concurrentContext;
}
@Override
public void start(StartContext context) throws StartException {
started = true;
concurrentContext.setServiceName(context.getController().getName());
}
@Override
public void stop(StopContext context) {
started = false;
}
@Override
public ConcurrentContext getValue() throws IllegalStateException, IllegalArgumentException {
if(!started) {
throw EeLogger.ROOT_LOGGER.serviceNotStarted();
}
return concurrentContext;
}
}
| 2,242 | 34.603175 | 96 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/service/ManagedExecutorServiceService.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.concurrent.service;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.glassfish.enterprise.concurrent.AbstractManagedExecutorService;
import org.glassfish.enterprise.concurrent.ContextServiceImpl;
import org.glassfish.enterprise.concurrent.ManagedExecutorServiceAdapter;
import org.jboss.as.ee.concurrent.ManagedExecutorServiceImpl;
import org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.wildfly.extension.requestcontroller.ControlPoint;
import org.wildfly.extension.requestcontroller.RequestController;
/**
* Service responsible for creating, starting and stopping a ManagedExecutorServiceImpl.
* <p/>
* Note that the service's value is the executor's adapter, which does not allows lifecyle related invocations.
*
* @author Eduardo Martins
*/
public class ManagedExecutorServiceService extends EEConcurrentAbstractService<ManagedExecutorServiceAdapter> {
private volatile ManagedExecutorServiceImpl executorService;
private final Consumer<ManagedExecutorServiceAdapter> consumer;
private final String name;
private final Supplier<ManagedThreadFactoryImpl> managedThreadFactorySupplier;
private final long hungTaskThreshold;
private final long hungTaskTerminationPeriod;
private final boolean longRunningTasks;
private final int corePoolSize;
private final int maxPoolSize;
private final long keepAliveTime;
private final TimeUnit keepAliveTimeUnit;
private final long threadLifeTime;
private final int queueCapacity;
private final DelegatingSupplier<ContextServiceImpl> contextServiceSupplier = new DelegatingSupplier<>();
private final AbstractManagedExecutorService.RejectPolicy rejectPolicy;
private final Integer threadPriority;
private final Supplier<RequestController> requestControllerSupplier;
private ControlPoint controlPoint;
private final Supplier<ManagedExecutorHungTasksPeriodicTerminationService> hungTasksPeriodicTerminationService;
private Future hungTasksPeriodicTerminationFuture;
/**
* @param consumer
* @param contextServiceSupplier
* @param managedThreadFactorySupplier
* @param requestControllerSupplier
* @param name
* @param jndiName
* @param hungTaskThreshold
* @param hungTaskTerminationPeriod
* @param longRunningTasks
* @param corePoolSize
* @param maxPoolSize
* @param keepAliveTime
* @param keepAliveTimeUnit
* @param threadLifeTime
* @param queueCapacity
* @param rejectPolicy
* @param threadPriority
* @see ManagedExecutorServiceImpl#ManagedExecutorServiceImpl(String, org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl, long, boolean, int, int, long, java.util.concurrent.TimeUnit, long, int, org.glassfish.enterprise.concurrent.ContextServiceImpl, org.glassfish.enterprise.concurrent.AbstractManagedExecutorService.RejectPolicy, org.wildfly.extension.requestcontroller.ControlPoint)
*/
public ManagedExecutorServiceService(final Consumer<ManagedExecutorServiceAdapter> consumer,
final Supplier<ContextServiceImpl> contextServiceSupplier,
final Supplier<ManagedThreadFactoryImpl> managedThreadFactorySupplier,
final Supplier<RequestController> requestControllerSupplier,
String name, String jndiName, long hungTaskThreshold, long hungTaskTerminationPeriod, boolean longRunningTasks, int corePoolSize, int maxPoolSize, long keepAliveTime, TimeUnit keepAliveTimeUnit, long threadLifeTime, int queueCapacity, AbstractManagedExecutorService.RejectPolicy rejectPolicy, Integer threadPriority, final Supplier<ManagedExecutorHungTasksPeriodicTerminationService> hungTasksPeriodicTerminationService) {
super(jndiName);
this.consumer = consumer;
this.contextServiceSupplier.set(contextServiceSupplier);
this.managedThreadFactorySupplier = managedThreadFactorySupplier;
this.requestControllerSupplier = requestControllerSupplier;
this.name = name;
this.hungTaskThreshold = hungTaskThreshold;
this.hungTaskTerminationPeriod = hungTaskTerminationPeriod;
this.longRunningTasks = longRunningTasks;
this.corePoolSize = corePoolSize;
this.maxPoolSize = maxPoolSize;
this.keepAliveTime = keepAliveTime;
this.keepAliveTimeUnit = keepAliveTimeUnit;
this.threadLifeTime = threadLifeTime;
this.queueCapacity = queueCapacity;
this.rejectPolicy = rejectPolicy;
this.threadPriority = threadPriority;
this.hungTasksPeriodicTerminationService = hungTasksPeriodicTerminationService;
}
@Override
void startValue(StartContext context) throws StartException {
final int priority;
if (threadPriority != null) {
priority = threadPriority;
} else {
ManagedThreadFactoryImpl managedThreadFactory = managedThreadFactorySupplier != null ? managedThreadFactorySupplier.get() : null;
priority = managedThreadFactory != null ? managedThreadFactory.getPriority() : Thread.NORM_PRIORITY;
}
ManagedThreadFactoryImpl managedThreadFactory = new ManagedThreadFactoryImpl("EE-ManagedExecutorService-"+name, null, priority);
if (requestControllerSupplier != null) {
final RequestController requestController = requestControllerSupplier.get();
controlPoint = requestController != null ? requestController.getControlPoint(name, "managed-executor-service") : null;
}
executorService = new ManagedExecutorServiceImpl(name, managedThreadFactory, hungTaskThreshold, longRunningTasks, corePoolSize, maxPoolSize, keepAliveTime, keepAliveTimeUnit, threadLifeTime, queueCapacity, contextServiceSupplier != null ? contextServiceSupplier.get() : null, rejectPolicy, controlPoint);
if (hungTaskThreshold > 0 && hungTaskTerminationPeriod > 0) {
hungTasksPeriodicTerminationFuture = hungTasksPeriodicTerminationService.get().startHungTaskPeriodicTermination(executorService, hungTaskTerminationPeriod);
}
consumer.accept(executorService.getAdapter());
}
@Override
void stopValue(StopContext context) {
if (executorService != null) {
if (hungTasksPeriodicTerminationFuture != null) {
hungTasksPeriodicTerminationFuture.cancel(true);
}
executorService.shutdownNow();
executorService.getManagedThreadFactory().stop();
this.executorService = null;
}
if(controlPoint != null) {
requestControllerSupplier.get().removeControlPoint(controlPoint);
}
consumer.accept(null);
}
public ManagedExecutorServiceAdapter getValue() throws IllegalStateException {
return getExecutorService().getAdapter();
}
public ManagedExecutorServiceImpl getExecutorService() throws IllegalStateException {
if (executorService == null) {
throw EeLogger.ROOT_LOGGER.concurrentServiceValueUninitialized();
}
return executorService;
}
public DelegatingSupplier<ContextServiceImpl> getContextServiceSupplier() {
return contextServiceSupplier;
}
}
| 8,631 | 48.895954 | 463 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/service/ManagedExecutorHungTasksPeriodicTerminationService.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2020 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.service;
import static org.wildfly.common.Assert.checkNotNullParamWithNullPointerException;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.ee.concurrent.ManagedExecutorWithHungThreads;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
/**
* Periodic hung task termination service for managed executors.
* @author emmartins
*/
public class ManagedExecutorHungTasksPeriodicTerminationService implements Service {
private volatile ScheduledExecutorService scheduler;
private Consumer<ManagedExecutorHungTasksPeriodicTerminationService> consumer;
public void install(OperationContext context) {
ServiceBuilder serviceBuilder = context.getServiceTarget()
.addService(ConcurrentServiceNames.HUNG_TASK_PERIODIC_TERMINATION_SERVICE_NAME)
.setInstance(this);
consumer = serviceBuilder.provides(ConcurrentServiceNames.HUNG_TASK_PERIODIC_TERMINATION_SERVICE_NAME);
serviceBuilder.install();
}
@Override
public void start(StartContext startContext) throws StartException {
consumer.accept(this);
}
@Override
public void stop(StopContext stopContext) {
if (scheduler != null) {
scheduler.shutdownNow();
scheduler = null;
}
consumer.accept(null);
}
/**
* Starts the periodic hang task termination for the specified executor.
* @param executor
* @param hungTaskTerminationPeriod
* @return a Future instance which may be used to cancel the hung task periodic termination
*/
public synchronized Future startHungTaskPeriodicTermination(final ManagedExecutorWithHungThreads executor, final long hungTaskTerminationPeriod) {
checkNotNullParamWithNullPointerException("executor", executor);
if (hungTaskTerminationPeriod <= 0) {
throw new IllegalArgumentException("hungTaskTerminationPeriod is not > 0");
}
if (scheduler == null) {
scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory());
}
return scheduler.scheduleAtFixedRate(() -> executor.terminateHungTasks(), hungTaskTerminationPeriod, hungTaskTerminationPeriod, TimeUnit.MILLISECONDS);
}
/**
* Wrapper of default threadfactory, just to override thread names.
*/
private static class ThreadFactory implements java.util.concurrent.ThreadFactory {
private final java.util.concurrent.ThreadFactory threadFactory = Executors.defaultThreadFactory();
/**
*
* @param r
* @return
*/
@Override
public Thread newThread(Runnable r) {
final Thread t = threadFactory.newThread(r);
t.setName("managed-executor-hungtaskperiodictermination-"+t.getName());
return t;
}
}
}
| 3,941 | 37.647059 | 159 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/service/ManagedScheduledExecutorServiceService.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.concurrent.service;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.glassfish.enterprise.concurrent.AbstractManagedExecutorService;
import org.glassfish.enterprise.concurrent.ContextServiceImpl;
import org.glassfish.enterprise.concurrent.ManagedScheduledExecutorServiceAdapter;
import org.jboss.as.ee.concurrent.ManagedScheduledExecutorServiceImpl;
import org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.wildfly.extension.requestcontroller.ControlPoint;
import org.wildfly.extension.requestcontroller.RequestController;
/**
* Service responsible for creating, starting and stopping a ManagedScheduledExecutorServiceImpl.
* <p/>
* Note that the service's value is the executor's adapter, which does not allows lifecyle related invocations.
*
* @author Eduardo Martins
*/
public class ManagedScheduledExecutorServiceService extends EEConcurrentAbstractService<ManagedScheduledExecutorServiceAdapter> {
private volatile ManagedScheduledExecutorServiceImpl executorService;
private final Consumer<ManagedScheduledExecutorServiceAdapter> consumer;
private final String name;
private final Supplier<ManagedThreadFactoryImpl> managedThreadFactorySupplier;
private final long hungTaskThreshold;
private final long hungTaskTerminationPeriod;
private final boolean longRunningTasks;
private final int corePoolSize;
private final long keepAliveTime;
private final TimeUnit keepAliveTimeUnit;
private final long threadLifeTime;
private final DelegatingSupplier<ContextServiceImpl> contextServiceSupplier = new DelegatingSupplier<>();
private final AbstractManagedExecutorService.RejectPolicy rejectPolicy;
private final Integer threadPriority;
private final Supplier<RequestController> requestControllerSupplier;
private ControlPoint controlPoint;
private final Supplier<ManagedExecutorHungTasksPeriodicTerminationService> hungTasksPeriodicTerminationService;
private Future hungTasksPeriodicTerminationFuture;
/**
* @param consumer
* @param contextServiceSupplier
* @param managedThreadFactorySupplier
* @param requestControllerSupplier
* @param name
* @param jndiName
* @param hungTaskThreshold
* @param longRunningTasks
* @param corePoolSize
* @param keepAliveTime
* @param keepAliveTimeUnit
* @param threadLifeTime
* @param rejectPolicy
* @param threadPriority
* @see ManagedScheduledExecutorServiceImpl#ManagedScheduledExecutorServiceImpl(String, org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl, long, boolean, int, long, java.util.concurrent.TimeUnit, long, org.glassfish.enterprise.concurrent.ContextServiceImpl, org.glassfish.enterprise.concurrent.AbstractManagedExecutorService.RejectPolicy, org.wildfly.extension.requestcontroller.ControlPoint)
*/
public ManagedScheduledExecutorServiceService(final Consumer<ManagedScheduledExecutorServiceAdapter> consumer,
final Supplier<ContextServiceImpl> contextServiceSupplier,
final Supplier<ManagedThreadFactoryImpl> managedThreadFactorySupplier,
final Supplier<RequestController> requestControllerSupplier,
String name, String jndiName, long hungTaskThreshold, long hungTaskTerminationPeriod, boolean longRunningTasks, int corePoolSize, long keepAliveTime, TimeUnit keepAliveTimeUnit, long threadLifeTime, AbstractManagedExecutorService.RejectPolicy rejectPolicy, Integer threadPriority, final Supplier<ManagedExecutorHungTasksPeriodicTerminationService> hungTasksPeriodicTerminationService) {
super(jndiName);
this.consumer = consumer;
this.contextServiceSupplier.set(contextServiceSupplier);
this.managedThreadFactorySupplier = managedThreadFactorySupplier;
this.requestControllerSupplier = requestControllerSupplier;
this.name = name;
this.hungTaskThreshold = hungTaskThreshold;
this.hungTaskTerminationPeriod = hungTaskTerminationPeriod;
this.longRunningTasks = longRunningTasks;
this.corePoolSize = corePoolSize;
this.keepAliveTime = keepAliveTime;
this.keepAliveTimeUnit = keepAliveTimeUnit;
this.threadLifeTime = threadLifeTime;
this.rejectPolicy = rejectPolicy;
this.threadPriority = threadPriority;
this.hungTasksPeriodicTerminationService = hungTasksPeriodicTerminationService;
}
@Override
void startValue(StartContext context) throws StartException {
final int priority;
if (threadPriority != null) {
priority = threadPriority;
} else {
ManagedThreadFactoryImpl managedThreadFactory = managedThreadFactorySupplier != null ? managedThreadFactorySupplier.get() : null;
priority = managedThreadFactory != null ? managedThreadFactory.getPriority() : Thread.NORM_PRIORITY;
}
ManagedThreadFactoryImpl managedThreadFactory = new ManagedThreadFactoryImpl("EE-ManagedScheduledExecutorService-" + name, null, priority);
if (requestControllerSupplier != null) {
final RequestController requestController = requestControllerSupplier.get();
controlPoint = requestController != null ? requestController.getControlPoint(name, "managed-scheduled-executor-service") : null;
}
executorService = new ManagedScheduledExecutorServiceImpl(name, managedThreadFactory, hungTaskThreshold, longRunningTasks, corePoolSize, keepAliveTime, keepAliveTimeUnit, threadLifeTime, contextServiceSupplier != null ? contextServiceSupplier.get() : null, rejectPolicy, controlPoint);
if (hungTaskThreshold > 0 && hungTaskTerminationPeriod > 0) {
hungTasksPeriodicTerminationFuture = hungTasksPeriodicTerminationService.get().startHungTaskPeriodicTermination(executorService, hungTaskTerminationPeriod);
}
consumer.accept(executorService.getAdapter());
}
@Override
void stopValue(StopContext context) {
consumer.accept(null);
if (executorService != null) {
if (hungTasksPeriodicTerminationFuture != null) {
hungTasksPeriodicTerminationFuture.cancel(true);
}
executorService.shutdownNow();
executorService.getManagedThreadFactory().stop();
this.executorService = null;
}
if(controlPoint != null) {
requestControllerSupplier.get().removeControlPoint(controlPoint);
}
}
public ManagedScheduledExecutorServiceAdapter getValue() throws IllegalStateException {
return getExecutorService().getAdapter();
}
public ManagedScheduledExecutorServiceImpl getExecutorService() throws IllegalStateException {
if (executorService == null) {
throw EeLogger.ROOT_LOGGER.concurrentServiceValueUninitialized();
}
return executorService;
}
public DelegatingSupplier<ContextServiceImpl> getContextServiceSupplier() {
return contextServiceSupplier;
}
}
| 8,489 | 50.454545 | 436 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/service/ContextServiceService.java | /*
* 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.ee.concurrent.service;
import org.glassfish.enterprise.concurrent.spi.ContextSetupProvider;
import org.jboss.as.ee.concurrent.ContextServiceTypesConfiguration;
import org.jboss.as.ee.concurrent.ContextServiceImpl;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StopContext;
/**
* Service responsible for managing a context service impl's lifecycle.
*
* @author Eduardo Martins
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public final class ContextServiceService extends EEConcurrentAbstractService<ContextServiceImpl> {
private final String name;
private final ContextSetupProvider contextSetupProvider;
private final ContextServiceTypesConfiguration contextServiceTypesConfiguration;
private volatile ContextServiceImpl contextService;
public ContextServiceService(final String name, final String jndiName, final ContextSetupProvider contextSetupProvider, final ContextServiceTypesConfiguration contextServiceTypesConfiguration) {
super(jndiName);
this.name = name;
this.contextSetupProvider = contextSetupProvider;
this.contextServiceTypesConfiguration = contextServiceTypesConfiguration;
}
@Override
void startValue(final StartContext context) {
contextService = new ContextServiceImpl(name, contextSetupProvider, contextServiceTypesConfiguration);
}
@Override
void stopValue(final StopContext context) {
contextService = null;
}
public ContextServiceImpl getValue() throws IllegalStateException {
final ContextServiceImpl value = this.contextService;
if (value == null) {
throw EeLogger.ROOT_LOGGER.concurrentServiceValueUninitialized();
}
return value;
}
}
| 2,858 | 39.267606 | 198 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/ThreadContextProviderContextHandleFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.handle;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.PrivilegedAction;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import jakarta.enterprise.concurrent.ContextService;
import jakarta.enterprise.concurrent.spi.ThreadContextProvider;
import jakarta.enterprise.concurrent.spi.ThreadContextRestorer;
import jakarta.enterprise.concurrent.spi.ThreadContextSnapshot;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* The context handle factory responsible for saving and setting the context for a deployement's ThreadContextProvider.
*
* @author Eduardo Martins
*/
public class ThreadContextProviderContextHandleFactory implements EE10ContextHandleFactory {
private static final int BASE_PRIORITY = 1000;
private final ThreadContextProvider threadContextProvider;
private final int priority;
public ThreadContextProviderContextHandleFactory(ThreadContextProvider threadContextProvider, int priority) {
this.threadContextProvider = threadContextProvider;
this.priority = BASE_PRIORITY + priority;
}
@Override
public String getContextType() {
return threadContextProvider.getThreadContextType();
}
@Override
public SetupContextHandle clearedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
return new ContextHandle(threadContextProvider, contextObjectProperties, true);
}
@Override
public SetupContextHandle propagatedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
return new ContextHandle(threadContextProvider, contextObjectProperties, false);
}
@Override
public String getName() {
return getContextType();
}
@Override
public int getChainPriority() {
return priority;
}
@Override
public void writeSetupContextHandle(SetupContextHandle contextHandle, ObjectOutputStream out) throws IOException {
out.writeObject(contextHandle);
}
@Override
public SetupContextHandle readSetupContextHandle(ObjectInputStream in) throws IOException, ClassNotFoundException {
return (ContextHandle) in.readObject();
}
private static class ContextHandle implements SetupContextHandle {
private static final long serialVersionUID = 842115413317072688L;
private final String factoryName;
private final ThreadContextSnapshot savedContextSnapshot;
private ContextHandle(ThreadContextProvider threadContextProvider, Map<String, String> contextObjectProperties, boolean cleared) {
this.factoryName = threadContextProvider.getThreadContextType();
this.savedContextSnapshot = cleared ? threadContextProvider.clearedContext(contextObjectProperties) : threadContextProvider.currentContext(contextObjectProperties);
}
@Override
public String getFactoryName() {
return factoryName;
}
@Override
public ResetContextHandle setup() throws IllegalStateException {
final ThreadContextRestorer threadContextRestorer = savedContextSnapshot.begin();
return new ResetContextHandle() {
@Override
public void reset() {
threadContextRestorer.endContext();
}
@Override
public String getFactoryName() {
return factoryName;
}
};
}
}
/**
* Retrieves a collection containing a new factory for each ThreadContextProvider found on the specified ClassLoader, through the ServiceLoader framework.
* @param classLoader
* @return
*/
public static Collection<ThreadContextProviderContextHandleFactory> fromServiceLoader(ClassLoader classLoader) {
if(WildFlySecurityManager.isChecking()) {
return WildFlySecurityManager.doUnchecked((PrivilegedAction<Collection<ThreadContextProviderContextHandleFactory>>) () -> fromServiceLoaderUnchecked(classLoader));
} else {
return fromServiceLoaderUnchecked(classLoader);
}
}
private static Collection<ThreadContextProviderContextHandleFactory> fromServiceLoaderUnchecked(ClassLoader classLoader) {
final Set<ThreadContextProviderContextHandleFactory> factories = new HashSet<>();
final ServiceLoader<ThreadContextProvider> threadContextProviderServiceLoader = ServiceLoader.load(ThreadContextProvider.class, classLoader);
final Iterator<ThreadContextProvider> threadContextProviderIterator = threadContextProviderServiceLoader.iterator();
int count = 0;
while (threadContextProviderIterator.hasNext()) {
final ThreadContextProvider threadContextProvider = threadContextProviderIterator.next();
factories.add(new ThreadContextProviderContextHandleFactory(threadContextProvider, count));
count++;
}
return factories;
}
}
| 5,897 | 39.122449 | 176 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/ClassLoaderContextHandleFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.concurrent.handle;
import jakarta.enterprise.concurrent.ContextServiceDefinition;
import org.jboss.as.ee.logging.EeLogger;
import org.wildfly.security.manager.WildFlySecurityManager;
import jakarta.enterprise.concurrent.ContextService;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
/**
* A context handle factory which is responsible for saving and setting proper classloading context.
*
* @author Eduardo Martins
*/
public class ClassLoaderContextHandleFactory implements EE10ContextHandleFactory {
public static final String NAME = "CLASSLOADER";
private final ClassLoader classLoader;
public ClassLoaderContextHandleFactory(ClassLoader classLoader) {
this.classLoader = classLoader;
}
@Override
public String getContextType() {
return ContextServiceDefinition.APPLICATION;
}
@Override
public SetupContextHandle propagatedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
return new ClassLoaderSetupContextHandle(classLoader);
}
@Override
public SetupContextHandle clearedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
return new ClassLoaderSetupContextHandle(null);
}
@Override
public String getName() {
return NAME;
}
@Override
public int getChainPriority() {
return 100;
}
@Override
public void writeSetupContextHandle(SetupContextHandle contextHandle, ObjectOutputStream out) throws IOException {
out.writeBoolean(((ClassLoaderSetupContextHandle)contextHandle).classLoader != null);
}
@Override
public SetupContextHandle readSetupContextHandle(ObjectInputStream in) throws IOException, ClassNotFoundException {
return new ClassLoaderSetupContextHandle(in.readBoolean() ? classLoader : null);
}
static class ClassLoaderSetupContextHandle implements SetupContextHandle {
private static final long serialVersionUID = -2669625643479981561L;
private final ClassLoader classLoader;
ClassLoaderSetupContextHandle(ClassLoader classLoader) {
this.classLoader = classLoader;
}
@Override
public ResetContextHandle setup() throws IllegalStateException {
final ClassLoaderResetContextHandle resetContextHandle = new ClassLoaderResetContextHandle(WildFlySecurityManager.getCurrentContextClassLoaderPrivileged());
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
return resetContextHandle;
}
@Override
public String getFactoryName() {
return NAME;
}
// serialization
private void writeObject(ObjectOutputStream out) throws IOException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
}
private static class ClassLoaderResetContextHandle implements ResetContextHandle {
private static final long serialVersionUID = -579159484365527468L;
private final ClassLoader previous;
private ClassLoaderResetContextHandle(ClassLoader previous) {
this.previous = previous;
}
@Override
public void reset() {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(previous);
}
@Override
public String getFactoryName() {
return NAME;
}
// serialization
private void writeObject(ObjectOutputStream out) throws IOException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
}
}
| 5,147 | 34.260274 | 168 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/ContextHandleFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.concurrent.handle;
import jakarta.enterprise.concurrent.ContextService;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
/**
* The factory responsible for creating the context handles with the current context saved
*
* @author Eduardo Martins
*/
public interface ContextHandleFactory {
/**
* @param contextService
* @param contextObjectProperties
* @return
* @see org.glassfish.enterprise.concurrent.spi.ContextSetupProvider#saveContext(jakarta.enterprise.concurrent.ContextService, java.util.Map)
*/
SetupContextHandle saveContext(ContextService contextService, Map<String, String> contextObjectProperties);
/**
* The factory priority is used to define the order of handles when chained. The handle with the lowest priority is the first in the chain.
* @return
*/
int getChainPriority();
/**
* Retrieves the factory's name.
* @return
*/
String getName();
/**
* Writes the handle to the specified output stream.
* @param contextHandle
* @param out
*/
void writeSetupContextHandle(SetupContextHandle contextHandle, ObjectOutputStream out) throws IOException;
/**
* Reads a handle from the specified input stream.
* @param in
* @return
*/
SetupContextHandle readSetupContextHandle(ObjectInputStream in) throws IOException, ClassNotFoundException;
}
| 2,511 | 33.888889 | 145 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/TransactionContextHandleFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.handle;
import jakarta.enterprise.concurrent.ContextService;
import jakarta.enterprise.concurrent.ContextServiceDefinition;
import jakarta.enterprise.concurrent.ManagedTask;
import jakarta.transaction.SystemException;
import jakarta.transaction.Transaction;
import jakarta.transaction.TransactionManager;
import org.jboss.as.ee.logging.EeLogger;
import org.wildfly.transaction.client.ContextTransactionManager;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
/**
* FIXME *FOLLOW UP* delete unused TransactionLeakContextHandleFactory and TransactionSetupProviderImpl, and deactivate unused logger msgs
* A context handle factory which is responsible for handling the context type ContextServiceDefinition.TRANSACTION.
*
* @author Eduardo Martins
*/
public class TransactionContextHandleFactory implements EE10ContextHandleFactory {
public static final String NAME = ContextServiceDefinition.TRANSACTION;
@Override
public String getContextType() {
return NAME;
}
@Override
public SetupContextHandle clearedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
if (contextObjectProperties != null && ManagedTask.USE_TRANSACTION_OF_EXECUTION_THREAD.equals(contextObjectProperties.get(ManagedTask.TRANSACTION))) {
// override to unchanged
return null;
}
return new ClearedSetupContextHandle(ContextTransactionManager.getInstance());
}
@Override
public SetupContextHandle propagatedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
// TODO *FOLLOW UP* not required by spec, but should we support it?!?
return unchangedContext(contextService, contextObjectProperties);
}
@Override
public SetupContextHandle unchangedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
if (contextObjectProperties != null && ManagedTask.SUSPEND.equals(contextObjectProperties.get(ManagedTask.TRANSACTION))) {
// override to cleared
return new ClearedSetupContextHandle(ContextTransactionManager.getInstance());
}
return null;
}
@Override
public String getName() {
return NAME;
}
@Override
public int getChainPriority() {
// this should have a top priority since the legacy TransactionSetupProvider was executed before the contexthandlefactories
return 10;
}
@Override
public void writeSetupContextHandle(SetupContextHandle contextHandle, ObjectOutputStream out) throws IOException {
}
@Override
public SetupContextHandle readSetupContextHandle(ObjectInputStream in) throws IOException, ClassNotFoundException {
return new ClearedSetupContextHandle(ContextTransactionManager.getInstance());
}
private static class ClearedSetupContextHandle implements SetupContextHandle {
private static final long serialVersionUID = 5751959084132309889L;
private final TransactionManager transactionManager;
private ClearedSetupContextHandle(TransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
@Override
public ResetContextHandle setup() throws IllegalStateException {
Transaction transactionOnSetup = null;
if(transactionManager != null) {
try {
transactionOnSetup = transactionManager.suspend();
} catch (SystemException e) {
EeLogger.ROOT_LOGGER.failedToSuspendTransaction(e);
}
}
return new ClearedResetContextHandle(transactionManager, transactionOnSetup);
}
@Override
public String getFactoryName() {
return NAME;
}
// serialization
private void writeObject(ObjectOutputStream out) throws IOException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
}
private static class ClearedResetContextHandle implements ResetContextHandle {
private static final long serialVersionUID = 6601621971677254974L;
private final TransactionManager transactionManager;
private final Transaction transactionOnSetup;
private ClearedResetContextHandle(TransactionManager transactionManager, Transaction transactionOnSetup) {
this.transactionManager = transactionManager;
this.transactionOnSetup = transactionOnSetup;
}
@Override
public void reset() {
try {
transactionManager.resume(transactionOnSetup);
} catch (Throwable e) {
EeLogger.ROOT_LOGGER.failedToResumeTransaction(e);
}
}
@Override
public String getFactoryName() {
return NAME;
}
// serialization
private void writeObject(ObjectOutputStream out) throws IOException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
}
}
| 6,305 | 37.218182 | 158 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/NullContextHandle.java | package org.jboss.as.ee.concurrent.handle;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* A context handle without invocation context to set. For now it provides only the setup and reset of TCCL captured at handle creation.
* @author Eduardo Martins
*/
public class NullContextHandle implements SetupContextHandle {
private static final long serialVersionUID = 2928225776829357837L;
private final SetupContextHandle tcclSetupHandle;
public NullContextHandle() {
tcclSetupHandle = new ClassLoaderContextHandleFactory.ClassLoaderSetupContextHandle(WildFlySecurityManager.getCurrentContextClassLoaderPrivileged());
}
@Override
public ResetContextHandle setup() throws IllegalStateException {
return tcclSetupHandle.setup();
}
@Override
public String getFactoryName() {
return "NULL";
}
}
| 878 | 29.310345 | 157 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/OtherEESetupActionsContextHandleFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.concurrent.handle;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import jakarta.enterprise.concurrent.ContextService;
import jakarta.enterprise.concurrent.ContextServiceDefinition;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.server.deployment.SetupAction;
/**
* The context handle factory responsible for setting EE setup actions in the invocation context.
*
* @author Eduardo Martins
*/
public class OtherEESetupActionsContextHandleFactory implements EE10ContextHandleFactory {
public static final String NAME = "EE_SETUP_ACTIONS";
private final List<SetupAction> setupActions;
private final SetupContextHandle clearedContextHandle;
public OtherEESetupActionsContextHandleFactory(List<SetupAction> setupActions) {
this.setupActions = setupActions;
this.clearedContextHandle = new ClearedSetupContextHandle(setupActions);
}
@Override
public String getContextType() {
return ContextServiceDefinition.APPLICATION;
}
@Override
public SetupContextHandle clearedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
return clearedContextHandle;
}
@Override
public SetupContextHandle propagatedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
return new PropagatedSetupContextHandle(setupActions);
}
@Override
public String getName() {
return NAME;
}
@Override
public int getChainPriority() {
return 400;
}
@Override
public void writeSetupContextHandle(SetupContextHandle contextHandle, ObjectOutputStream out) throws IOException {
out.writeBoolean(contextHandle != clearedContextHandle);
}
@Override
public SetupContextHandle readSetupContextHandle(ObjectInputStream in) throws IOException, ClassNotFoundException {
return in.readBoolean() ? new PropagatedSetupContextHandle(setupActions) : clearedContextHandle;
}
private static class PropagatedSetupContextHandle implements SetupContextHandle {
private static final long serialVersionUID = 5698880356954066079L;
private final List<SetupAction> setupActions;
private PropagatedSetupContextHandle(List<SetupAction> setupActions) {
this.setupActions = setupActions;
}
@Override
public String getFactoryName() {
return NAME;
}
@Override
public org.jboss.as.ee.concurrent.handle.ResetContextHandle setup() throws IllegalStateException {
final LinkedList<SetupAction> resetActions = new LinkedList<>();
final PropagatedResetContextHandle resetContextHandle = new PropagatedResetContextHandle(resetActions);
try {
for (SetupAction setupAction : this.setupActions) {
setupAction.setup(Collections.<String, Object>emptyMap());
resetActions.addFirst(setupAction);
}
} catch (Error | RuntimeException e) {
resetContextHandle.reset();
throw e;
}
return resetContextHandle;
}
// serialization
private void writeObject(ObjectOutputStream out) throws IOException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
}
private static class PropagatedResetContextHandle implements ResetContextHandle {
private static final long serialVersionUID = -1279030727101664631L;
private List<SetupAction> resetActions;
private PropagatedResetContextHandle(List<SetupAction> resetActions) {
this.resetActions = resetActions;
}
@Override
public String getFactoryName() {
return NAME;
}
@Override
public void reset() {
if(resetActions != null) {
for (SetupAction resetAction : this.resetActions) {
try {
resetAction.teardown(Collections.<String, Object>emptyMap());
} catch (Throwable e) {
EeLogger.ROOT_LOGGER.debug("failed to teardown action",e);
}
}
resetActions = null;
}
}
// serialization
private void writeObject(ObjectOutputStream out) throws IOException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
}
private static class ClearedSetupContextHandle implements SetupContextHandle {
private static final long serialVersionUID = 175538978733960332L;
private final List<SetupAction> setupActions;
private ClearedSetupContextHandle(List<SetupAction> setupActions) {
this.setupActions = setupActions;
}
@Override
public String getFactoryName() {
return NAME;
}
@Override
public org.jboss.as.ee.concurrent.handle.ResetContextHandle setup() throws IllegalStateException {
// we probably should instead have a thread stack with the current setup actions and restore current on reset?
new PropagatedResetContextHandle(setupActions).reset();
return new ResetContextHandle() {
@Override
public void reset() {
}
@Override
public String getFactoryName() {
return NAME;
}
};
}
// serialization
private void writeObject(ObjectOutputStream out) throws IOException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
}
}
| 7,538 | 34.9 | 125 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/EE10ContextHandleFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.handle;
import jakarta.enterprise.concurrent.ContextService;
import java.util.Map;
/**
* The EE10 ContextHandleFactory, which should replace the legacy one once all impls are migrated.
* @author emmartins
*/
public interface EE10ContextHandleFactory extends ContextHandleFactory {
/**
*
* @return the context type the factory provides handles for
*/
String getContextType();
/**
* @param contextService
* @param contextObjectProperties
* @return a SetupContextHandle which partially or fully clears the factory's context type
*/
SetupContextHandle clearedContext(ContextService contextService, Map<String, String> contextObjectProperties);
/**
* @param contextService
* @param contextObjectProperties
* @return a SetupContextHandle which partially or fully propagates the factory's context type
*/
SetupContextHandle propagatedContext(ContextService contextService, Map<String, String> contextObjectProperties);
/**
* @param contextService
* @param contextObjectProperties
* @return a SetupContextHandle which partially or fully unchanges the factory's context type
*/
default SetupContextHandle unchangedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
return null;
}
@Override
default SetupContextHandle saveContext(ContextService contextService, Map<String, String> contextObjectProperties) {
throw new UnsupportedOperationException();
}
}
| 2,272 | 34.515625 | 125 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/TransactionLeakContextHandleFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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.ee.concurrent.handle;
import org.jboss.as.ee.logging.EeLogger;
import org.wildfly.transaction.client.ContextTransactionManager;
import jakarta.enterprise.concurrent.ContextService;
import jakarta.transaction.Status;
import jakarta.transaction.SystemException;
import jakarta.transaction.Transaction;
import jakarta.transaction.TransactionManager;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
/**
* A context handle factory which is responsible for preventing transaction leaks.
*
* @author Eduardo Martins
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public class TransactionLeakContextHandleFactory implements ContextHandleFactory {
public static final String NAME = "TRANSACTION_LEAK";
@Override
public SetupContextHandle saveContext(ContextService contextService, Map<String, String> contextObjectProperties) {
return new TransactionLeakSetupContextHandle(ContextTransactionManager.getInstance());
}
@Override
public String getName() {
return NAME;
}
@Override
public int getChainPriority() {
// must be higher/after other ee setup actions, which include the connector invocation context setup
return 600;
}
@Override
public void writeSetupContextHandle(SetupContextHandle contextHandle, ObjectOutputStream out) throws IOException {
}
@Override
public SetupContextHandle readSetupContextHandle(ObjectInputStream in) throws IOException, ClassNotFoundException {
return new TransactionLeakSetupContextHandle(ContextTransactionManager.getInstance());
}
private static class TransactionLeakSetupContextHandle implements SetupContextHandle {
private static final long serialVersionUID = -8142799455606311295L;
private final TransactionManager transactionManager;
private TransactionLeakSetupContextHandle(TransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
@Override
public ResetContextHandle setup() throws IllegalStateException {
Transaction transactionOnSetup = null;
if(transactionManager != null) {
try {
transactionOnSetup = transactionManager.getTransaction();
} catch (SystemException e) {
throw new IllegalStateException(e);
}
}
return new TransactionLeakResetContextHandle(transactionManager, transactionOnSetup);
}
@Override
public String getFactoryName() {
return NAME;
}
// serialization
private void writeObject(ObjectOutputStream out) throws IOException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
}
private static class TransactionLeakResetContextHandle implements ResetContextHandle {
private static final long serialVersionUID = -1726741825781759990L;
private final TransactionManager transactionManager;
private final Transaction transactionOnSetup;
private TransactionLeakResetContextHandle(TransactionManager transactionManager, Transaction transactionOnSetup) {
this.transactionManager = transactionManager;
this.transactionOnSetup = transactionOnSetup;
}
@Override
public void reset() {
if(transactionManager != null) {
try {
final Transaction transactionOnReset = transactionManager.getTransaction();
if(transactionOnReset != null && !transactionOnReset.equals(transactionOnSetup)) {
switch (transactionOnReset.getStatus()) {
case Status.STATUS_ACTIVE:
case Status.STATUS_COMMITTING:
case Status.STATUS_MARKED_ROLLBACK:
case Status.STATUS_PREPARING:
case Status.STATUS_ROLLING_BACK:
case Status.STATUS_PREPARED:
try {
EeLogger.ROOT_LOGGER.rollbackOfTransactionStartedInEEConcurrentInvocation();
transactionManager.rollback();
} catch (Throwable e) {
EeLogger.ROOT_LOGGER.failedToRollbackTransaction(e);
} finally {
try {
transactionManager.suspend();
} catch (Throwable e) {
EeLogger.ROOT_LOGGER.failedToSuspendTransaction(e);
}
}
}
}
} catch (SystemException e) {
EeLogger.ROOT_LOGGER.systemErrorWhileCheckingForTransactionLeak(e);
}
}
}
@Override
public String getFactoryName() {
return NAME;
}
// serialization
private void writeObject(ObjectOutputStream out) throws IOException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
}
}
| 6,847 | 39.046784 | 122 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/NamingContextHandleFactory.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.concurrent.handle;
import jakarta.enterprise.concurrent.ContextServiceDefinition;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.naming.WritableServiceBasedNamingStore;
import org.jboss.as.naming.context.NamespaceContextSelector;
import org.jboss.msc.service.ServiceName;
import jakarta.enterprise.concurrent.ContextService;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;
/**
* The context handle factory responsible for saving and setting the naming context.
*
* @author Eduardo Martins
*/
public class NamingContextHandleFactory implements EE10ContextHandleFactory {
private static final NamingContextHandle CLEARED_CONTEXT_HANDLE = new NamingContextHandle(null, null);
public static final String NAME = "NAMING";
private final NamespaceContextSelector namespaceContextSelector;
private final ServiceName duServiceName;
public NamingContextHandleFactory(NamespaceContextSelector namespaceContextSelector, ServiceName duServiceName) {
this.namespaceContextSelector = namespaceContextSelector;
this.duServiceName = duServiceName;
}
@Override
public String getContextType() {
return ContextServiceDefinition.APPLICATION;
}
@Override
public SetupContextHandle clearedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
return CLEARED_CONTEXT_HANDLE;
}
@Override
public SetupContextHandle propagatedContext(ContextService contextService, Map<String, String> contextObjectProperties) {
return new NamingContextHandle(namespaceContextSelector,duServiceName);
}
@Override
public String getName() {
return NAME;
}
@Override
public int getChainPriority() {
return 200;
}
@Override
public void writeSetupContextHandle(SetupContextHandle contextHandle, ObjectOutputStream out) throws IOException {
out.writeBoolean(contextHandle != CLEARED_CONTEXT_HANDLE);
}
@Override
public SetupContextHandle readSetupContextHandle(ObjectInputStream in) throws IOException, ClassNotFoundException {
return in.readBoolean() ? new NamingContextHandle(namespaceContextSelector,duServiceName) : CLEARED_CONTEXT_HANDLE;
}
private static class NamingContextHandle implements SetupContextHandle, ResetContextHandle {
private static final long serialVersionUID = -4631099493960707685L;
private final NamespaceContextSelector namespaceContextSelector;
private final ServiceName duServiceName;
private NamingContextHandle(NamespaceContextSelector namespaceContextSelector, ServiceName duServiceName) {
this.namespaceContextSelector = namespaceContextSelector;
this.duServiceName = duServiceName;
}
@Override
public String getFactoryName() {
return NAME;
}
@Override
public ResetContextHandle setup() throws IllegalStateException {
NamespaceContextSelector.pushCurrentSelector(namespaceContextSelector);
WritableServiceBasedNamingStore.pushOwner(duServiceName);
return this;
}
@Override
public void reset() {
WritableServiceBasedNamingStore.popOwner();
NamespaceContextSelector.popCurrentSelector();
}
// serialization
private void writeObject(ObjectOutputStream out) throws IOException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw EeLogger.ROOT_LOGGER.serializationMustBeHandledByTheFactory();
}
}
}
| 4,846 | 36 | 125 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/ResetContextHandle.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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.ee.concurrent.handle;
/**
* The Wildfly's EE context handle.
*
* @author Eduardo Martins
*/
public interface ResetContextHandle extends org.glassfish.enterprise.concurrent.spi.ContextHandle {
/**
* @see org.glassfish.enterprise.concurrent.spi.ContextSetupProvider#reset(org.glassfish.enterprise.concurrent.spi.ContextHandle)
*/
void reset();
/**
* Retrieves the name of the factory which built the handle.
* @return
*/
String getFactoryName();
}
| 1,538 | 35.642857 | 133 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/handle/SetupContextHandle.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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.ee.concurrent.handle;
/**
* The Wildfly's EE context handle that sets a saved invocation context.
*
* @author Eduardo Martins
*/
public interface SetupContextHandle extends org.glassfish.enterprise.concurrent.spi.ContextHandle {
/**
* @see org.glassfish.enterprise.concurrent.spi.ContextSetupProvider#setup(org.glassfish.enterprise.concurrent.spi.ContextHandle)
* @return
* @throws IllegalStateException
*/
ResetContextHandle setup() throws IllegalStateException;
/**
* Retrieves the name of the factory which built the handle.
* @return
*/
String getFactoryName();
}
| 1,670 | 36.977273 | 133 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/deployers/EEConcurrentContextProcessor.java | package org.jboss.as.ee.concurrent.deployers;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentConfigurator;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentNamingMode;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ee.concurrent.ConcurrentContext;
import org.jboss.as.ee.concurrent.ConcurrentContextInterceptor;
import org.jboss.as.ee.concurrent.ConcurrentContextSetupAction;
import org.jboss.as.ee.concurrent.handle.ClassLoaderContextHandleFactory;
import org.jboss.as.ee.concurrent.handle.ContextHandleFactory;
import org.jboss.as.ee.concurrent.handle.NamingContextHandleFactory;
import org.jboss.as.ee.concurrent.handle.OtherEESetupActionsContextHandleFactory;
import org.jboss.as.ee.concurrent.handle.ThreadContextProviderContextHandleFactory;
import org.jboss.as.ee.concurrent.handle.TransactionContextHandleFactory;
import org.jboss.as.ee.concurrent.service.ConcurrentContextService;
import org.jboss.as.ee.concurrent.service.ConcurrentServiceNames;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.naming.context.NamespaceContextSelector;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.invocation.ImmediateInterceptorFactory;
import org.jboss.invocation.InterceptorFactory;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import java.util.Collection;
import static org.jboss.as.server.deployment.Attachments.MODULE;
/**
* The DUP responsible for the base concurrent context configuration setup.
*
* @author Eduardo Martins
*/
public class EEConcurrentContextProcessor implements DeploymentUnitProcessor {
/**
* Name of the capability that ensures a local provider of transactions is present.
* Once its service is started, calls to the getInstance() methods of ContextTransactionManager,
* ContextTransactionSynchronizationRegistry and LocalUserTransaction can be made knowing
* that the global default TM, TSR and UT will be from that provider.
*/
private static final String LOCAL_TRANSACTION_PROVIDER_CAPABILITY = "org.wildfly.transactions.global-default-local-provider";
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
if(eeModuleDescription == null) {
return;
}
final CapabilityServiceSupport capabilityServiceSupport = phaseContext.getDeploymentUnit().getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
final ServiceName localTransactionProviderCapabilityServiceName = capabilityServiceSupport.hasCapability(LOCAL_TRANSACTION_PROVIDER_CAPABILITY) ? capabilityServiceSupport.getCapabilityServiceName(LOCAL_TRANSACTION_PROVIDER_CAPABILITY) : null;
processModuleDescription(eeModuleDescription, deploymentUnit, phaseContext, localTransactionProviderCapabilityServiceName);
final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
if (componentDescriptions == null) {
return;
}
for (ComponentDescription componentDescription : componentDescriptions) {
if (componentDescription.getNamingMode() == ComponentNamingMode.NONE) {
// skip components without namespace
continue;
}
processComponentDescription(componentDescription, localTransactionProviderCapabilityServiceName);
}
}
private void processModuleDescription(final EEModuleDescription moduleDescription, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, ServiceName localTransactionProviderCapabilityServiceName) {
final ConcurrentContext concurrentContext = moduleDescription.getConcurrentContext();
// setup context
setupConcurrentContext(concurrentContext, moduleDescription.getApplicationName(), moduleDescription.getModuleName(), null, deploymentUnit.getAttachment(MODULE).getClassLoader(), moduleDescription.getNamespaceContextSelector(), deploymentUnit, phaseContext.getServiceTarget(), localTransactionProviderCapabilityServiceName);
// attach setup action
final ConcurrentContextSetupAction setupAction = new ConcurrentContextSetupAction(concurrentContext);
deploymentUnit.putAttachment(Attachments.CONCURRENT_CONTEXT_SETUP_ACTION, setupAction);
deploymentUnit.addToAttachmentList(Attachments.WEB_SETUP_ACTIONS, setupAction);
}
private void processComponentDescription(final ComponentDescription componentDescription, ServiceName localTransactionProviderCapabilityServiceName) {
final ComponentConfigurator componentConfigurator = new ComponentConfigurator() {
@Override
public void configure(DeploymentPhaseContext context, ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final ConcurrentContext concurrentContext = configuration.getConcurrentContext();
// setup context
setupConcurrentContext(concurrentContext, description.getApplicationName(), description.getModuleName(), description.getComponentName(), configuration.getModuleClassLoader(), configuration.getNamespaceContextSelector(), context.getDeploymentUnit(), context.getServiceTarget(), localTransactionProviderCapabilityServiceName);
// add the interceptor which manages the concurrent context
final ConcurrentContextInterceptor interceptor = new ConcurrentContextInterceptor(concurrentContext);
final InterceptorFactory interceptorFactory = new ImmediateInterceptorFactory(interceptor);
configuration.addPostConstructInterceptor(interceptorFactory, InterceptorOrder.ComponentPostConstruct.CONCURRENT_CONTEXT);
configuration.addPreDestroyInterceptor(interceptorFactory, InterceptorOrder.ComponentPreDestroy.CONCURRENT_CONTEXT);
if (description.isPassivationApplicable()) {
configuration.addPrePassivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.CONCURRENT_CONTEXT);
configuration.addPostActivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.CONCURRENT_CONTEXT);
}
configuration.addComponentInterceptor(interceptorFactory, InterceptorOrder.Component.CONCURRENT_CONTEXT, false);
}
};
componentDescription.getConfigurators().add(componentConfigurator);
}
/**
*
* @param concurrentContext
* @param applicationName
* @param moduleName
* @param componentName
* @param moduleClassLoader
* @param namespaceContextSelector
* @param deploymentUnit
* @param serviceTarget
* @param localTransactionProviderCapabilityServiceName the service name of the local tx provider capability. If not present this param should be null
*/
private void setupConcurrentContext(ConcurrentContext concurrentContext, String applicationName, String moduleName, String componentName, ClassLoader moduleClassLoader, NamespaceContextSelector namespaceContextSelector, DeploymentUnit deploymentUnit, ServiceTarget serviceTarget, ServiceName localTransactionProviderCapabilityServiceName) {
// add default factories
concurrentContext.addFactory(new NamingContextHandleFactory(namespaceContextSelector, deploymentUnit.getServiceName()));
concurrentContext.addFactory(new ClassLoaderContextHandleFactory(moduleClassLoader));
for(ContextHandleFactory factory : deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_FACTORIES)) {
concurrentContext.addFactory(factory);
}
concurrentContext.addFactory(new OtherEESetupActionsContextHandleFactory(deploymentUnit.getAttachmentList(Attachments.OTHER_EE_SETUP_ACTIONS)));
// only add tx related factories if the capability is present
if (localTransactionProviderCapabilityServiceName != null) {
concurrentContext.addFactory(new TransactionContextHandleFactory());
}
// add factories for deployment provided thread context providers
for (ContextHandleFactory contextHandleFactory : ThreadContextProviderContextHandleFactory.fromServiceLoader(moduleClassLoader)) {
concurrentContext.addFactory(contextHandleFactory);
}
final ConcurrentContextService service = new ConcurrentContextService(concurrentContext);
final ServiceName serviceName = ConcurrentServiceNames.getConcurrentContextServiceName(applicationName, moduleName, componentName);
final ServiceBuilder serviceBuilder = serviceTarget.addService(serviceName, service);
if (localTransactionProviderCapabilityServiceName != null) {
serviceBuilder.requires(localTransactionProviderCapabilityServiceName);
}
serviceBuilder.install();
}
@Override
public void undeploy(DeploymentUnit deploymentUnit) {
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
ConcurrentContextSetupAction action = deploymentUnit.removeAttachment(Attachments.CONCURRENT_CONTEXT_SETUP_ACTION);
if (action != null) {
deploymentUnit.getAttachmentList(Attachments.WEB_SETUP_ACTIONS).remove(action);
}
}
}
| 10,300 | 62.981366 | 344 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/deployers/EEConcurrentDefaultBindingProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.concurrent.deployers;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.deployers.AbstractPlatformBindingProcessor;
import org.jboss.as.server.deployment.DeploymentUnit;
/**
* Processor responsible for binding the default EE concurrency resources to the naming context of EE modules/components.
*
* @author Eduardo Martins
*/
public class EEConcurrentDefaultBindingProcessor extends AbstractPlatformBindingProcessor {
public static final String DEFAULT_CONTEXT_SERVICE_JNDI_NAME = "DefaultContextService";
public static final String COMP_DEFAULT_CONTEXT_SERVICE_JNDI_NAME = "java:comp/"+DEFAULT_CONTEXT_SERVICE_JNDI_NAME;
public static final String DEFAULT_MANAGED_EXECUTOR_SERVICE_JNDI_NAME = "DefaultManagedExecutorService";
public static final String COMP_DEFAULT_MANAGED_EXECUTOR_SERVICE_JNDI_NAME = "java:comp/"+DEFAULT_MANAGED_EXECUTOR_SERVICE_JNDI_NAME;
public static final String DEFAULT_MANAGED_SCHEDULED_EXECUTOR_SERVICE_JNDI_NAME = "DefaultManagedScheduledExecutorService";
public static final String COMP_DEFAULT_MANAGED_SCHEDULED_EXECUTOR_SERVICE_JNDI_NAME = "java:comp/"+DEFAULT_MANAGED_SCHEDULED_EXECUTOR_SERVICE_JNDI_NAME;
public static final String DEFAULT_MANAGED_THREAD_FACTORY_JNDI_NAME = "DefaultManagedThreadFactory";
public static final String COMP_DEFAULT_MANAGED_THREAD_FACTORY_JNDI_NAME = "java:comp/"+DEFAULT_MANAGED_THREAD_FACTORY_JNDI_NAME;
@Override
protected void addBindings(DeploymentUnit deploymentUnit, EEModuleDescription moduleDescription) {
final String contextService = moduleDescription.getDefaultResourceJndiNames().getContextService();
if(contextService != null) {
addBinding(contextService, DEFAULT_CONTEXT_SERVICE_JNDI_NAME, deploymentUnit, moduleDescription);
}
final String managedExecutorService = moduleDescription.getDefaultResourceJndiNames().getManagedExecutorService();
if(managedExecutorService != null) {
addBinding(managedExecutorService, DEFAULT_MANAGED_EXECUTOR_SERVICE_JNDI_NAME, deploymentUnit, moduleDescription);
}
final String managedScheduledExecutorService = moduleDescription.getDefaultResourceJndiNames().getManagedScheduledExecutorService();
if(managedScheduledExecutorService != null) {
addBinding(managedScheduledExecutorService, DEFAULT_MANAGED_SCHEDULED_EXECUTOR_SERVICE_JNDI_NAME, deploymentUnit, moduleDescription);
}
final String managedThreadFactory = moduleDescription.getDefaultResourceJndiNames().getManagedThreadFactory();
if(managedThreadFactory != null) {
addBinding(managedThreadFactory, DEFAULT_MANAGED_THREAD_FACTORY_JNDI_NAME, deploymentUnit, moduleDescription);
}
}
}
| 3,830 | 56.179104 | 157 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/deployers/injection/ManagedScheduledExecutorServiceResourceReferenceProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.concurrent.deployers.injection;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.component.LookupInjectionSource;
import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessor;
import org.jboss.as.ee.concurrent.deployers.EEConcurrentDefaultBindingProcessor;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import jakarta.enterprise.concurrent.ManagedScheduledExecutorService;
/**
* @author Eduardo Martins
*/
public class ManagedScheduledExecutorServiceResourceReferenceProcessor implements EEResourceReferenceProcessor {
private static final String TYPE = ManagedScheduledExecutorService.class.getName();
private static final LookupInjectionSource injectionSource = new LookupInjectionSource(EEConcurrentDefaultBindingProcessor.COMP_DEFAULT_MANAGED_SCHEDULED_EXECUTOR_SERVICE_JNDI_NAME);
public static final ManagedScheduledExecutorServiceResourceReferenceProcessor INSTANCE = new ManagedScheduledExecutorServiceResourceReferenceProcessor();
private ManagedScheduledExecutorServiceResourceReferenceProcessor() {
}
@Override
public String getResourceReferenceType() {
return TYPE;
}
@Override
public InjectionSource getResourceReferenceBindingSource() throws DeploymentUnitProcessingException {
return injectionSource;
}
}
| 2,392 | 42.509091 | 186 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/deployers/injection/ManagedExecutorServiceResourceReferenceProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.concurrent.deployers.injection;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.component.LookupInjectionSource;
import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessor;
import org.jboss.as.ee.concurrent.deployers.EEConcurrentDefaultBindingProcessor;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import jakarta.enterprise.concurrent.ManagedExecutorService;
/**
* @author Eduardo Martins
*/
public class ManagedExecutorServiceResourceReferenceProcessor implements EEResourceReferenceProcessor {
private static final String TYPE = ManagedExecutorService.class.getName();
private static final LookupInjectionSource injectionSource = new LookupInjectionSource(EEConcurrentDefaultBindingProcessor.COMP_DEFAULT_MANAGED_EXECUTOR_SERVICE_JNDI_NAME);
public static final ManagedExecutorServiceResourceReferenceProcessor INSTANCE = new ManagedExecutorServiceResourceReferenceProcessor();
private ManagedExecutorServiceResourceReferenceProcessor() {
}
@Override
public String getResourceReferenceType() {
return TYPE;
}
@Override
public InjectionSource getResourceReferenceBindingSource() throws DeploymentUnitProcessingException {
return injectionSource;
}
}
| 2,328 | 41.345455 | 176 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/deployers/injection/ContextServiceResourceReferenceProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.concurrent.deployers.injection;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.component.LookupInjectionSource;
import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessor;
import org.jboss.as.ee.concurrent.deployers.EEConcurrentDefaultBindingProcessor;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import jakarta.enterprise.concurrent.ContextService;
/**
* @author Eduardo Martins
*/
public class ContextServiceResourceReferenceProcessor implements EEResourceReferenceProcessor {
private static final String TYPE = ContextService.class.getName();
private static final LookupInjectionSource injectionSource = new LookupInjectionSource(EEConcurrentDefaultBindingProcessor.COMP_DEFAULT_CONTEXT_SERVICE_JNDI_NAME);
public static final ContextServiceResourceReferenceProcessor INSTANCE = new ContextServiceResourceReferenceProcessor();
private ContextServiceResourceReferenceProcessor() {
}
@Override
public String getResourceReferenceType() {
return TYPE;
}
@Override
public InjectionSource getResourceReferenceBindingSource() throws DeploymentUnitProcessingException {
return injectionSource;
}
}
| 2,271 | 40.309091 | 167 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/deployers/injection/ManagedThreadFactoryResourceReferenceProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2013, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.concurrent.deployers.injection;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.component.LookupInjectionSource;
import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessor;
import org.jboss.as.ee.concurrent.deployers.EEConcurrentDefaultBindingProcessor;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import jakarta.enterprise.concurrent.ManagedThreadFactory;
/**
* @author Eduardo Martins
*/
public class ManagedThreadFactoryResourceReferenceProcessor implements EEResourceReferenceProcessor {
private static final String TYPE = ManagedThreadFactory.class.getName();
private static final LookupInjectionSource injectionSource = new LookupInjectionSource(EEConcurrentDefaultBindingProcessor.COMP_DEFAULT_MANAGED_THREAD_FACTORY_JNDI_NAME);
public static final ManagedThreadFactoryResourceReferenceProcessor INSTANCE = new ManagedThreadFactoryResourceReferenceProcessor();
private ManagedThreadFactoryResourceReferenceProcessor() {
}
@Override
public String getResourceReferenceType() {
return TYPE;
}
@Override
public InjectionSource getResourceReferenceBindingSource() throws DeploymentUnitProcessingException {
return injectionSource;
}
}
| 2,314 | 41.090909 | 174 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ManagedScheduledExecutorDefinitionInjectionSource.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.glassfish.enterprise.concurrent.AbstractManagedExecutorService;
import org.glassfish.enterprise.concurrent.ManagedScheduledExecutorServiceAdapter;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.concurrent.ContextServiceImpl;
import org.jboss.as.ee.concurrent.deployers.EEConcurrentDefaultBindingProcessor;
import org.jboss.as.ee.concurrent.service.ConcurrentServiceNames;
import org.jboss.as.ee.concurrent.service.ManagedExecutorHungTasksPeriodicTerminationService;
import org.jboss.as.ee.concurrent.service.ManagedScheduledExecutorServiceService;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.ee.subsystem.ManagedScheduledExecutorServiceResourceDefinition;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.msc.inject.InjectionException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.wildfly.common.cpu.ProcessorInfo;
import org.wildfly.extension.requestcontroller.RequestController;
/**
* The {@link ResourceDefinitionInjectionSource} for {@link jakarta.enterprise.concurrent.ManagedScheduledExecutorDefinition}.
*
* @author emmartins
*/
public class ManagedScheduledExecutorDefinitionInjectionSource extends ResourceDefinitionInjectionSource {
public static final String CONTEXT_PROP = "context";
public static final String HUNG_TASK_THRESHOLD_PROP = "hungTaskThreshold";
public static final String MAX_ASYNC_PROP = "maxAsync";
private static final String REQUEST_CONTROLLER_CAPABILITY_NAME = "org.wildfly.request-controller";
private String contextServiceRef;
private long hungTaskThreshold;
private int maxAsync = (ProcessorInfo.availableProcessors() * 2);
private int hungTaskTerminationPeriod = 0;
private boolean longRunningTasks = false;
private long keepAliveTime = 60000;
private TimeUnit keepAliveTimeUnit = TimeUnit.MILLISECONDS;
private long threadLifeTime = 0L;
private AbstractManagedExecutorService.RejectPolicy rejectPolicy = AbstractManagedExecutorService.RejectPolicy.ABORT;
private int threadPriority = Thread.NORM_PRIORITY;
public ManagedScheduledExecutorDefinitionInjectionSource(final String jndiName) {
super(jndiName);
}
public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final String resourceName = uniqueName(context);
final String resourceJndiName = "java:jboss/ee/concurrency/definition/managedScheduledExecutor/"+resourceName;
final CapabilityServiceSupport capabilityServiceSupport = phaseContext.getDeploymentUnit().getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
try {
// install the resource service
final ServiceName resourceServiceName = ManagedScheduledExecutorServiceResourceDefinition.CAPABILITY.getCapabilityServiceName(resourceName);
final ServiceBuilder resourceServiceBuilder = phaseContext.getServiceTarget().addService(resourceServiceName);
final Consumer<ManagedScheduledExecutorServiceAdapter> consumer = resourceServiceBuilder.provides(resourceServiceName);
final Supplier<ManagedExecutorHungTasksPeriodicTerminationService> hungTasksPeriodicTerminationService = resourceServiceBuilder.requires(ConcurrentServiceNames.HUNG_TASK_PERIODIC_TERMINATION_SERVICE_NAME);
Supplier<RequestController> requestControllerSupplier = null;
if (capabilityServiceSupport.hasCapability(REQUEST_CONTROLLER_CAPABILITY_NAME)) {
requestControllerSupplier = resourceServiceBuilder.requires(capabilityServiceSupport.getCapabilityServiceName(REQUEST_CONTROLLER_CAPABILITY_NAME));
}
final ManagedScheduledExecutorServiceService resourceService = new ManagedScheduledExecutorServiceService(consumer, null, null, requestControllerSupplier, resourceName, resourceJndiName, hungTaskThreshold, hungTaskTerminationPeriod, longRunningTasks, maxAsync, keepAliveTime, keepAliveTimeUnit, threadLifeTime, rejectPolicy, threadPriority, hungTasksPeriodicTerminationService);
resourceServiceBuilder.setInstance(resourceService);
final Injector<ManagedReferenceFactory> contextServiceLookupInjector = new Injector<>() {
@Override
public void inject(ManagedReferenceFactory value) throws InjectionException {
resourceService.getContextServiceSupplier().set(() -> (ContextServiceImpl)value.getReference().getInstance());
}
@Override
public void uninject() {
resourceService.getContextServiceSupplier().set(() -> null);
}
};
final String contextServiceRef = this.contextServiceRef == null || this.contextServiceRef.isEmpty() ? EEConcurrentDefaultBindingProcessor.COMP_DEFAULT_CONTEXT_SERVICE_JNDI_NAME : this.contextServiceRef;
final ContextNames.BindInfo contextServiceBindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), contextServiceRef);
contextServiceBindInfo.setupLookupInjection(resourceServiceBuilder, contextServiceLookupInjector, phaseContext.getDeploymentUnit(), false);
resourceServiceBuilder.install();
// use a dependency to the resource service installed to inject the resource
serviceBuilder.addDependency(resourceServiceName, ManagedScheduledExecutorServiceAdapter.class, new Injector<>() {
@Override
public void inject(final ManagedScheduledExecutorServiceAdapter resource) throws InjectionException {
injector.inject(() -> new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
return resource;
}
});
}
@Override
public void uninject() {
injector.uninject();
}
});
} catch (Exception e) {
throw new DeploymentUnitProcessingException(e);
}
}
public String getContextServiceRef() {
return contextServiceRef;
}
public void setContextServiceRef(String contextServiceRef) {
this.contextServiceRef = contextServiceRef;
}
public long getHungTaskThreshold() {
return hungTaskThreshold;
}
public void setHungTaskThreshold(long hungTaskThreshold) {
this.hungTaskThreshold = hungTaskThreshold;
}
public int getMaxAsync() {
return maxAsync;
}
public void setMaxAsync(int maxAsync) {
if (maxAsync > 0) {
this.maxAsync = maxAsync;
}
}
public int getHungTaskTerminationPeriod() {
return hungTaskTerminationPeriod;
}
public void setHungTaskTerminationPeriod(int hungTaskTerminationPeriod) {
this.hungTaskTerminationPeriod = hungTaskTerminationPeriod;
}
public boolean isLongRunningTasks() {
return longRunningTasks;
}
public void setLongRunningTasks(boolean longRunningTasks) {
this.longRunningTasks = longRunningTasks;
}
public long getKeepAliveTime() {
return keepAliveTime;
}
public void setKeepAliveTime(long keepAliveTime) {
this.keepAliveTime = keepAliveTime;
}
public TimeUnit getKeepAliveTimeUnit() {
return keepAliveTimeUnit;
}
public void setKeepAliveTimeUnit(TimeUnit keepAliveTimeUnit) {
this.keepAliveTimeUnit = keepAliveTimeUnit;
}
public long getThreadLifeTime() {
return threadLifeTime;
}
public void setThreadLifeTime(long threadLifeTime) {
this.threadLifeTime = threadLifeTime;
}
public AbstractManagedExecutorService.RejectPolicy getRejectPolicy() {
return rejectPolicy;
}
public void setRejectPolicy(AbstractManagedExecutorService.RejectPolicy rejectPolicy) {
this.rejectPolicy = rejectPolicy;
}
public int getThreadPriority() {
return threadPriority;
}
public void setThreadPriority(int threadPriority) {
this.threadPriority = threadPriority;
}
}
| 9,794 | 45.421801 | 390 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ContextServiceDefinitionInjectionSource.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import org.jboss.as.ee.concurrent.ContextServiceImpl;
import org.jboss.as.ee.concurrent.ContextServiceTypesConfiguration;
import org.jboss.as.ee.concurrent.DefaultContextSetupProviderImpl;
import org.jboss.as.ee.concurrent.service.ContextServiceService;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.ee.subsystem.ContextServiceResourceDefinition;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.msc.inject.InjectionException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
/**
* The {@link ResourceDefinitionInjectionSource} for {@link jakarta.enterprise.concurrent.ContextServiceDefinition}
*
* @author emmartins
*/
public class ContextServiceDefinitionInjectionSource extends ResourceDefinitionInjectionSource {
private final ContextServiceTypesConfiguration contextServiceTypesConfiguration;
public ContextServiceDefinitionInjectionSource(final String jndiName, final ContextServiceTypesConfiguration contextServiceTypesConfiguration) {
super(jndiName);
this.contextServiceTypesConfiguration = contextServiceTypesConfiguration;
}
public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final String resourceName = uniqueName(context);
final String resourceJndiName = "java:jboss/ee/concurrency/definition/context/"+resourceName;
try {
// install the resource service
final ContextServiceService resourceService = new ContextServiceService(resourceName, resourceJndiName, new DefaultContextSetupProviderImpl(), contextServiceTypesConfiguration);
final ServiceName resourceServiceName = ContextServiceResourceDefinition.CAPABILITY.getCapabilityServiceName(resourceName);
phaseContext.getServiceTarget()
.addService(resourceServiceName)
.setInstance(resourceService)
.install();
// use a dependency to the resource service installed to inject the resource
serviceBuilder.addDependency(resourceServiceName, ContextServiceImpl.class, new Injector<>() {
@Override
public void inject(final ContextServiceImpl resource) throws InjectionException {
injector.inject(() -> new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
return resource;
}
});
}
@Override
public void uninject() {
injector.uninject();
}
});
} catch (Exception e) {
throw new DeploymentUnitProcessingException(e);
}
}
public ContextServiceTypesConfiguration getContextServiceTypesConfiguration() {
return contextServiceTypesConfiguration;
}
}
| 4,216 | 46.920455 | 241 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ManagedScheduledExecutorDefinitionDescriptorProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import org.jboss.as.ee.resource.definition.ResourceDefinitionDescriptorProcessor;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.metadata.javaee.spec.Environment;
import org.jboss.metadata.javaee.spec.ManagedScheduledExecutorMetaData;
import org.jboss.metadata.javaee.spec.ManagedScheduledExecutorsMetaData;
import org.jboss.metadata.javaee.spec.RemoteEnvironment;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* The {@link ResourceDefinitionDescriptorProcessor} for {@link jakarta.enterprise.concurrent.ManagedScheduledExecutorDefinition}.
* @author emmartins
*/
public class ManagedScheduledExecutorDefinitionDescriptorProcessor extends ResourceDefinitionDescriptorProcessor {
@Override
protected void processEnvironment(RemoteEnvironment environment, ResourceDefinitionInjectionSources injectionSources) throws DeploymentUnitProcessingException {
if (environment instanceof Environment) {
final ManagedScheduledExecutorsMetaData metaDatas = ((Environment)environment).getManagedScheduledExecutors();
if (metaDatas != null) {
for(ManagedScheduledExecutorMetaData metaData : metaDatas) {
injectionSources.addResourceDefinitionInjectionSource(getResourceDefinitionInjectionSource(metaData));
}
}
}
}
private ResourceDefinitionInjectionSource getResourceDefinitionInjectionSource(final ManagedScheduledExecutorMetaData metaData) {
final String name = metaData.getName();
if (name == null || name.isEmpty()) {
throw ROOT_LOGGER.elementAttributeMissing("<managed-scheduled-executor>", "name");
}
final ManagedScheduledExecutorDefinitionInjectionSource resourceDefinitionInjectionSource = new ManagedScheduledExecutorDefinitionInjectionSource(name);
resourceDefinitionInjectionSource.setContextServiceRef(metaData.getContextServiceRef());
final Integer hungTaskThreshold = metaData.getHungTaskThreshold();
if (hungTaskThreshold != null) {
resourceDefinitionInjectionSource.setHungTaskThreshold(hungTaskThreshold);
}
final Integer maxAsync = metaData.getMaxAsync();
if (maxAsync != null) {
resourceDefinitionInjectionSource.setMaxAsync(maxAsync);
}
// TODO *FOLLOW UP* XML properties are unused, perhaps we should consider those to configure other managed scheduled exec properties we have on server config?
return resourceDefinitionInjectionSource;
}
}
| 3,422 | 50.863636 | 166 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ManagedExecutorDefinitionAnnotationProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import jakarta.enterprise.concurrent.ManagedExecutorDefinition;
import org.jboss.as.ee.resource.definition.ResourceDefinitionAnnotationProcessor;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.jboss.metadata.property.PropertyReplacer;
/**
* The {@link ResourceDefinitionAnnotationProcessor} for {@link ManagedExecutorDefinition}.
* @author emmartins
*/
public class ManagedExecutorDefinitionAnnotationProcessor extends ResourceDefinitionAnnotationProcessor {
private static final DotName MANAGED_EXECUTOR_DEFINITION = DotName.createSimple(ManagedExecutorDefinition.class.getName());
private static final DotName MANAGED_EXECUTOR_DEFINITION_LIST = DotName.createSimple(ManagedExecutorDefinition.List.class.getName());
@Override
protected DotName getAnnotationDotName() {
return MANAGED_EXECUTOR_DEFINITION;
}
@Override
protected DotName getAnnotationCollectionDotName() {
return MANAGED_EXECUTOR_DEFINITION_LIST;
}
@Override
protected ResourceDefinitionInjectionSource processAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
final String jndiName = AnnotationElement.asRequiredString(annotationInstance, AnnotationElement.NAME);
final String context = AnnotationElement.asOptionalString(annotationInstance, ManagedExecutorDefinitionInjectionSource.CONTEXT_PROP);
final String hungTaskThresholdString = AnnotationElement.asOptionalString(annotationInstance, ManagedExecutorDefinitionInjectionSource.HUNG_TASK_THRESHOLD_PROP);
final long hungTaskThreshold = hungTaskThresholdString != null && !hungTaskThresholdString.isEmpty() ? Math.max(Long.valueOf(hungTaskThresholdString), 0L) : 0L;
final int maxAsync = AnnotationElement.asOptionalInt(annotationInstance, ManagedExecutorDefinitionInjectionSource.MAX_ASYNC_PROP);
final ManagedExecutorDefinitionInjectionSource injectionSource = new ManagedExecutorDefinitionInjectionSource(jndiName);
injectionSource.setContextServiceRef(context);
injectionSource.setHungTaskThreshold(hungTaskThreshold);
injectionSource.setMaxAsync(maxAsync);
return injectionSource;
}
}
| 3,191 | 51.327869 | 182 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ContextServiceDefinitionDescriptorProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import org.jboss.as.ee.concurrent.ContextServiceTypesConfiguration;
import org.jboss.as.ee.resource.definition.ResourceDefinitionDescriptorProcessor;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.metadata.javaee.spec.ContextServiceMetaData;
import org.jboss.metadata.javaee.spec.ContextServicesMetaData;
import org.jboss.metadata.javaee.spec.Environment;
import org.jboss.metadata.javaee.spec.RemoteEnvironment;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* The {@link ResourceDefinitionDescriptorProcessor} for {@link jakarta.enterprise.concurrent.ContextServiceDefinition}.
* @author emmartins
*/
public class ContextServiceDefinitionDescriptorProcessor extends ResourceDefinitionDescriptorProcessor {
@Override
protected void processEnvironment(RemoteEnvironment environment, ResourceDefinitionInjectionSources injectionSources) throws DeploymentUnitProcessingException {
if (environment instanceof Environment) {
final ContextServicesMetaData metaDatas = ((Environment)environment).getContextServices();
if (metaDatas != null) {
for(ContextServiceMetaData metaData : metaDatas) {
injectionSources.addResourceDefinitionInjectionSource(getResourceDefinitionInjectionSource(metaData));
}
}
}
}
private ResourceDefinitionInjectionSource getResourceDefinitionInjectionSource(final ContextServiceMetaData metaData) {
final String name = metaData.getName();
if (name == null || name.isEmpty()) {
throw ROOT_LOGGER.elementAttributeMissing("<context-service>", "name");
}
final ContextServiceTypesConfiguration contextServiceTypesConfiguration = new ContextServiceTypesConfiguration.Builder()
.setCleared(metaData.getCleared())
.setPropagated(metaData.getPropagated())
.setUnchanged(metaData.getUnchanged())
.build();
return new ContextServiceDefinitionInjectionSource(name, contextServiceTypesConfiguration);
}
}
| 2,962 | 46.790323 | 164 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ManagedThreadFactoryDefinitionAnnotationProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import jakarta.enterprise.concurrent.ManagedThreadFactoryDefinition;
import org.jboss.as.ee.resource.definition.ResourceDefinitionAnnotationProcessor;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.jboss.metadata.property.PropertyReplacer;
/**
* The {@link ResourceDefinitionAnnotationProcessor} for {@link ManagedThreadFactoryDefinition}.
* @author emmartins
*/
public class ManagedThreadFactoryDefinitionAnnotationProcessor extends ResourceDefinitionAnnotationProcessor {
private static final DotName MANAGED_THREAD_FACTORY_DEFINITION = DotName.createSimple(ManagedThreadFactoryDefinition.class.getName());
private static final DotName MANAGED_THREAD_FACTORY_DEFINITION_LIST = DotName.createSimple(ManagedThreadFactoryDefinition.List.class.getName());
@Override
protected DotName getAnnotationDotName() {
return MANAGED_THREAD_FACTORY_DEFINITION;
}
@Override
protected DotName getAnnotationCollectionDotName() {
return MANAGED_THREAD_FACTORY_DEFINITION_LIST;
}
@Override
protected ResourceDefinitionInjectionSource processAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
final String jndiName = AnnotationElement.asRequiredString(annotationInstance, AnnotationElement.NAME);
final String context = AnnotationElement.asOptionalString(annotationInstance, ManagedThreadFactoryDefinitionInjectionSource.CONTEXT_PROP);
final int priority = AnnotationElement.asOptionalInt(annotationInstance, ManagedThreadFactoryDefinitionInjectionSource.PRIORITY_PROP);
final ManagedThreadFactoryDefinitionInjectionSource injectionSource = new ManagedThreadFactoryDefinitionInjectionSource(jndiName);
injectionSource.setContextServiceRef(context);
injectionSource.setPriority(priority > 0 ? priority : Thread.NORM_PRIORITY);
return injectionSource;
}
}
| 2,893 | 48.896552 | 182 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ManagedExecutorDefinitionDescriptorProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import org.jboss.as.ee.resource.definition.ResourceDefinitionDescriptorProcessor;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.metadata.javaee.spec.Environment;
import org.jboss.metadata.javaee.spec.ManagedExecutorMetaData;
import org.jboss.metadata.javaee.spec.ManagedExecutorsMetaData;
import org.jboss.metadata.javaee.spec.RemoteEnvironment;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* The {@link ResourceDefinitionDescriptorProcessor} for {@link jakarta.enterprise.concurrent.ManagedExecutorDefinition}.
* @author emmartins
*/
public class ManagedExecutorDefinitionDescriptorProcessor extends ResourceDefinitionDescriptorProcessor {
@Override
protected void processEnvironment(RemoteEnvironment environment, ResourceDefinitionInjectionSources injectionSources) throws DeploymentUnitProcessingException {
if (environment instanceof Environment) {
final ManagedExecutorsMetaData metaDatas = ((Environment)environment).getManagedExecutors();
if (metaDatas != null) {
for(ManagedExecutorMetaData metaData : metaDatas) {
injectionSources.addResourceDefinitionInjectionSource(getResourceDefinitionInjectionSource(metaData));
}
}
}
}
private ResourceDefinitionInjectionSource getResourceDefinitionInjectionSource(final ManagedExecutorMetaData metaData) {
final String name = metaData.getName();
if (name == null || name.isEmpty()) {
throw ROOT_LOGGER.elementAttributeMissing("<managed-executor>", "name");
}
final ManagedExecutorDefinitionInjectionSource resourceDefinitionInjectionSource = new ManagedExecutorDefinitionInjectionSource(name);
resourceDefinitionInjectionSource.setContextServiceRef(metaData.getContextServiceRef());
final Integer hungTaskThreshold = metaData.getHungTaskThreshold();
if (hungTaskThreshold != null) {
resourceDefinitionInjectionSource.setHungTaskThreshold(hungTaskThreshold);
}
final Integer maxAsync = metaData.getMaxAsync();
if (maxAsync != null) {
resourceDefinitionInjectionSource.setMaxAsync(maxAsync);
}
// TODO *FOLLOW UP* XML properties are unused, perhaps we should consider those to configure other managed exec properties we have on server config?
return resourceDefinitionInjectionSource;
}
}
| 3,313 | 48.462687 | 164 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ManagedThreadFactoryDefinitionDescriptorProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import org.jboss.as.ee.resource.definition.ResourceDefinitionDescriptorProcessor;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.metadata.javaee.spec.Environment;
import org.jboss.metadata.javaee.spec.ManagedThreadFactoriesMetaData;
import org.jboss.metadata.javaee.spec.ManagedThreadFactoryMetaData;
import org.jboss.metadata.javaee.spec.RemoteEnvironment;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
/**
* The {@link ResourceDefinitionDescriptorProcessor} for {@link jakarta.enterprise.concurrent.ManagedThreadFactoryDefinition}.
* @author emmartins
*/
public class ManagedThreadFactoryDefinitionDescriptorProcessor extends ResourceDefinitionDescriptorProcessor {
@Override
protected void processEnvironment(RemoteEnvironment environment, ResourceDefinitionInjectionSources injectionSources) throws DeploymentUnitProcessingException {
if (environment instanceof Environment) {
final ManagedThreadFactoriesMetaData metaDatas = ((Environment)environment).getManagedThreadFactories();
if (metaDatas != null) {
for(ManagedThreadFactoryMetaData metaData : metaDatas) {
injectionSources.addResourceDefinitionInjectionSource(getResourceDefinitionInjectionSource(metaData));
}
}
}
}
private ResourceDefinitionInjectionSource getResourceDefinitionInjectionSource(final ManagedThreadFactoryMetaData metaData) {
final String name = metaData.getName();
if (name == null || name.isEmpty()) {
throw ROOT_LOGGER.elementAttributeMissing("<managed-thread-factory>", "name");
}
final ManagedThreadFactoryDefinitionInjectionSource resourceDefinitionInjectionSource = new ManagedThreadFactoryDefinitionInjectionSource(name);
resourceDefinitionInjectionSource.setContextServiceRef(metaData.getContextServiceRef());
final Integer priority = metaData.getPriority();
if (priority != null) {
resourceDefinitionInjectionSource.setPriority(priority);
}
return resourceDefinitionInjectionSource;
}
}
| 3,002 | 47.435484 | 164 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ContextServiceDefinitionAnnotationProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import jakarta.enterprise.concurrent.ContextServiceDefinition;
import org.jboss.as.ee.concurrent.ContextServiceTypesConfiguration;
import org.jboss.as.ee.resource.definition.ResourceDefinitionAnnotationProcessor;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.jboss.metadata.property.PropertyReplacer;
/**
* The {@link ResourceDefinitionAnnotationProcessor} for {@link ContextServiceDefinition}.
* @author emmartins
*/
public class ContextServiceDefinitionAnnotationProcessor extends ResourceDefinitionAnnotationProcessor {
public static final String CLEARED_PROP = "cleared";
public static final String PROPAGATED_PROP = "propagated";
public static final String UNCHANGED_PROP = "unchanged";
private static final DotName CONTEXT_SERVICE_DEFINITION = DotName.createSimple(ContextServiceDefinition.class.getName());
private static final DotName CONTEXT_SERVICE_DEFINITION_LIST = DotName.createSimple(ContextServiceDefinition.List.class.getName());
@Override
protected DotName getAnnotationDotName() {
return CONTEXT_SERVICE_DEFINITION;
}
@Override
protected DotName getAnnotationCollectionDotName() {
return CONTEXT_SERVICE_DEFINITION_LIST;
}
@Override
protected ResourceDefinitionInjectionSource processAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
final String jndiName = AnnotationElement.asRequiredString(annotationInstance, AnnotationElement.NAME);
final ContextServiceTypesConfiguration contextServiceTypesConfiguration = new ContextServiceTypesConfiguration.Builder()
.setCleared(AnnotationElement.asOptionalStringArray(annotationInstance, CLEARED_PROP))
.setPropagated(AnnotationElement.asOptionalStringArray(annotationInstance, PROPAGATED_PROP))
.setUnchanged(AnnotationElement.asOptionalStringArray(annotationInstance, UNCHANGED_PROP))
.build();
return new ContextServiceDefinitionInjectionSource(jndiName, contextServiceTypesConfiguration);
}
}
| 3,062 | 47.619048 | 182 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ManagedExecutorDefinitionInjectionSource.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import org.glassfish.enterprise.concurrent.AbstractManagedExecutorService;
import org.glassfish.enterprise.concurrent.ManagedExecutorServiceAdapter;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.concurrent.ContextServiceImpl;
import org.jboss.as.ee.concurrent.deployers.EEConcurrentDefaultBindingProcessor;
import org.jboss.as.ee.concurrent.service.ConcurrentServiceNames;
import org.jboss.as.ee.concurrent.service.ManagedExecutorHungTasksPeriodicTerminationService;
import org.jboss.as.ee.concurrent.service.ManagedExecutorServiceService;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.ee.subsystem.ManagedExecutorServiceResourceDefinition;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.msc.inject.InjectionException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.wildfly.common.cpu.ProcessorInfo;
import org.wildfly.extension.requestcontroller.RequestController;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* The {@link ResourceDefinitionInjectionSource} for {@link jakarta.enterprise.concurrent.ManagedExecutorDefinition}.
*
* @author emmartins
*/
public class ManagedExecutorDefinitionInjectionSource extends ResourceDefinitionInjectionSource {
public static final String CONTEXT_PROP = "context";
public static final String HUNG_TASK_THRESHOLD_PROP = "hungTaskThreshold";
public static final String MAX_ASYNC_PROP = "maxAsync";
private static final String REQUEST_CONTROLLER_CAPABILITY_NAME = "org.wildfly.request-controller";
private String contextServiceRef;
private long hungTaskThreshold;
private int maxAsync = (ProcessorInfo.availableProcessors() * 2);
private int hungTaskTerminationPeriod = 0;
private boolean longRunningTasks = false;
private long keepAliveTime = 60000;
private TimeUnit keepAliveTimeUnit = TimeUnit.MILLISECONDS;
private long threadLifeTime = 0L;
private int queueLength = Integer.MAX_VALUE;
private AbstractManagedExecutorService.RejectPolicy rejectPolicy = AbstractManagedExecutorService.RejectPolicy.ABORT;
private int threadPriority = Thread.NORM_PRIORITY;
public ManagedExecutorDefinitionInjectionSource(final String jndiName) {
super(jndiName);
}
public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final String resourceName = uniqueName(context);
final String resourceJndiName = "java:jboss/ee/concurrency/definition/managedExecutor/"+resourceName;
final CapabilityServiceSupport capabilityServiceSupport = phaseContext.getDeploymentUnit().getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
try {
// install the resource service
final ServiceName resourceServiceName = ManagedExecutorServiceResourceDefinition.CAPABILITY.getCapabilityServiceName(resourceName);
final ServiceBuilder resourceServiceBuilder = phaseContext.getServiceTarget().addService(resourceServiceName);
final Consumer<ManagedExecutorServiceAdapter> consumer = resourceServiceBuilder.provides(resourceServiceName);
final Supplier<ManagedExecutorHungTasksPeriodicTerminationService> hungTasksPeriodicTerminationService = resourceServiceBuilder.requires(ConcurrentServiceNames.HUNG_TASK_PERIODIC_TERMINATION_SERVICE_NAME);
Supplier<RequestController> requestControllerSupplier = null;
if (capabilityServiceSupport.hasCapability(REQUEST_CONTROLLER_CAPABILITY_NAME)) {
requestControllerSupplier = resourceServiceBuilder.requires(capabilityServiceSupport.getCapabilityServiceName(REQUEST_CONTROLLER_CAPABILITY_NAME));
}
final ManagedExecutorServiceService resourceService = new ManagedExecutorServiceService(consumer, null, null, requestControllerSupplier, resourceName, resourceJndiName, hungTaskThreshold, hungTaskTerminationPeriod, longRunningTasks, maxAsync, maxAsync, keepAliveTime, keepAliveTimeUnit, threadLifeTime, queueLength, rejectPolicy, threadPriority, hungTasksPeriodicTerminationService);
resourceServiceBuilder.setInstance(resourceService);
final Injector<ManagedReferenceFactory> contextServiceLookupInjector = new Injector<>() {
@Override
public void inject(ManagedReferenceFactory value) throws InjectionException {
resourceService.getContextServiceSupplier().set(() -> (ContextServiceImpl)value.getReference().getInstance());
}
@Override
public void uninject() {
resourceService.getContextServiceSupplier().set(() -> null);
}
};
final String contextServiceRef = this.contextServiceRef == null || this.contextServiceRef.isEmpty() ? EEConcurrentDefaultBindingProcessor.COMP_DEFAULT_CONTEXT_SERVICE_JNDI_NAME : this.contextServiceRef;
final ContextNames.BindInfo contextServiceBindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), contextServiceRef);
contextServiceBindInfo.setupLookupInjection(resourceServiceBuilder, contextServiceLookupInjector, phaseContext.getDeploymentUnit(), false);
resourceServiceBuilder.install();
// use a dependency to the resource service installed to inject the resource
serviceBuilder.addDependency(resourceServiceName, ManagedExecutorServiceAdapter.class, new Injector<>() {
@Override
public void inject(final ManagedExecutorServiceAdapter resource) throws InjectionException {
injector.inject(() -> new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
return resource;
}
});
}
@Override
public void uninject() {
injector.uninject();
}
});
} catch (Exception e) {
throw new DeploymentUnitProcessingException(e);
}
}
public String getContextServiceRef() {
return contextServiceRef;
}
public void setContextServiceRef(String contextServiceRef) {
this.contextServiceRef = contextServiceRef;
}
public long getHungTaskThreshold() {
return hungTaskThreshold;
}
public void setHungTaskThreshold(long hungTaskThreshold) {
this.hungTaskThreshold = hungTaskThreshold;
}
public int getMaxAsync() {
return maxAsync;
}
public void setMaxAsync(int maxAsync) {
if (maxAsync > 0) {
this.maxAsync = maxAsync;
}
}
public int getHungTaskTerminationPeriod() {
return hungTaskTerminationPeriod;
}
public void setHungTaskTerminationPeriod(int hungTaskTerminationPeriod) {
this.hungTaskTerminationPeriod = hungTaskTerminationPeriod;
}
public boolean isLongRunningTasks() {
return longRunningTasks;
}
public void setLongRunningTasks(boolean longRunningTasks) {
this.longRunningTasks = longRunningTasks;
}
public long getKeepAliveTime() {
return keepAliveTime;
}
public void setKeepAliveTime(long keepAliveTime) {
this.keepAliveTime = keepAliveTime;
}
public TimeUnit getKeepAliveTimeUnit() {
return keepAliveTimeUnit;
}
public void setKeepAliveTimeUnit(TimeUnit keepAliveTimeUnit) {
this.keepAliveTimeUnit = keepAliveTimeUnit;
}
public long getThreadLifeTime() {
return threadLifeTime;
}
public void setThreadLifeTime(long threadLifeTime) {
this.threadLifeTime = threadLifeTime;
}
public int getQueueLength() {
return queueLength;
}
public void setQueueLength(int queueLength) {
this.queueLength = queueLength;
}
public AbstractManagedExecutorService.RejectPolicy getRejectPolicy() {
return rejectPolicy;
}
public void setRejectPolicy(AbstractManagedExecutorService.RejectPolicy rejectPolicy) {
this.rejectPolicy = rejectPolicy;
}
public int getThreadPriority() {
return threadPriority;
}
public void setThreadPriority(int threadPriority) {
this.threadPriority = threadPriority;
}
}
| 9,915 | 44.072727 | 395 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ManagedThreadFactoryDefinitionInjectionSource.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import java.util.function.Consumer;
import org.jboss.as.ee.concurrent.ContextServiceImpl;
import org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl;
import org.jboss.as.ee.concurrent.deployers.EEConcurrentDefaultBindingProcessor;
import org.jboss.as.ee.concurrent.service.ManagedThreadFactoryService;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.ee.subsystem.ManagedThreadFactoryResourceDefinition;
import org.jboss.as.naming.ManagedReference;
import org.jboss.as.naming.ManagedReferenceFactory;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.msc.inject.InjectionException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
/**
* The {@link ResourceDefinitionInjectionSource} for {@link jakarta.enterprise.concurrent.ManagedThreadFactoryDefinition}.
*
* @author emmartins
*/
public class ManagedThreadFactoryDefinitionInjectionSource extends ResourceDefinitionInjectionSource {
public static final String CONTEXT_PROP = "context";
public static final String PRIORITY_PROP = "priority";
private String contextServiceRef;
private int priority = Thread.NORM_PRIORITY;
public ManagedThreadFactoryDefinitionInjectionSource(final String jndiName) {
super(jndiName);
}
public void getResourceValue(final ResolutionContext context, final ServiceBuilder<?> serviceBuilder, final DeploymentPhaseContext phaseContext, final Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final String resourceName = uniqueName(context);
final String resourceJndiName = "java:jboss/ee/concurrency/definition/managedScheduledExecutor/"+resourceName;
try {
// install the resource service
final ServiceName resourceServiceName = ManagedThreadFactoryResourceDefinition.CAPABILITY.getCapabilityServiceName(resourceName);
final ServiceBuilder resourceServiceBuilder = phaseContext.getServiceTarget().addService(resourceServiceName);
final Consumer<ManagedThreadFactoryImpl> consumer = resourceServiceBuilder.provides(resourceServiceName);
final ManagedThreadFactoryService resourceService = new ManagedThreadFactoryService(consumer, null, resourceName, resourceJndiName, priority);
final Injector<ManagedReferenceFactory> contextServiceLookupInjector = new Injector<>() {
@Override
public void inject(ManagedReferenceFactory value) throws InjectionException {
resourceService.getContextServiceSupplier().set(() -> (ContextServiceImpl)value.getReference().getInstance());
}
@Override
public void uninject() {
resourceService.getContextServiceSupplier().set(() -> null);
}
};
final String contextServiceRef = this.contextServiceRef == null || this.contextServiceRef.isEmpty() ? EEConcurrentDefaultBindingProcessor.COMP_DEFAULT_CONTEXT_SERVICE_JNDI_NAME : this.contextServiceRef;
final ContextNames.BindInfo contextServiceBindInfo = ContextNames.bindInfoForEnvEntry(context.getApplicationName(), context.getModuleName(), context.getComponentName(), !context.isCompUsesModule(), contextServiceRef);
contextServiceBindInfo.setupLookupInjection(resourceServiceBuilder, contextServiceLookupInjector, phaseContext.getDeploymentUnit(), false);
resourceServiceBuilder.setInstance(resourceService);
resourceServiceBuilder.install();
// use a dependency to the resource service installed to inject the resource
serviceBuilder.addDependency(resourceServiceName, ManagedThreadFactoryImpl.class, new Injector<>() {
@Override
public void inject(final ManagedThreadFactoryImpl resource) throws InjectionException {
injector.inject(() -> new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
return resource;
}
});
}
@Override
public void uninject() {
injector.uninject();
}
});
} catch (Exception e) {
throw new DeploymentUnitProcessingException(e);
}
}
public String getContextServiceRef() {
return contextServiceRef;
}
public void setContextServiceRef(String contextServiceRef) {
this.contextServiceRef = contextServiceRef;
}
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
}
| 5,844 | 48.117647 | 241 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/concurrent/resource/definition/ManagedScheduledExecutorDefinitionAnnotationProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.concurrent.resource.definition;
import jakarta.enterprise.concurrent.ManagedScheduledExecutorDefinition;
import org.jboss.as.ee.resource.definition.ResourceDefinitionAnnotationProcessor;
import org.jboss.as.ee.resource.definition.ResourceDefinitionInjectionSource;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.jboss.metadata.property.PropertyReplacer;
/**
* The {@link ResourceDefinitionAnnotationProcessor} for {@link ManagedScheduledExecutorDefinition}.
* @author emmartins
*/
public class ManagedScheduledExecutorDefinitionAnnotationProcessor extends ResourceDefinitionAnnotationProcessor {
private static final DotName MANAGED_SCHEDULED_EXECUTOR_DEFINITION = DotName.createSimple(ManagedScheduledExecutorDefinition.class.getName());
private static final DotName MANAGED_SCHEDULED_EXECUTOR_DEFINITION_LIST = DotName.createSimple(ManagedScheduledExecutorDefinition.List.class.getName());
@Override
protected DotName getAnnotationDotName() {
return MANAGED_SCHEDULED_EXECUTOR_DEFINITION;
}
@Override
protected DotName getAnnotationCollectionDotName() {
return MANAGED_SCHEDULED_EXECUTOR_DEFINITION_LIST;
}
@Override
protected ResourceDefinitionInjectionSource processAnnotation(AnnotationInstance annotationInstance, PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
final String jndiName = AnnotationElement.asRequiredString(annotationInstance, AnnotationElement.NAME);
final String context = AnnotationElement.asOptionalString(annotationInstance, ManagedScheduledExecutorDefinitionInjectionSource.CONTEXT_PROP);
final String hungTaskThresholdString = AnnotationElement.asOptionalString(annotationInstance, ManagedScheduledExecutorDefinitionInjectionSource.HUNG_TASK_THRESHOLD_PROP);
final long hungTaskThreshold = hungTaskThresholdString != null && !hungTaskThresholdString.isEmpty() ? Math.max(Long.valueOf(hungTaskThresholdString), 0L) : 0L;
final int maxAsync = AnnotationElement.asOptionalInt(annotationInstance, ManagedScheduledExecutorDefinitionInjectionSource.MAX_ASYNC_PROP);
final ManagedScheduledExecutorDefinitionInjectionSource injectionSource = new ManagedScheduledExecutorDefinitionInjectionSource(jndiName);
injectionSource.setContextServiceRef(context);
injectionSource.setHungTaskThreshold(hungTaskThreshold);
injectionSource.setMaxAsync(maxAsync);
return injectionSource;
}
}
| 3,321 | 53.459016 | 182 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EJBClientDescriptorXMLAttribute.java | package org.jboss.as.ee.structure;
import java.util.HashMap;
import java.util.Map;
public enum EJBClientDescriptorXMLAttribute {
EXCLUDE_LOCAL_RECEIVER("exclude-local-receiver"),
LOCAL_RECEIVER_PASS_BY_VALUE("local-receiver-pass-by-value"),
CONNECT_TIMEOUT("connect-timeout"),
NAME("name"),
OUTBOUND_CONNECTION_REF("outbound-connection-ref"),
VALUE("value"),
MAX_ALLOWED_CONNECTED_NODES("max-allowed-connected-nodes"),
CLUSTER_NODE_SELECTOR("cluster-node-selector"),
USERNAME("username"),
SECURITY_REALM("security-realm"),
INVOCATION_TIMEOUT("invocation-timeout"),
DEPLOYMENT_NODE_SELECTOR("deployment-node-selector"),
DEFAULT_COMPRESSION("default-compression"),
URI("uri"),
// default unknown attribute
UNKNOWN(null);
private final String name;
EJBClientDescriptorXMLAttribute(final String name) {
this.name = name;
}
/**
* Get the local name of this attribute.
*
* @return the local name
*/
public String getLocalName() {
return name;
}
private static final Map<String, EJBClientDescriptorXMLAttribute> MAP;
static {
final Map<String, EJBClientDescriptorXMLAttribute> map = new HashMap<String, EJBClientDescriptorXMLAttribute>();
for (EJBClientDescriptorXMLAttribute element : values()) {
final String name = element.getLocalName();
if (name != null)
map.put(name, element);
}
MAP = map;
}
public static EJBClientDescriptorXMLAttribute forName(String localName) {
final EJBClientDescriptorXMLAttribute element = MAP.get(localName);
return element == null ? UNKNOWN : element;
}
@Override
public String toString() {
return getLocalName();
}
}
| 1,807 | 27.698413 | 120 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/ApplicationClientDeploymentProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.structure;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.SubDeploymentMarker;
import org.jboss.as.server.deployment.module.ModuleRootMarker;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.metadata.ear.spec.ModuleMetaData;
import org.jboss.vfs.VirtualFile;
import java.util.List;
import java.util.Locale;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
/**
* Processor that sets up application clients. If this is an ear deployment it will mark the client as
* a sub deployment.
* If this is an application client deployment it will set the deployment type.
* <p/>
*
* @author Stuart Douglas
*/
public class ApplicationClientDeploymentProcessor implements DeploymentUnitProcessor {
private static final String META_INF_APPLICATION_CLIENT_XML = "META-INF/application-client.xml";
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
List<ResourceRoot> potentialSubDeployments = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : potentialSubDeployments) {
if (ModuleRootMarker.isModuleRoot(resourceRoot)) {
// module roots cannot be ejb jars
continue;
}
VirtualFile appclientClientXml = resourceRoot.getRoot().getChild(META_INF_APPLICATION_CLIENT_XML);
if (appclientClientXml.exists()) {
SubDeploymentMarker.mark(resourceRoot);
ModuleRootMarker.mark(resourceRoot);
} else {
final Manifest manifest = resourceRoot.getAttachment(Attachments.MANIFEST);
if (manifest != null) {
Attributes main = manifest.getMainAttributes();
if (main != null) {
String mainClass = main.getValue("Main-Class");
if (mainClass != null && !mainClass.isEmpty()) {
SubDeploymentMarker.mark(resourceRoot);
ModuleRootMarker.mark(resourceRoot);
}
}
}
}
}
} else if (deploymentUnit.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final ModuleMetaData md = root.getAttachment(org.jboss.as.ee.structure.Attachments.MODULE_META_DATA);
if (md != null) {
if (md.getType() == ModuleMetaData.ModuleType.Client) {
DeploymentTypeMarker.setType(DeploymentType.APPLICATION_CLIENT, deploymentUnit);
}
} else {
VirtualFile appclientClientXml = root.getRoot().getChild(META_INF_APPLICATION_CLIENT_XML);
if (appclientClientXml.exists()) {
DeploymentTypeMarker.setType(DeploymentType.APPLICATION_CLIENT, deploymentUnit);
} else {
final Manifest manifest = root.getAttachment(Attachments.MANIFEST);
if (manifest != null) {
Attributes main = manifest.getMainAttributes();
if (main != null) {
String mainClass = main.getValue("Main-Class");
if (mainClass != null && !mainClass.isEmpty()) {
DeploymentTypeMarker.setType(DeploymentType.APPLICATION_CLIENT, deploymentUnit);
}
}
}
}
}
}
}
}
| 5,251 | 47.62963 | 118 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EJBClientDescriptorXMLElement.java | package org.jboss.as.ee.structure;
import java.util.HashMap;
import java.util.Map;
public enum EJBClientDescriptorXMLElement {
CLIENT_CONTEXT("client-context"),
NODE("node"),
EJB_RECEIVERS("ejb-receivers"),
JBOSS_EJB_CLIENT("jboss-ejb-client"),
REMOTING_EJB_RECEIVER("remoting-ejb-receiver"),
HTTP_CONNECTIONS("http-connections"),
HTTP_CONNECTION("http-connection"),
CLUSTERS("clusters"),
CLUSTER("cluster"),
CHANNEL_CREATION_OPTIONS("channel-creation-options"),
CONNECTION_CREATION_OPTIONS("connection-creation-options"),
PROPERTY("property"),
PROFILE("profile"),
// default unknown element
UNKNOWN(null);
private final String name;
EJBClientDescriptorXMLElement(final String name) {
this.name = name;
}
public String getLocalName() {
return name;
}
private static final Map<String, EJBClientDescriptorXMLElement> MAP;
static {
final Map<String, EJBClientDescriptorXMLElement> map = new HashMap<String, EJBClientDescriptorXMLElement>();
for (EJBClientDescriptorXMLElement element : values()) {
final String name = element.getLocalName();
if (name != null) map.put(name, element);
}
MAP = map;
}
public static EJBClientDescriptorXMLElement forName(String localName) {
final EJBClientDescriptorXMLElement element = MAP.get(localName);
return element == null ? UNKNOWN : element;
}
}
| 1,478 | 29.183673 | 116 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EJBClientDescriptor12Parser.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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.ee.structure;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import java.util.EnumSet;
import java.util.Properties;
import java.util.Set;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.ee.metadata.EJBClientDescriptorMetaData;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Parser for urn:jboss:ejb-client:1.2:jboss-ejb-client
*
* @author Jaikiran Pai
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
* @author <a href="mailto:[email protected]">Wolf-Dieter Fink</a>
*/
class EJBClientDescriptor12Parser extends EJBClientDescriptor11Parser {
public static final String NAMESPACE_1_2 = "urn:jboss:ejb-client:1.2";
protected EJBClientDescriptor12Parser(final PropertyReplacer propertyReplacer) {
super(propertyReplacer);
}
protected void parseClientContext(final XMLExtendedStreamReader reader,
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader
.getAttributeLocalName(i));
final String value = readResolveValue(reader, i);
switch (attribute) {
case INVOCATION_TIMEOUT:
final long invocationTimeout = Long.parseLong(value);
ejbClientDescriptorMetaData.setInvocationTimeout(invocationTimeout);
break;
case DEPLOYMENT_NODE_SELECTOR:
ejbClientDescriptorMetaData.setDeploymentNodeSelector(value);
break;
default:
unexpectedContent(reader);
}
}
final Set<EJBClientDescriptorXMLElement> visited = EnumSet.noneOf(EJBClientDescriptorXMLElement.class);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
if (visited.contains(element)) {
unexpectedElement(reader);
}
visited.add(element);
switch (element) {
case EJB_RECEIVERS:
this.parseEJBReceivers(reader, ejbClientDescriptorMetaData);
break;
case CLUSTERS:
this.parseClusters(reader, ejbClientDescriptorMetaData);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
/**
* connectTimeout added
*/
protected void parseRemotingReceiver(final XMLExtendedStreamReader reader,
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
String outboundConnectionRef = null;
final Set<EJBClientDescriptorXMLAttribute> required = EnumSet
.of(EJBClientDescriptorXMLAttribute.OUTBOUND_CONNECTION_REF);
final int count = reader.getAttributeCount();
EJBClientDescriptorMetaData.RemotingReceiverConfiguration remotingReceiverConfiguration = null;
long connectTimeout = 5000;
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader
.getAttributeLocalName(i));
required.remove(attribute);
final String value = readResolveValue(reader, i);
switch (attribute) {
case OUTBOUND_CONNECTION_REF:
outboundConnectionRef = value;
remotingReceiverConfiguration = ejbClientDescriptorMetaData
.addRemotingReceiverConnectionRef(outboundConnectionRef);
break;
case CONNECT_TIMEOUT:
connectTimeout = Long.parseLong(value);
break;
default:
unexpectedContent(reader);
}
}
if (!required.isEmpty()) {
missingAttributes(reader.getLocation(), required);
}
// set the timeout
remotingReceiverConfiguration.setConnectionTimeout(connectTimeout);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case CHANNEL_CREATION_OPTIONS:
final Properties channelCreationOptions = this.parseChannelCreationOptions(reader);
remotingReceiverConfiguration.setChannelCreationOptions(channelCreationOptions);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
}
| 6,969 | 40.987952 | 127 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/InitializeInOrderProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.structure;
import java.util.HashMap;
import java.util.Map;
import org.jboss.as.server.deployment.DeploymentCompleteServiceProcessor;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.Phase;
import org.jboss.as.server.deployment.Services;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.metadata.ear.spec.EarMetaData;
import org.jboss.metadata.ear.spec.ModuleMetaData;
import org.jboss.msc.service.ServiceName;
/**
* Sets up dependencies for the next phase if initialize in order is set.
*
* @author Stuart Douglas
*/
public class InitializeInOrderProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final DeploymentUnit parent = deploymentUnit.getParent();
if (parent == null) {
return;
}
final EarMetaData earConfig = parent.getAttachment(Attachments.EAR_METADATA);
if (earConfig != null) {
final boolean inOrder = earConfig.getInitializeInOrder();
if (inOrder && earConfig.getModules().size() > 1) {
final Map<String, DeploymentUnit> deploymentUnitMap = new HashMap<String, DeploymentUnit>();
for (final DeploymentUnit subDeployment : parent.getAttachment(org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS)) {
final ResourceRoot deploymentRoot = subDeployment.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final ModuleMetaData moduleMetaData = deploymentRoot.getAttachment(Attachments.MODULE_META_DATA);
if (moduleMetaData != null) {
deploymentUnitMap.put(moduleMetaData.getFileName(), subDeployment);
}
}
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final ModuleMetaData thisModulesMetadata = deploymentRoot.getAttachment(Attachments.MODULE_META_DATA);
if (thisModulesMetadata != null && thisModulesMetadata.getType() != ModuleMetaData.ModuleType.Client) {
ModuleMetaData previous = null;
boolean found = false;
for (ModuleMetaData module : earConfig.getModules()) {
if (module.getType() != ModuleMetaData.ModuleType.Client) {
if (module.getFileName().equals(thisModulesMetadata.getFileName())) {
found = true;
break;
}
previous = module;
}
}
if (previous != null && found) {
//now we know the previous module we can setup the service dependencies
//we setup one on the deployment service, and also one on every component
final ServiceName serviceName = Services.deploymentUnitName(parent.getName(), previous.getFileName());
phaseContext.addToAttachmentList(org.jboss.as.server.deployment.Attachments.NEXT_PHASE_DEPS, serviceName.append(Phase.INSTALL.name()));
final DeploymentUnit prevDeployment = deploymentUnitMap.get(previous.getFileName());
phaseContext.addToAttachmentList(org.jboss.as.server.deployment.Attachments.NEXT_PHASE_DEPS, DeploymentCompleteServiceProcessor.serviceName(prevDeployment.getServiceName()));
}
}
}
}
}
}
| 5,043 | 51.541667 | 198 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EarMetaDataParsingProcessor.java | /*
* 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.ee.structure;
import java.io.InputStream;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.DeploymentDescriptorEnvironment;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.metadata.ear.jboss.JBossAppMetaData;
import org.jboss.metadata.ear.merge.JBossAppMetaDataMerger;
import org.jboss.metadata.ear.parser.jboss.JBossAppMetaDataParser;
import org.jboss.metadata.ear.parser.spec.EarMetaDataParser;
import org.jboss.metadata.ear.spec.EarMetaData;
import org.jboss.metadata.parser.util.NoopXMLResolver;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.vfs.VFSUtils;
import org.jboss.vfs.VirtualFile;
/**
* Deployment processor responsible for parsing the application.xml file of an ear.
*
* @author John Bailey
*/
public class EarMetaDataParsingProcessor implements DeploymentUnitProcessor {
private static final String APPLICATION_XML = "META-INF/application.xml";
private static final String JBOSS_APP_XML = "META-INF/jboss-app.xml";
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final VirtualFile deploymentFile = deploymentRoot.getRoot();
EarMetaData earMetaData = handleSpecMetadata(deploymentFile, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
JBossAppMetaData jbossMetaData = handleJbossMetadata(deploymentFile, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit), deploymentUnit);
if (earMetaData == null && jbossMetaData == null) {
return;
}
// the jboss-app.xml has a distinct-name configured then attach it to the deployment unit
if (jbossMetaData != null && jbossMetaData.getDistinctName() != null) {
deploymentUnit.putAttachment(Attachments.DISTINCT_NAME, jbossMetaData.getDistinctName());
}
JBossAppMetaData merged;
if (earMetaData != null) {
merged = new JBossAppMetaData(earMetaData.getEarVersion());
} else {
merged = new JBossAppMetaData();
}
JBossAppMetaDataMerger.merge(merged, jbossMetaData, earMetaData);
deploymentUnit.putAttachment(Attachments.EAR_METADATA, merged);
if (merged.getEarEnvironmentRefsGroup() != null) {
final DeploymentDescriptorEnvironment bindings = new DeploymentDescriptorEnvironment("java:app/env/", merged.getEarEnvironmentRefsGroup());
deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.MODULE_DEPLOYMENT_DESCRIPTOR_ENVIRONMENT, bindings);
}
}
private EarMetaData handleSpecMetadata(VirtualFile deploymentFile, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
final VirtualFile applicationXmlFile = deploymentFile.getChild(APPLICATION_XML);
if (!applicationXmlFile.exists()) {
return null;
}
InputStream inputStream = null;
try {
inputStream = applicationXmlFile.openStream();
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setXMLResolver(NoopXMLResolver.create());
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(inputStream);
return EarMetaDataParser.INSTANCE.parse(xmlReader, propertyReplacer);
} catch (Exception e) {
throw EeLogger.ROOT_LOGGER.failedToParse(e, applicationXmlFile);
} finally {
VFSUtils.safeClose(inputStream);
}
}
private JBossAppMetaData handleJbossMetadata(VirtualFile deploymentFile, final PropertyReplacer propertyReplacer, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
final VirtualFile applicationXmlFile = deploymentFile.getChild(JBOSS_APP_XML);
if (!applicationXmlFile.exists()) {
//may have been in jboss-all.xml
return deploymentUnit.getAttachment(AppJBossAllParser.ATTACHMENT_KEY);
}
InputStream inputStream = null;
try {
inputStream = applicationXmlFile.openStream();
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setXMLResolver(NoopXMLResolver.create());
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(inputStream);
return JBossAppMetaDataParser.INSTANCE.parse(xmlReader, propertyReplacer);
} catch (Exception e) {
throw EeLogger.ROOT_LOGGER.failedToParse(e, applicationXmlFile);
} finally {
VFSUtils.safeClose(inputStream);
}
}
public void undeploy(final DeploymentUnit deploymentUnit) {
deploymentUnit.removeAttachment(Attachments.EAR_METADATA);
}
}
| 6,491 | 46.043478 | 197 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EarInitializationProcessor.java | /*
* 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.ee.structure;
import java.util.Locale;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
/**
* Processor responsible for detecting and marking EAR file deployments.
*
* @author John Bailey
*/
public class EarInitializationProcessor implements DeploymentUnitProcessor {
private static final String EAR_EXTENSION = ".ear";
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// Make sure this is an EAR deployment
String deploymentName = deploymentUnit.getName().toLowerCase(Locale.ENGLISH);
if (deploymentName.endsWith(EAR_EXTENSION)) {
// Let other processors know this is an EAR deployment
DeploymentTypeMarker.setType(DeploymentType.EAR, deploymentUnit);
}
}
}
| 2,116 | 39.711538 | 102 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/Attachments.java | /*
* 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.ee.structure;
import org.jboss.as.ee.metadata.EJBClientDescriptorMetaData;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.metadata.ear.spec.EarMetaData;
import org.jboss.metadata.ear.spec.ModuleMetaData;
import org.jboss.vfs.VirtualFile;
/**
* EE related attachments.
*
* @author John Bailey
* @author Stuart Douglas
*/
public final class Attachments {
public static final AttachmentKey<EarMetaData> EAR_METADATA = AttachmentKey.create(EarMetaData.class);
/**
* The distinct-name that is configured for the EE deployment, in the deployment descriptor
*/
public static final AttachmentKey<String> DISTINCT_NAME = AttachmentKey.create(String.class);
public static final AttachmentKey<ModuleMetaData> MODULE_META_DATA = AttachmentKey.create(ModuleMetaData.class);
public static final AttachmentKey<EJBClientDescriptorMetaData> EJB_CLIENT_METADATA = AttachmentKey.create(EJBClientDescriptorMetaData.class);
/**
* The alternate deployment descriptor location
*/
public static final AttachmentKey<VirtualFile> ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR = AttachmentKey.create(VirtualFile.class);
public static final AttachmentKey<VirtualFile> ALTERNATE_WEB_DEPLOYMENT_DESCRIPTOR = AttachmentKey.create(VirtualFile.class);
public static final AttachmentKey<VirtualFile> ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR = AttachmentKey.create(VirtualFile.class);
public static final AttachmentKey<VirtualFile> ALTERNATE_CONNECTOR_DEPLOYMENT_DESCRIPTOR = AttachmentKey.create(VirtualFile.class);
/**
* A Marker that identifies the type of deployment
*/
public static final AttachmentKey<DeploymentType> DEPLOYMENT_TYPE = AttachmentKey.create(DeploymentType.class);
/**
* If this is set to true property replacement will be enabled for spec descriptors
*/
public static final AttachmentKey<Boolean> SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT = AttachmentKey.create(Boolean.class);
/**
* If this is set to true property replacement will be enabled for jboss descriptors
*/
public static final AttachmentKey<Boolean> JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT = AttachmentKey.create(Boolean.class);
/**
* If this is set to true property replacement will be enabled for Jakarta Enterprise Beans annotations
*/
public static final AttachmentKey<Boolean> ANNOTATION_PROPERTY_REPLACEMENT = AttachmentKey.create(Boolean.class);
private Attachments() {
}
}
| 3,537 | 42.146341 | 145 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/AppJBossAllParser.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, 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.ee.structure;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.jbossallxml.JBossAllXMLParser;
import org.jboss.metadata.ear.jboss.JBossAppMetaData;
import org.jboss.metadata.ear.parser.jboss.JBossAppMetaDataParser;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* The app client handler for jboss-all.xml
*
* @author Stuart Douglas
*/
public class AppJBossAllParser implements JBossAllXMLParser<JBossAppMetaData> {
public static final AttachmentKey<JBossAppMetaData> ATTACHMENT_KEY = AttachmentKey.create(JBossAppMetaData.class);
public static final QName ROOT_ELEMENT = new QName("http://www.jboss.com/xml/ns/javaee", "jboss-app");
@Override
public JBossAppMetaData parse(final XMLExtendedStreamReader reader, final DeploymentUnit deploymentUnit) throws XMLStreamException {
return JBossAppMetaDataParser.INSTANCE.parse(reader, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
}
}
| 2,171 | 40.769231 | 136 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EarDependencyProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, 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.ee.structure;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.Services;
import static org.jboss.as.server.deployment.Attachments.NEXT_PHASE_DEPS;
import static org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS;
/**
* Processor which ensures that subdeployments of an EAR all synchronize before the next phase.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class EarDependencyProcessor implements DeploymentUnitProcessor {
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
if (phaseContext.getAttachment(Attachments.DEPLOYMENT_TYPE) == DeploymentType.EAR) {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
// Make sure the next phase of this EAR depends on this phase of not just the EAR but also all subdeployments
for (DeploymentUnit subdeployment : deploymentUnit.getAttachmentList(SUB_DEPLOYMENTS)) {
phaseContext.addToAttachmentList(NEXT_PHASE_DEPS, Services.deploymentUnitName(deploymentUnit.getName(), subdeployment.getName(), phaseContext.getPhase()));
}
}
}
}
| 2,480 | 47.647059 | 171 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EarStructureProcessor.java | /*
* 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.ee.structure;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.MountedDeploymentOverlay;
import org.jboss.as.server.deployment.SubDeploymentMarker;
import org.jboss.as.server.deployment.SubExplodedDeploymentMarker;
import org.jboss.as.server.deployment.module.ModuleRootMarker;
import org.jboss.as.server.deployment.module.MountHandle;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.as.server.deployment.module.TempFileProviderService;
import org.jboss.metadata.ear.spec.EarMetaData;
import org.jboss.metadata.ear.spec.ModuleMetaData;
import org.jboss.metadata.ear.spec.ModuleMetaData.ModuleType;
import org.jboss.vfs.VFS;
import org.jboss.vfs.VFSUtils;
import org.jboss.vfs.VirtualFile;
import org.jboss.vfs.VisitorAttributes;
import org.jboss.vfs.util.SuffixMatchFilter;
/**
* Deployment processor responsible for detecting EAR deployments and putting setting up the basic structure.
*
* @author John Bailey
* @author Stuart Douglas
*/
public class EarStructureProcessor implements DeploymentUnitProcessor {
private static final String JAR_EXTENSION = ".jar";
private static final String WAR_EXTENSION = ".war";
private static final String SAR_EXTENSION = ".sar";
private static final String RAR_EXTENSION = ".rar";
private static final List<String> CHILD_ARCHIVE_EXTENSIONS = new ArrayList<String>();
static {
CHILD_ARCHIVE_EXTENSIONS.add(JAR_EXTENSION);
CHILD_ARCHIVE_EXTENSIONS.add(WAR_EXTENSION);
CHILD_ARCHIVE_EXTENSIONS.add(SAR_EXTENSION);
CHILD_ARCHIVE_EXTENSIONS.add(RAR_EXTENSION);
}
private static final SuffixMatchFilter CHILD_ARCHIVE_FILTER = new SuffixMatchFilter(CHILD_ARCHIVE_EXTENSIONS, new VisitorAttributes() {
public boolean isLeavesOnly() {
return false;
}
});
private static final String DEFAULT_LIB_DIR = "lib";
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
final ResourceRoot deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile virtualFile = deploymentRoot.getRoot();
// Make sure we don't index or add this as a module root
deploymentRoot.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
ModuleRootMarker.mark(deploymentRoot, false);
String libDirName = DEFAULT_LIB_DIR;
//its possible that the ear metadata could come for jboss-app.xml
final boolean appXmlPresent = deploymentRoot.getRoot().getChild("META-INF/application.xml").exists();
final EarMetaData earMetaData = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
if (earMetaData != null) {
final String xmlLibDirName = earMetaData.getLibraryDirectory();
if (xmlLibDirName != null) {
if (xmlLibDirName.length() == 1 && xmlLibDirName.charAt(0) == '/') {
throw EeLogger.ROOT_LOGGER.rootAsLibraryDirectory();
}
libDirName = xmlLibDirName;
}
}
// Process all the children
Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
try {
final VirtualFile libDir;
// process the lib directory
if (!libDirName.isEmpty()) {
libDir = virtualFile.getChild(libDirName);
if (libDir.exists()) {
List<VirtualFile> libArchives = libDir.getChildren(CHILD_ARCHIVE_FILTER);
for (final VirtualFile child : libArchives) {
String relativeName = child.getPathNameRelativeTo(deploymentRoot.getRoot());
MountedDeploymentOverlay overlay = overlays.get(relativeName);
final MountHandle mountHandle;
if (overlay != null) {
overlay.remountAsZip(false);
mountHandle = MountHandle.create(null);
} else {
final Closeable closable = child.isFile() ? mount(child, false) : null;
mountHandle = MountHandle.create(closable);
}
final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
if (child.getName().toLowerCase(Locale.ENGLISH).endsWith(JAR_EXTENSION)) {
ModuleRootMarker.mark(childResource);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
}
}
}
} else {
libDir = null;
}
// scan the ear looking for wars and jars
final List<VirtualFile> childArchives = new ArrayList<VirtualFile>(virtualFile.getChildren(new SuffixMatchFilter(
CHILD_ARCHIVE_EXTENSIONS, new VisitorAttributes() {
@Override
public boolean isLeavesOnly() {
return false;
}
@Override
public boolean isRecurse(VirtualFile file) {
// don't recurse into /lib
if (file.equals(libDir)) {
return false;
}
for (String suffix : CHILD_ARCHIVE_EXTENSIONS) {
if (file.getName().endsWith(suffix)) {
// don't recurse into sub deployments
return false;
}
}
return true;
}
})));
// if there is no application.xml then look in the ear root for modules
if (!appXmlPresent) {
for (final VirtualFile child : childArchives) {
final boolean isWarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(WAR_EXTENSION);
final boolean isRarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(RAR_EXTENSION);
this.createResourceRoot(deploymentUnit, child, isWarFile || isRarFile, isWarFile);
}
} else {
final Set<VirtualFile> subDeploymentFiles = new HashSet<VirtualFile>();
// otherwise read from application.xml
for (final ModuleMetaData module : earMetaData.getModules()) {
if(module.getFileName().endsWith(".xml")) {
throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
}
final VirtualFile moduleFile = virtualFile.getChild(module.getFileName());
if (!moduleFile.exists()) {
throw EeLogger.ROOT_LOGGER.cannotProcessEarModule(virtualFile, module.getFileName());
}
if (libDir != null) {
VirtualFile moduleParentFile = moduleFile.getParent();
if (moduleParentFile != null && libDir.equals(moduleParentFile)) {
throw EeLogger.ROOT_LOGGER.earModuleChildOfLibraryDirectory(libDirName, module.getFileName());
}
}
// maintain this in a collection of subdeployment virtual files, to be used later
subDeploymentFiles.add(moduleFile);
final boolean webArchive = module.getType() == ModuleType.Web;
final ResourceRoot childResource = this.createResourceRoot(deploymentUnit, moduleFile, true, webArchive);
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.MODULE_META_DATA, module);
if (!webArchive) {
ModuleRootMarker.mark(childResource);
}
final String alternativeDD = module.getAlternativeDD();
if (alternativeDD != null && alternativeDD.trim().length() > 0) {
final VirtualFile alternateDeploymentDescriptor = deploymentRoot.getRoot().getChild(alternativeDD);
if (!alternateDeploymentDescriptor.exists()) {
throw EeLogger.ROOT_LOGGER.alternateDeploymentDescriptor(alternateDeploymentDescriptor, moduleFile);
}
switch (module.getType()) {
case Client:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Connector:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CONNECTOR_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Ejb:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Web:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_WEB_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Service:
throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
}
}
}
// now check the rest of the archive for any other jar/sar files
for (final VirtualFile child : childArchives) {
if (subDeploymentFiles.contains(child)) {
continue;
}
final String fileName = child.getName().toLowerCase(Locale.ENGLISH);
if (fileName.endsWith(SAR_EXTENSION) || fileName.endsWith(JAR_EXTENSION)) {
this.createResourceRoot(deploymentUnit, child, false, false);
}
}
}
} catch (IOException e) {
throw EeLogger.ROOT_LOGGER.failedToProcessChild(e, virtualFile);
}
}
private static Closeable mount(VirtualFile moduleFile, boolean explode) throws IOException {
return explode ? VFS.mountZipExpanded(moduleFile, moduleFile, TempFileProviderService.provider())
: VFS.mountZip(moduleFile, moduleFile, TempFileProviderService.provider());
}
/**
* Creates a {@link ResourceRoot} for the passed {@link VirtualFile file} and adds it to the list of {@link ResourceRoot}s
* in the {@link DeploymentUnit deploymentUnit}
*
* @param deploymentUnit The deployment unit
* @param file The file for which the resource root will be created
* @param markAsSubDeployment If this is true, then the {@link ResourceRoot} that is created will be marked as a subdeployment
* through a call to {@link SubDeploymentMarker#mark(org.jboss.as.server.deployment.module.ResourceRoot)}
* @param explodeDuringMount If this is true then the {@link VirtualFile file} will be exploded during mount,
* while creating the {@link ResourceRoot}
* @return Returns the created {@link ResourceRoot}
* @throws IOException
*/
private ResourceRoot createResourceRoot(final DeploymentUnit deploymentUnit, final VirtualFile file, final boolean markAsSubDeployment, final boolean explodeDuringMount) throws IOException {
final boolean war = file.getName().toLowerCase(Locale.ENGLISH).endsWith(WAR_EXTENSION);
final Closeable closable = file.isFile() ? mount(file, explodeDuringMount) : exportExplodedWar(war, file, deploymentUnit);
final MountHandle mountHandle = MountHandle.create(closable);
final ResourceRoot resourceRoot = new ResourceRoot(file, mountHandle);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, resourceRoot);
if (markAsSubDeployment) {
SubDeploymentMarker.mark(resourceRoot);
}
if (war) {
resourceRoot.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
SubExplodedDeploymentMarker.mark(resourceRoot);
}
return resourceRoot;
}
private Closeable exportExplodedWar(final boolean war, final VirtualFile file, final DeploymentUnit deploymentUnit) throws IOException {
if (isExplodedWarInArchiveEar(war, file, deploymentUnit)) {
File warContent = file.getPhysicalFile();
VFSUtils.recursiveCopy(file, warContent.getParentFile());
return VFS.mountReal(warContent, file);
}
return null;
}
private boolean isExplodedWarInArchiveEar(final boolean war, final VirtualFile file, final DeploymentUnit deploymentUnit) {
return war && !file.isFile() && deploymentUnit.hasAttachment(Attachments.DEPLOYMENT_CONTENTS) && deploymentUnit.getAttachment(Attachments.DEPLOYMENT_CONTENTS).isFile();
}
public void undeploy(DeploymentUnit context) {
final List<ResourceRoot> children = context.removeAttachment(Attachments.RESOURCE_ROOTS);
if (children != null) {
for (ResourceRoot childRoot : children) {
VFSUtils.safeClose(childRoot.getMountHandle());
}
}
}
}
| 15,522 | 49.399351 | 194 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EJBClientDescriptor11Parser.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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.ee.structure;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import java.util.EnumSet;
import java.util.Properties;
import java.util.Set;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.ee.metadata.EJBClientDescriptorMetaData;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Parser for urn:jboss:ejb-client:1.1:jboss-ejb-client
*
* @author Jaikiran Pai
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
* @author <a href="mailto:[email protected]">Wolf-Dieter Fink</a>
*/
class EJBClientDescriptor11Parser extends EJBClientDescriptor10Parser {
public static final String NAMESPACE_1_1 = "urn:jboss:ejb-client:1.1";
protected EJBClientDescriptor11Parser(final PropertyReplacer propertyReplacer) {
super(propertyReplacer);
}
protected void parseClientContext(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
final Set<EJBClientDescriptorXMLElement> visited = EnumSet.noneOf(EJBClientDescriptorXMLElement.class);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
if (visited.contains(element)) {
unexpectedElement(reader);
}
visited.add(element);
switch (element) {
case EJB_RECEIVERS:
this.parseEJBReceivers(reader, ejbClientDescriptorMetaData);
break;
case CLUSTERS:
this.parseClusters(reader, ejbClientDescriptorMetaData);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected void parseClusters(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case CLUSTER:
this.parseCluster(reader, ejbClientDescriptorMetaData);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected void parseCluster(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
final Set<EJBClientDescriptorXMLAttribute> required = EnumSet.of(EJBClientDescriptorXMLAttribute.NAME);
final int count = reader.getAttributeCount();
String clusterName = null;
String clusterNodeSelector = null;
long connectTimeout = 5000;
long maxAllowedConnectedNodes = 10;
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
final String value = readResolveValue(reader, i);
switch (attribute) {
case NAME:
clusterName = value;
break;
case CONNECT_TIMEOUT:
connectTimeout = Long.parseLong(value);
break;
case CLUSTER_NODE_SELECTOR:
clusterNodeSelector = value;
break;
case MAX_ALLOWED_CONNECTED_NODES:
maxAllowedConnectedNodes = Long.parseLong(value);
break;
case USERNAME:
throw ROOT_LOGGER.attributeNoLongerSupported(EJBClientDescriptorXMLAttribute.USERNAME.getLocalName());
case SECURITY_REALM:
throw ROOT_LOGGER.attributeNoLongerSupported(EJBClientDescriptorXMLAttribute.SECURITY_REALM.getLocalName());
default:
unexpectedContent(reader);
}
}
if (!required.isEmpty()) {
missingAttributes(reader.getLocation(), required);
}
// add a new cluster config to the client configuration metadata
final EJBClientDescriptorMetaData.ClusterConfig clusterConfig = ejbClientDescriptorMetaData.newClusterConfig(clusterName);
clusterConfig.setConnectTimeout(connectTimeout);
clusterConfig.setNodeSelector(clusterNodeSelector);
clusterConfig.setMaxAllowedConnectedNodes(maxAllowedConnectedNodes);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case CONNECTION_CREATION_OPTIONS:
final Properties connectionCreationOptions = this.parseConnectionCreationOptions(reader);
clusterConfig.setConnectionOptions(connectionCreationOptions);
break;
case CHANNEL_CREATION_OPTIONS:
final Properties channelCreationOptions = this.parseChannelCreationOptions(reader);
clusterConfig.setChannelCreationOptions(channelCreationOptions);
break;
case NODE:
this.parseClusterNode(reader, clusterConfig);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected Properties parseConnectionCreationOptions(final XMLExtendedStreamReader reader) throws XMLStreamException {
final Properties connectionCreationOptions = new Properties();
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return connectionCreationOptions;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case PROPERTY:
connectionCreationOptions.putAll(this.parseProperty(reader));
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
// unreachable
return connectionCreationOptions;
}
protected Properties parseChannelCreationOptions(final XMLExtendedStreamReader reader) throws XMLStreamException {
final Properties channelCreationOptions = new Properties();
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return channelCreationOptions;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case PROPERTY:
channelCreationOptions.putAll(this.parseProperty(reader));
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
// unreachable
return channelCreationOptions;
}
protected void parseClusterNode(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData.ClusterConfig clusterConfig) throws XMLStreamException {
final Set<EJBClientDescriptorXMLAttribute> required = EnumSet.of(EJBClientDescriptorXMLAttribute.NAME);
final int count = reader.getAttributeCount();
String nodeName = null;
long connectTimeout = 5000;
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
final String value = readResolveValue(reader, i);
switch (attribute) {
case NAME:
nodeName = value;
break;
case CONNECT_TIMEOUT:
connectTimeout = Long.parseLong(value);
break;
case USERNAME:
throw ROOT_LOGGER.attributeNoLongerSupported(EJBClientDescriptorXMLAttribute.USERNAME.getLocalName());
case SECURITY_REALM:
throw ROOT_LOGGER.attributeNoLongerSupported(EJBClientDescriptorXMLAttribute.SECURITY_REALM.getLocalName());
default:
unexpectedContent(reader);
}
}
if (!required.isEmpty()) {
missingAttributes(reader.getLocation(), required);
}
// add a new node config to the cluster config
final EJBClientDescriptorMetaData.ClusterNodeConfig clusterNodeConfig = clusterConfig.newClusterNode(nodeName);
clusterNodeConfig.setConnectTimeout(connectTimeout);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case CONNECTION_CREATION_OPTIONS:
final Properties connectionCreationOptions = this.parseConnectionCreationOptions(reader);
clusterNodeConfig.setConnectionOptions(connectionCreationOptions);
break;
case CHANNEL_CREATION_OPTIONS:
final Properties channelCreationOptions = this.parseChannelCreationOptions(reader);
clusterNodeConfig.setChannelCreationOptions(channelCreationOptions);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected Properties parseProperty(final XMLExtendedStreamReader reader) throws XMLStreamException {
final Set<EJBClientDescriptorXMLAttribute> required = EnumSet.of(EJBClientDescriptorXMLAttribute.NAME,
EJBClientDescriptorXMLAttribute.VALUE);
final int count = reader.getAttributeCount();
String name = null;
String value = null;
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
final String val = readResolveValue(reader, i);
switch (attribute) {
case NAME:
name = val;
break;
case VALUE:
value = val;
break;
default:
unexpectedContent(reader);
}
}
if (!required.isEmpty()) {
missingAttributes(reader.getLocation(), required);
}
// no child elements allowed
requireNoContent(reader);
final Properties property = new Properties();
property.put(name, value);
return property;
}
protected static void requireNoContent(final XMLExtendedStreamReader reader) throws XMLStreamException {
if (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
unexpectedElement(reader);
}
}
}
| 14,925 | 42.9 | 166 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EJBClientDescriptor15Parser.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2020, 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.ee.structure;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import java.util.EnumSet;
import java.util.Properties;
import java.util.Set;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.ee.metadata.EJBClientDescriptorMetaData;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Parser for urn:jboss:ejb-client:1.4:jboss-ejb-client
*
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
*/
class EJBClientDescriptor15Parser extends EJBClientDescriptor14Parser {
public static final String NAMESPACE_1_5 = "urn:jboss:ejb-client:1.5";
protected EJBClientDescriptor15Parser(final PropertyReplacer propertyReplacer) {
super(propertyReplacer);
}
protected void parseCluster(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
final Set<EJBClientDescriptorXMLAttribute> required = EnumSet.of(EJBClientDescriptorXMLAttribute.NAME);
final int count = reader.getAttributeCount();
String clusterName = null;
String clusterNodeSelector = null;
long connectTimeout = 5000;
long maxAllowedConnectedNodes = 10;
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
final String value = readResolveValue(reader, i);
switch (attribute) {
case NAME:
clusterName = value;
break;
case CONNECT_TIMEOUT:
connectTimeout = Long.parseLong(value);
break;
case CLUSTER_NODE_SELECTOR:
clusterNodeSelector = value;
break;
case MAX_ALLOWED_CONNECTED_NODES:
maxAllowedConnectedNodes = Long.parseLong(value);
break;
default:
unexpectedContent(reader);
}
}
if (!required.isEmpty()) {
missingAttributes(reader.getLocation(), required);
}
// add a new cluster config to the client configuration metadata
final EJBClientDescriptorMetaData.ClusterConfig clusterConfig = ejbClientDescriptorMetaData.newClusterConfig(clusterName);
clusterConfig.setConnectTimeout(connectTimeout);
clusterConfig.setNodeSelector(clusterNodeSelector);
clusterConfig.setMaxAllowedConnectedNodes(maxAllowedConnectedNodes);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case CONNECTION_CREATION_OPTIONS:
final Properties connectionCreationOptions = this.parseConnectionCreationOptions(reader);
clusterConfig.setConnectionOptions(connectionCreationOptions);
break;
case CHANNEL_CREATION_OPTIONS:
final Properties channelCreationOptions = this.parseChannelCreationOptions(reader);
clusterConfig.setChannelCreationOptions(channelCreationOptions);
break;
case NODE:
this.parseClusterNode(reader, clusterConfig);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected void parseClusterNode(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData.ClusterConfig clusterConfig) throws XMLStreamException {
final Set<EJBClientDescriptorXMLAttribute> required = EnumSet.of(EJBClientDescriptorXMLAttribute.NAME);
final int count = reader.getAttributeCount();
String nodeName = null;
long connectTimeout = 5000;
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
final String value = readResolveValue(reader, i);
switch (attribute) {
case NAME:
nodeName = value;
break;
case CONNECT_TIMEOUT:
connectTimeout = Long.parseLong(value);
break;
default:
unexpectedContent(reader);
}
}
if (!required.isEmpty()) {
missingAttributes(reader.getLocation(), required);
}
// add a new node config to the cluster config
final EJBClientDescriptorMetaData.ClusterNodeConfig clusterNodeConfig = clusterConfig.newClusterNode(nodeName);
clusterNodeConfig.setConnectTimeout(connectTimeout);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case CONNECTION_CREATION_OPTIONS:
final Properties connectionCreationOptions = this.parseConnectionCreationOptions(reader);
clusterNodeConfig.setConnectionOptions(connectionCreationOptions);
break;
case CHANNEL_CREATION_OPTIONS:
final Properties channelCreationOptions = this.parseChannelCreationOptions(reader);
clusterNodeConfig.setChannelCreationOptions(channelCreationOptions);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
}
| 7,884 | 43.548023 | 164 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/GlobalModuleDependencyProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.structure;
import java.util.List;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.module.ModuleDependency;
import org.jboss.as.server.deployment.module.ModuleSpecification;
import org.jboss.modules.Module;
import org.jboss.modules.filter.PathFilters;
import static org.jboss.as.ee.subsystem.GlobalModulesDefinition.GlobalModule;
/**
* Dependency processor that adds modules defined in the global-modules section of
* the configuration to all deployments.
*
* @author Stuart Douglas
*/
public class GlobalModuleDependencyProcessor implements DeploymentUnitProcessor {
private volatile List<GlobalModule> globalModules;
public GlobalModuleDependencyProcessor() {
}
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
final List<GlobalModule> globalMods = this.globalModules;
for (final GlobalModule module : globalMods) {
final ModuleDependency dependency = new ModuleDependency(Module.getBootModuleLoader(), module.getModuleIdentifier(), false, false, module.isServices(), false);
if (module.isMetaInf()) {
dependency.addImportFilter(PathFilters.getMetaInfSubdirectoriesFilter(), true);
dependency.addImportFilter(PathFilters.getMetaInfFilter(), true);
}
if(module.isAnnotations()) {
deploymentUnit.addToAttachmentList(Attachments.ADDITIONAL_ANNOTATION_INDEXES, module.getModuleIdentifier());
}
moduleSpecification.addSystemDependency(dependency);
}
}
/**
* Set the global modules configuration for the container.
* @param globalModules a fully resolved (i.e. with expressions resolved and default values set) global modules configuration
*/
public void setGlobalModules(final List<GlobalModule> globalModules) {
this.globalModules = globalModules;
}
}
| 3,513 | 41.853659 | 175 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/DeploymentTypeMarker.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.structure;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.module.ResourceRoot;
/**
* Helper class for dealing with the {@link Attachments#RESOURCE_ROOT_TYPE} attachment.
*
* @author Stuart Douglas
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
public final class DeploymentTypeMarker {
private DeploymentTypeMarker() {
// forbidden instantiation
}
public static boolean isType(final DeploymentType deploymentType, final DeploymentUnit deploymentUnit) {
return deploymentType == deploymentUnit.getAttachment(Attachments.DEPLOYMENT_TYPE);
}
public static boolean isType(final DeploymentType deploymentType, final ResourceRoot resourceRoot) {
return deploymentType == resourceRoot.getAttachment(Attachments.DEPLOYMENT_TYPE);
}
public static void setType(final DeploymentType deploymentType, final DeploymentUnit deploymentUnit) {
deploymentUnit.putAttachment(Attachments.DEPLOYMENT_TYPE, deploymentType);
final ResourceRoot resourceRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
if (resourceRoot != null) {
resourceRoot.putAttachment(Attachments.DEPLOYMENT_TYPE, deploymentType);
}
}
}
| 2,351 | 41 | 131 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EJBClientDescriptor14Parser.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2020, 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.ee.structure;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import java.util.EnumSet;
import java.util.Set;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.ee.metadata.EJBClientDescriptorMetaData;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Parser for urn:jboss:ejb-client:1.4:jboss-ejb-client
*
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
*/
class EJBClientDescriptor14Parser extends EJBClientDescriptor13Parser {
public static final String NAMESPACE_1_4 = "urn:jboss:ejb-client:1.4";
protected EJBClientDescriptor14Parser(final PropertyReplacer propertyReplacer) {
super(propertyReplacer);
}
protected void parseClientContext(final XMLExtendedStreamReader reader,
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader
.getAttributeLocalName(i));
final String value = readResolveValue(reader, i);
switch (attribute) {
case INVOCATION_TIMEOUT:
final Long invocationTimeout = Long.parseLong(value);
ejbClientDescriptorMetaData.setInvocationTimeout(invocationTimeout);
break;
case DEPLOYMENT_NODE_SELECTOR:
final String deploymentNodeSelector = readResolveValue(reader, i);
ejbClientDescriptorMetaData.setDeploymentNodeSelector(deploymentNodeSelector);
break;
case DEFAULT_COMPRESSION:
final Integer defaultRequestCompression = Integer.parseInt(value);
ejbClientDescriptorMetaData.setDefaultCompression(defaultRequestCompression);
break;
default:
unexpectedContent(reader);
}
}
final Set<EJBClientDescriptorXMLElement> visited = EnumSet.noneOf(EJBClientDescriptorXMLElement.class);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
if (visited.contains(element)) {
unexpectedElement(reader);
}
visited.add(element);
switch (element) {
case EJB_RECEIVERS:
this.parseEJBReceivers(reader, ejbClientDescriptorMetaData);
break;
case HTTP_CONNECTIONS:
this.parseHttpConnections(reader, ejbClientDescriptorMetaData);
break;
case CLUSTERS:
this.parseClusters(reader, ejbClientDescriptorMetaData);
break;
case PROFILE:
this.parseProfile(reader, ejbClientDescriptorMetaData);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected void parseHttpConnections(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case HTTP_CONNECTION:
this.parseHttpConnection(reader, ejbClientDescriptorMetaData);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected void parseHttpConnection(final XMLExtendedStreamReader reader,
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
String uri = null;
final Set<EJBClientDescriptorXMLAttribute> required = EnumSet.of(EJBClientDescriptorXMLAttribute.URI);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader
.getAttributeLocalName(i));
required.remove(attribute);
final String value = readResolveValue(reader, i);
switch (attribute) {
case URI:
uri = value;
break;
default:
unexpectedContent(reader);
}
}
if (!required.isEmpty()) {
missingAttributes(reader.getLocation(), required);
}
requireNoContent(reader);
ejbClientDescriptorMetaData.addHttpConnectionRef(uri);
}
}
| 7,052 | 42.269939 | 168 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EJBClientDescriptor13Parser.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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.ee.structure;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import java.util.EnumSet;
import java.util.Set;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.ee.metadata.EJBClientDescriptorMetaData;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Parser for urn:jboss:ejb-client:1.3:jboss-ejb-client
*
* @author Jaikiran Pai
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
* @author <a href="mailto:[email protected]">Wolf-Dieter Fink</a>
*/
class EJBClientDescriptor13Parser extends EJBClientDescriptor12Parser {
public static final String NAMESPACE_1_3 = "urn:jboss:ejb-client:1.3";
protected EJBClientDescriptor13Parser(final PropertyReplacer propertyReplacer) {
super(propertyReplacer);
}
protected void parseClientContext(final XMLExtendedStreamReader reader,
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader
.getAttributeLocalName(i));
final String value = readResolveValue(reader, i);
switch (attribute) {
case INVOCATION_TIMEOUT:
final Long invocationTimeout = Long.parseLong(value);
ejbClientDescriptorMetaData.setInvocationTimeout(invocationTimeout);
break;
case DEPLOYMENT_NODE_SELECTOR:
final String deploymentNodeSelector = readResolveValue(reader, i);
ejbClientDescriptorMetaData.setDeploymentNodeSelector(deploymentNodeSelector);
break;
default:
unexpectedContent(reader);
}
}
final Set<EJBClientDescriptorXMLElement> visited = EnumSet.noneOf(EJBClientDescriptorXMLElement.class);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
if (visited.contains(element)) {
unexpectedElement(reader);
}
visited.add(element);
switch (element) {
case EJB_RECEIVERS:
this.parseEJBReceivers(reader, ejbClientDescriptorMetaData);
break;
case CLUSTERS:
this.parseClusters(reader, ejbClientDescriptorMetaData);
break;
case PROFILE:
this.parseProfile(reader, ejbClientDescriptorMetaData);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected void parseProfile(final XMLExtendedStreamReader reader,
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
final Set<EJBClientDescriptorXMLAttribute> required = EnumSet.of(EJBClientDescriptorXMLAttribute.NAME);
final int count = reader.getAttributeCount();
String profileName = null;
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader
.getAttributeLocalName(i));
required.remove(attribute);
final String value = readResolveValue(reader, i);
switch (attribute) {
case NAME:
profileName = value;
break;
default:
unexpectedContent(reader);
}
}
if (!required.isEmpty()) {
missingAttributes(reader.getLocation(), required);
}
// add a new node config to the cluster config
ejbClientDescriptorMetaData.setProfile(profileName);
}
}
| 5,656 | 41.533835 | 127 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/AnnotationPropertyReplacementProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.structure;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
/**
* {@link org.jboss.as.server.deployment.DeploymentUnitProcessor} responsible for determining if property replacement should be
* done on Jakarta Enterprise Beans annotations.
*/
public class AnnotationPropertyReplacementProcessor implements DeploymentUnitProcessor {
private volatile boolean annotationPropertyReplacement = false;
private final AttachmentKey<Boolean> attachmentKey;
public AnnotationPropertyReplacementProcessor(final AttachmentKey<Boolean> attachmentKey) {
this.attachmentKey = attachmentKey;
}
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
deploymentUnit.putAttachment(attachmentKey, annotationPropertyReplacement);
}
public void setDescriptorPropertyReplacement(boolean annotationPropertyReplacement) {
this.annotationPropertyReplacement = annotationPropertyReplacement;
}
}
| 2,377 | 41.464286 | 127 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/JBossDescriptorPropertyReplacement.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, 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.ee.structure;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.metadata.property.PropertyReplacers;
/**
* @author Stuart Douglas
*/
public class JBossDescriptorPropertyReplacement {
public static PropertyReplacer propertyReplacer(final DeploymentUnit deploymentUnit) {
Boolean replacement = deploymentUnit.getAttachment(Attachments.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT);
if (replacement == null || replacement) {
PropertyReplacer replacer = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_REPLACER);
// Replacer might be null if the EE subsystem isn't installed (e.g. sar w/o ee) TODO clean up this relationship
return replacer != null ? replacer : PropertyReplacers.noop();
} else {
return PropertyReplacers.noop();
}
}
private JBossDescriptorPropertyReplacement() {
}
}
| 2,038 | 40.612245 | 140 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EJBAnnotationPropertyReplacement.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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.ee.structure;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.metadata.property.PropertyReplacers;
/**
* @author wangchao
*
*/
public class EJBAnnotationPropertyReplacement {
public static PropertyReplacer propertyReplacer(final DeploymentUnit deploymentUnit) {
Boolean replacement = deploymentUnit.getAttachment(Attachments.ANNOTATION_PROPERTY_REPLACEMENT);
if (replacement == null || replacement) {
PropertyReplacer replacer = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_REPLACER);
// Replacer might be null if the EE subsystem isn't installed (e.g. sar w/o ee) TODO clean up this relationship
return replacer != null ? replacer : PropertyReplacers.noop();
} else {
return PropertyReplacers.noop();
}
}
private EJBAnnotationPropertyReplacement() {
}
}
| 2,025 | 39.52 | 140 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EjbJarDeploymentProcessor.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.structure;
import java.util.List;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.SubDeploymentMarker;
import org.jboss.as.server.deployment.module.ModuleRootMarker;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.jboss.vfs.VirtualFile;
/**
* Processor that only runs for ear deployments where no application.xml is provided. It examines jars in the ear to determine
* which are Jakarta Enterprise Beans sub-deployments.
* <p/>
* TODO: Move this to the Jakarta Enterprise Beans subsystem.
*
* @author Stuart Douglas
*/
public class EjbJarDeploymentProcessor implements DeploymentUnitProcessor {
private static final DotName STATELESS = DotName.createSimple("jakarta.ejb.Stateless");
private static final DotName STATEFUL = DotName.createSimple("jakarta.ejb.Stateful");
private static final DotName MESSAGE_DRIVEN = DotName.createSimple("jakarta.ejb.MessageDriven");
private static final DotName SINGLETON = DotName.createSimple("jakarta.ejb.Singleton");
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
//we don't check for the metadata attachment
//cause this could come from a jboss-app.xml instead
if(deploymentRoot.getRoot().getChild("META-INF/application.xml").exists()) {
//if we have an application.xml we don't scan
return;
}
// TODO: deal with application clients, we need the manifest information
List<ResourceRoot> potentialSubDeployments = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : potentialSubDeployments) {
if (ModuleRootMarker.isModuleRoot(resourceRoot)) {
// module roots cannot be ejb jars
continue;
}
VirtualFile ejbJarFile = resourceRoot.getRoot().getChild("META-INF/ejb-jar.xml");
if (ejbJarFile.exists()) {
SubDeploymentMarker.mark(resourceRoot);
ModuleRootMarker.mark(resourceRoot);
} else {
final Index index = resourceRoot.getAttachment(Attachments.ANNOTATION_INDEX);
if (index != null
&& (!index.getAnnotations(STATEFUL).isEmpty() ||
!index.getAnnotations(STATELESS).isEmpty() ||
!index.getAnnotations(MESSAGE_DRIVEN).isEmpty() ||
!index.getAnnotations(SINGLETON).isEmpty())) {
// this is an Jakarta Enterprise Beans deployment
// TODO: we need to mark Jakarta Enterprise Beans sub deployments so the sub deployers know they are Jakarta
// Enterprise Beans deployments
SubDeploymentMarker.mark(resourceRoot);
ModuleRootMarker.mark(resourceRoot);
}
}
}
}
}
| 4,657 | 48.553191 | 133 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/DeploymentType.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.structure;
public enum DeploymentType {
EAR, WAR, EJB_JAR, APPLICATION_CLIENT;
}
| 1,126 | 40.740741 | 73 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EJBClientDescriptorParsingProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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.ee.structure;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.metadata.EJBClientDescriptorMetaData;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.as.server.moduleservice.ServiceModuleLoader;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.staxmapper.XMLMapper;
import org.jboss.vfs.VirtualFile;
/**
* A deployment unit processor which parses jboss-ejb-client.xml in top level deployments.
* If a jboss-ejb-client.xml is found in the top level deployment, then this processor creates a {@link EJBClientDescriptorMetaData}
* out of it and attaches it to the deployment unit at {@link Attachments#EJB_CLIENT_METADATA}
*
* @author Jaikiran Pai
* @author <a href=mailto:[email protected]>Tomasz Adamski</a>
* @author <a href="mailto:[email protected]">Wolf-Dieter Fink</a>
*/
public class EJBClientDescriptorParsingProcessor implements DeploymentUnitProcessor {
public static final String[] EJB_CLIENT_DESCRIPTOR_LOCATIONS = { "META-INF/jboss-ejb-client.xml",
"WEB-INF/jboss-ejb-client.xml" };
private static final QName ROOT_1_0 = new QName(EJBClientDescriptor10Parser.NAMESPACE_1_0, "jboss-ejb-client");
private static final QName ROOT_1_1 = new QName(EJBClientDescriptor11Parser.NAMESPACE_1_1, "jboss-ejb-client");
private static final QName ROOT_1_2 = new QName(EJBClientDescriptor12Parser.NAMESPACE_1_2, "jboss-ejb-client");
private static final QName ROOT_1_3 = new QName(EJBClientDescriptor13Parser.NAMESPACE_1_3, "jboss-ejb-client");
private static final QName ROOT_1_4 = new QName(EJBClientDescriptor14Parser.NAMESPACE_1_4, "jboss-ejb-client");
private static final QName ROOT_1_5 = new QName(EJBClientDescriptor15Parser.NAMESPACE_1_5, "jboss-ejb-client");
private static final QName ROOT_NO_NAMESPACE = new QName("jboss-ejb-client");
private static final XMLInputFactory INPUT_FACTORY = XMLInputFactory.newInstance();
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final XMLMapper mapper = createMapper(deploymentUnit);
final ResourceRoot resourceRoot = deploymentUnit
.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final ServiceModuleLoader moduleLoader = deploymentUnit
.getAttachment(org.jboss.as.server.deployment.Attachments.SERVICE_MODULE_LOADER);
VirtualFile descriptorFile = null;
for (final String loc : EJB_CLIENT_DESCRIPTOR_LOCATIONS) {
final VirtualFile file = resourceRoot.getRoot().getChild(loc);
if (file.exists()) {
descriptorFile = file;
break;
}
}
if (descriptorFile == null) {
return;
}
if (deploymentUnit.getParent() != null) {
EeLogger.ROOT_LOGGER.subdeploymentIgnored(descriptorFile.getPathName());
return;
}
final File ejbClientDeploymentDescriptorFile;
try {
ejbClientDeploymentDescriptorFile = descriptorFile.getPhysicalFile();
} catch (IOException e) {
throw EeLogger.ROOT_LOGGER.failedToProcessEJBClientDescriptor(e);
}
final EJBClientDescriptorMetaData ejbClientDescriptorMetaData = parse(ejbClientDeploymentDescriptorFile, mapper);
EeLogger.ROOT_LOGGER.debugf("Successfully parsed jboss-ejb-client.xml for deployment unit %s", deploymentUnit);
// attach the metadata
deploymentUnit.putAttachment(Attachments.EJB_CLIENT_METADATA, ejbClientDescriptorMetaData);
}
private XMLMapper createMapper(final DeploymentUnit deploymentUnit) {
final XMLMapper mapper = XMLMapper.Factory.create();
final PropertyReplacer propertyReplacer = EjbClientDescriptorPropertyReplacement.propertyReplacer(deploymentUnit);
final EJBClientDescriptor10Parser ejbClientDescriptor10Parser = new EJBClientDescriptor10Parser(propertyReplacer);
mapper.registerRootElement(ROOT_1_0, ejbClientDescriptor10Parser);
final EJBClientDescriptor11Parser ejbClientDescriptor11Parser = new EJBClientDescriptor11Parser(propertyReplacer);
mapper.registerRootElement(ROOT_1_1, ejbClientDescriptor11Parser);
final EJBClientDescriptor11Parser ejbClientDescriptor12Parser = new EJBClientDescriptor12Parser(propertyReplacer);
mapper.registerRootElement(ROOT_1_2, ejbClientDescriptor12Parser);
final EJBClientDescriptor13Parser ejbClientDescriptor13Parser = new EJBClientDescriptor13Parser(propertyReplacer);
mapper.registerRootElement(ROOT_1_3, ejbClientDescriptor13Parser);
final EJBClientDescriptor14Parser ejbClientDescriptor14Parser = new EJBClientDescriptor14Parser(propertyReplacer);
mapper.registerRootElement(ROOT_1_4, ejbClientDescriptor14Parser);
final EJBClientDescriptor15Parser ejbClientDescriptor15Parser = new EJBClientDescriptor15Parser(propertyReplacer);
mapper.registerRootElement(ROOT_1_5, ejbClientDescriptor15Parser);
mapper.registerRootElement(ROOT_NO_NAMESPACE, ejbClientDescriptor15Parser);
return mapper;
}
private EJBClientDescriptorMetaData parse(final File file, final XMLMapper mapper) throws DeploymentUnitProcessingException {
final FileInputStream fis;
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
throw EeLogger.ROOT_LOGGER.failedToProcessEJBClientDescriptor(e);
}
try {
return parse(fis, file, mapper);
} finally {
safeClose(fis);
}
}
private EJBClientDescriptorMetaData parse(final InputStream source, final File file, final XMLMapper mapper)
throws DeploymentUnitProcessingException {
try {
final XMLInputFactory inputFactory = INPUT_FACTORY;
setIfSupported(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
setIfSupported(inputFactory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
final XMLStreamReader streamReader = inputFactory.createXMLStreamReader(source);
try {
final EJBClientDescriptorMetaData result = new EJBClientDescriptorMetaData();
mapper.parseDocument(result, streamReader);
return result;
} finally {
safeClose(streamReader);
}
} catch (XMLStreamException e) {
throw EeLogger.ROOT_LOGGER.xmlErrorParsingEJBClientDescriptor(e, file.getAbsolutePath());
}
}
private void setIfSupported(final XMLInputFactory inputFactory, final String property, final Object value) {
if (inputFactory.isPropertySupported(property)) {
inputFactory.setProperty(property, value);
}
}
private static void safeClose(final Closeable closeable) {
if (closeable != null)
try {
closeable.close();
} catch (IOException e) {
// ignore
}
}
private static void safeClose(final XMLStreamReader streamReader) {
if (streamReader != null)
try {
streamReader.close();
} catch (XMLStreamException e) {
// ignore
}
}
}
| 9,075 | 47.276596 | 132 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EJBClientDescriptor10Parser.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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.ee.structure;
import static javax.xml.stream.XMLStreamConstants.ATTRIBUTE;
import static javax.xml.stream.XMLStreamConstants.CDATA;
import static javax.xml.stream.XMLStreamConstants.CHARACTERS;
import static javax.xml.stream.XMLStreamConstants.COMMENT;
import static javax.xml.stream.XMLStreamConstants.DTD;
import static javax.xml.stream.XMLStreamConstants.END_DOCUMENT;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.ENTITY_DECLARATION;
import static javax.xml.stream.XMLStreamConstants.ENTITY_REFERENCE;
import static javax.xml.stream.XMLStreamConstants.NAMESPACE;
import static javax.xml.stream.XMLStreamConstants.NOTATION_DECLARATION;
import static javax.xml.stream.XMLStreamConstants.PROCESSING_INSTRUCTION;
import static javax.xml.stream.XMLStreamConstants.SPACE;
import static javax.xml.stream.XMLStreamConstants.START_DOCUMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import java.util.EnumSet;
import java.util.Set;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.metadata.EJBClientDescriptorMetaData;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Parser for urn:jboss:ejb-client:1.0:jboss-ejb-client
*
* @author Jaikiran Pai
* @author <a href="mailto:[email protected]">Tomasz Adamski</a>
* @author <a href="mailto:[email protected]">Wolf-Dieter Fink</a>
*/
class EJBClientDescriptor10Parser implements XMLElementReader<EJBClientDescriptorMetaData> {
public static final String NAMESPACE_1_0 = "urn:jboss:ejb-client:1.0";
protected final PropertyReplacer propertyReplacer;
protected EJBClientDescriptor10Parser(final PropertyReplacer propertyReplacer) {
this.propertyReplacer = propertyReplacer;
}
@Override
public void readElement(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case CLIENT_CONTEXT:
this.parseClientContext(reader, ejbClientDescriptorMetaData);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected void parseClientContext(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
final Set<EJBClientDescriptorXMLElement> visited = EnumSet.noneOf(EJBClientDescriptorXMLElement.class);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
if (visited.contains(element)) {
unexpectedElement(reader);
}
visited.add(element);
switch (element) {
case EJB_RECEIVERS:
this.parseEJBReceivers(reader, ejbClientDescriptorMetaData);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected void parseEJBReceivers(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
// initialize the local-receiver-pass-by-value to the default null - to indicate it has not been initialized via XML
// check for 'true' - localReceiverPassByValue != Boolean.FALSE
Boolean localReceiverPassByValue = null;
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader.getAttributeLocalName(i));
final String value = readResolveValue(reader, i);
switch (attribute) {
case EXCLUDE_LOCAL_RECEIVER:
final boolean excludeLocalReceiver = Boolean.parseBoolean(value);
ejbClientDescriptorMetaData.setExcludeLocalReceiver(excludeLocalReceiver);
break;
case LOCAL_RECEIVER_PASS_BY_VALUE:
localReceiverPassByValue = Boolean.parseBoolean(value);
break;
default:
unexpectedContent(reader);
}
}
// set the local receiver pass by value into the metadata
ejbClientDescriptorMetaData.setLocalReceiverPassByValue(localReceiverPassByValue != Boolean.FALSE);
while (reader.hasNext()) {
switch (reader.nextTag()) {
case END_ELEMENT: {
return;
}
case START_ELEMENT: {
final EJBClientDescriptorXMLElement element = EJBClientDescriptorXMLElement.forName(reader.getLocalName());
switch (element) {
case REMOTING_EJB_RECEIVER:
this.parseRemotingReceiver(reader, ejbClientDescriptorMetaData);
break;
default:
unexpectedElement(reader);
}
break;
}
default: {
unexpectedContent(reader);
}
}
}
unexpectedEndOfDocument(reader.getLocation());
}
protected void parseRemotingReceiver(final XMLExtendedStreamReader reader, final EJBClientDescriptorMetaData ejbClientDescriptorMetaData) throws XMLStreamException {
String outboundConnectionRef = null;
final Set<EJBClientDescriptorXMLAttribute> required = EnumSet.of(EJBClientDescriptorXMLAttribute.OUTBOUND_CONNECTION_REF);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
final EJBClientDescriptorXMLAttribute attribute = EJBClientDescriptorXMLAttribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case OUTBOUND_CONNECTION_REF:
outboundConnectionRef = readResolveValue(reader, i);
ejbClientDescriptorMetaData.addRemotingReceiverConnectionRef(outboundConnectionRef);
break;
default:
unexpectedContent(reader);
}
}
if (!required.isEmpty()) {
missingAttributes(reader.getLocation(), required);
}
// This element is just composed of attributes which we already processed, so no more content
// is expected
if (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
unexpectedContent(reader);
}
}
protected static void unexpectedEndOfDocument(final Location location) throws XMLStreamException {
throw EeLogger.ROOT_LOGGER.errorParsingEJBClientDescriptor("Unexpected end of document", location);
}
protected static void missingAttributes(final Location location, final Set<EJBClientDescriptorXMLAttribute> required) throws XMLStreamException {
final StringBuilder b = new StringBuilder("Missing one or more required attributes:");
for (EJBClientDescriptorXMLAttribute attribute : required) {
b.append(' ').append(attribute);
}
throw EeLogger.ROOT_LOGGER.errorParsingEJBClientDescriptor(b.toString(), location);
}
/**
* Throws a XMLStreamException for the unexpected element that was encountered during the parse
*
* @param reader the stream reader
* @throws XMLStreamException
*/
protected static void unexpectedElement(final XMLExtendedStreamReader reader) throws XMLStreamException {
throw EeLogger.ROOT_LOGGER.unexpectedElement(reader.getName(), reader.getLocation());
}
protected static void unexpectedContent(final XMLStreamReader reader) throws XMLStreamException {
final String kind;
switch (reader.getEventType()) {
case ATTRIBUTE:
kind = "attribute";
break;
case CDATA:
kind = "cdata";
break;
case CHARACTERS:
kind = "characters";
break;
case COMMENT:
kind = "comment";
break;
case DTD:
kind = "dtd";
break;
case END_DOCUMENT:
kind = "document end";
break;
case END_ELEMENT:
kind = "element end";
break;
case ENTITY_DECLARATION:
kind = "entity declaration";
break;
case ENTITY_REFERENCE:
kind = "entity ref";
break;
case NAMESPACE:
kind = "namespace";
break;
case NOTATION_DECLARATION:
kind = "notation declaration";
break;
case PROCESSING_INSTRUCTION:
kind = "processing instruction";
break;
case SPACE:
kind = "whitespace";
break;
case START_DOCUMENT:
kind = "document start";
break;
case START_ELEMENT:
kind = "element start";
break;
default:
kind = "unknown";
break;
}
final StringBuilder b = new StringBuilder("Unexpected content of type '").append(kind).append('\'');
if (reader.hasName()) {
b.append(" named '").append(reader.getName()).append('\'');
}
if (reader.hasText()) {
b.append(", text is: '").append(reader.getText()).append('\'');
}
throw EeLogger.ROOT_LOGGER.errorParsingEJBClientDescriptor(b.toString(), reader.getLocation());
}
protected String readResolveValue(final XMLExtendedStreamReader reader, final int index) {
return propertyReplacer.replaceProperties(reader.getAttributeValue(index).trim());
}
}
| 12,406 | 41.489726 | 169 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/DescriptorPropertyReplacementProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, 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.ee.structure;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
/**
* {@link org.jboss.as.server.deployment.DeploymentUnitProcessor} responsible for determining if
* property replacement should be done on EE spec descriptors.
*
*/
public class DescriptorPropertyReplacementProcessor implements DeploymentUnitProcessor {
private volatile boolean descriptorPropertyReplacement = true;
private final AttachmentKey<Boolean> attachmentKey;
public DescriptorPropertyReplacementProcessor(final AttachmentKey<Boolean> attachmentKey) {
this.attachmentKey = attachmentKey;
}
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
deploymentUnit.putAttachment(attachmentKey, descriptorPropertyReplacement);
}
public void setDescriptorPropertyReplacement(boolean descriptorPropertyReplacement) {
this.descriptorPropertyReplacement = descriptorPropertyReplacement;
}
}
| 2,363 | 39.758621 | 102 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/SpecDescriptorPropertyReplacement.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, 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.ee.structure;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.metadata.property.PropertyReplacers;
/**
* @author Stuart Douglas
*/
public class SpecDescriptorPropertyReplacement {
public static PropertyReplacer propertyReplacer(final DeploymentUnit deploymentUnit) {
Boolean replacement = deploymentUnit.getAttachment(Attachments.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT);
if (replacement == null || replacement) {
PropertyReplacer replacer = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_REPLACER);
// Replacer might be null if the EE subsystem isn't installed (e.g. sar w/o ee) TODO clean up this relationship
return replacer != null ? replacer : PropertyReplacers.noop();
} else {
return PropertyReplacers.noop();
}
}
private SpecDescriptorPropertyReplacement() {
}
}
| 2,035 | 40.55102 | 140 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/EjbClientDescriptorPropertyReplacement.java | package org.jboss.as.ee.structure;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.metadata.property.PropertyReplacer;
import org.jboss.metadata.property.PropertyReplacers;
/**
* @author <a href=mailto:[email protected]>Tomasz Adamski</a>
*/
public class EjbClientDescriptorPropertyReplacement {
public static PropertyReplacer propertyReplacer(final DeploymentUnit deploymentUnit) {
Boolean replacement = deploymentUnit.getAttachment(Attachments.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT);
if (replacement == null || replacement) {
PropertyReplacer replacer = deploymentUnit
.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_REPLACER);
return replacer != null ? replacer : PropertyReplacers.noop();
} else {
return PropertyReplacers.noop();
}
}
private EjbClientDescriptorPropertyReplacement() {
}
}
| 957 | 35.846154 | 110 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/ComponentAggregationProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, 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.ee.structure;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.ComponentRegistry;
import org.jboss.as.ee.component.EEApplicationDescription;
import org.jboss.as.ee.component.EEClassIntrospector;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StopContext;
import java.util.List;
import java.util.Map;
import static org.jboss.as.ee.component.Attachments.*;
import static org.jboss.as.server.deployment.Attachments.SUB_DEPLOYMENTS;
/**
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
* @author Stuart Douglas
*/
public final class ComponentAggregationProcessor implements DeploymentUnitProcessor {
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ComponentRegistry componentRegistry = new ComponentRegistry(phaseContext.getServiceRegistry());
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
if(moduleDescription == null) {
return;
}
final ServiceName sn = ComponentRegistry.serviceName(deploymentUnit);
final ServiceBuilder<?> sb = phaseContext.getServiceTarget().addService(sn);
sb.setInstance(new ValueService(componentRegistry));
sb.addDependency(moduleDescription.getDefaultClassIntrospectorServiceName(), EEClassIntrospector.class, componentRegistry.getClassIntrospectorInjectedValue()).install();
deploymentUnit.putAttachment(COMPONENT_REGISTRY, componentRegistry);
if (deploymentUnit.getAttachment(Attachments.DEPLOYMENT_TYPE) == DeploymentType.EAR) {
final EEApplicationDescription applicationDescription = new EEApplicationDescription();
deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION, applicationDescription);
for (final Map.Entry<String, String> messageDestination : moduleDescription.getMessageDestinations().entrySet()) {
applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT).getRoot());
}
/*
* We are an EAR, so we must inspect all of our subdeployments and aggregate all their component views
* into a single index, so that inter-module resolution will work.
*/
// Add the application description
final List<DeploymentUnit> subdeployments = deploymentUnit.getAttachmentList(SUB_DEPLOYMENTS);
for (final DeploymentUnit subdeployment : subdeployments) {
final EEModuleDescription subDeploymentModuleDescription = subdeployment.getAttachment(EE_MODULE_DESCRIPTION);
final ResourceRoot deploymentRoot = subdeployment.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
if (subDeploymentModuleDescription == null) {
// Not an EE deployment.
continue;
}
for (final ComponentDescription componentDescription : subDeploymentModuleDescription.getComponentDescriptions()) {
applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
}
for (final Map.Entry<String, String> messageDestination : subDeploymentModuleDescription.getMessageDestinations().entrySet()) {
applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentRoot.getRoot());
}
for (final ComponentDescription componentDescription : subdeployment.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
}
subdeployment.putAttachment(EE_APPLICATION_DESCRIPTION, applicationDescription);
}
} else if (deploymentUnit.getParent() == null) {
final EEApplicationDescription applicationDescription = new EEApplicationDescription();
deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_DESCRIPTION, applicationDescription);
/*
* We are a top-level EE deployment, or a non-EE deployment. Our "aggregate" index is just a copy of
* our local EE module index.
*/
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
}
for (final Map.Entry<String, String> messageDestination : moduleDescription.getMessageDestinations().entrySet()) {
applicationDescription.addMessageDestination(messageDestination.getKey(), messageDestination.getValue(), deploymentRoot.getRoot());
}
for (final ComponentDescription componentDescription : deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
applicationDescription.addComponent(componentDescription, deploymentRoot.getRoot());
}
}
}
private static final class ValueService implements Service<ComponentRegistry> {
private final ComponentRegistry value;
public ValueService(final ComponentRegistry value) {
this.value = value;
}
public void start(final StartContext context) {
// noop
}
public void stop(final StopContext context) {
// noop
}
public ComponentRegistry getValue() {
return value;
}
}
}
| 7,662 | 51.848276 | 221 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/structure/GlobalDirectoryDependencyProcessor.java | /*
* Copyright 2019 Red Hat, Inc.
*
* 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.jboss.as.ee.structure;
import static org.jboss.as.ee.subsystem.EeCapabilities.EE_GLOBAL_DIRECTORY_CAPABILITY_NAME;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ee.subsystem.GlobalDirectoryDeploymentService;
import org.jboss.as.ee.subsystem.GlobalDirectoryResourceDefinition;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DelegatingSupplier;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.module.ModuleSpecification;
import org.jboss.as.server.moduleservice.ExternalModule;
import org.jboss.modules.ModuleLoader;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
/**
* A deployment processor that prepares the global directories that are going to be used as dependencies in a deployment.
* <p>
* It finds which services were installed under ee/global-directory resource using its capability name and installs a
* {@link GlobalDirectoryDeploymentService} to consume the supplied GlobalDirectory values.
* <p>
* This deployment processor ensures that the {@link GlobalDirectoryDeploymentService} installed for this deployment is up before moving
* to the next phase.
*
* @author Yeray Borges
*/
public class GlobalDirectoryDependencyProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ServiceName depUnitServiceName = deploymentUnit.getServiceName();
final DeploymentUnit parent = deploymentUnit.getParent();
final DeploymentUnit topLevelDeployment = parent == null ? deploymentUnit : parent;
final ExternalModule externalModuleService = topLevelDeployment.getAttachment(Attachments.EXTERNAL_MODULE_SERVICE);
final ModuleLoader moduleLoader = deploymentUnit.getAttachment(Attachments.SERVICE_MODULE_LOADER);
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
final CapabilityServiceSupport capabilitySupport = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
final ServiceRegistry serviceRegistry = phaseContext.getServiceRegistry();
final ServiceTarget target = phaseContext.getServiceTarget();
final ServiceTarget externalServiceTarget = deploymentUnit.getAttachment(Attachments.EXTERNAL_SERVICE_TARGET);
final ServiceName allDirReadyServiceName = depUnitServiceName.append("directory-services-ready");
final ServiceBuilder<?> allDirReadyServiceBuilder = target.addService(allDirReadyServiceName);
final List<Supplier<GlobalDirectoryResourceDefinition.GlobalDirectory>> allDirReadySuppliers = new ArrayList<>();
final ServiceName csName = capabilitySupport.getCapabilityServiceName(EE_GLOBAL_DIRECTORY_CAPABILITY_NAME);
List<ServiceName> serviceNames = serviceRegistry.getServiceNames();
for (ServiceName serviceName : serviceNames) {
if (csName.isParentOf(serviceName)) {
Supplier<GlobalDirectoryResourceDefinition.GlobalDirectory> pathRequirement = allDirReadyServiceBuilder.requires(serviceName);
allDirReadySuppliers.add(pathRequirement);
}
}
if (!allDirReadySuppliers.isEmpty()) {
GlobalDirectoryDeploymentService globalDirDepService = new GlobalDirectoryDeploymentService(allDirReadySuppliers, externalModuleService, moduleSpecification, moduleLoader, serviceRegistry, externalServiceTarget);
allDirReadyServiceBuilder.requires(phaseContext.getPhaseServiceName());
allDirReadyServiceBuilder.setInstance(globalDirDepService)
.install();
phaseContext.requires(allDirReadyServiceName, new DelegatingSupplier());
}
}
@Override
public void undeploy(DeploymentUnit deploymentUnit) {
ServiceController<?> requiredService = deploymentUnit.getServiceRegistry().getService(deploymentUnit.getServiceName().append("directory-services-ready"));
if (requiredService != null) {
requiredService.setMode(ServiceController.Mode.REMOVE);
}
}
}
| 5,360 | 50.548077 | 224 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/logging/EeLogger.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, 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.ee.logging;
import static org.jboss.logging.Logger.Level.ERROR;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.WARN;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.RejectedExecutionException;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.ee.component.BindingConfiguration;
import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentInstance;
import org.jboss.as.ee.component.ComponentIsStoppedException;
import org.jboss.as.ee.component.InjectionSource;
import org.jboss.as.ee.concurrent.ConcurrentContext;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.invocation.proxy.MethodIdentifier;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.Cause;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.logging.annotations.Param;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartException;
import org.jboss.vfs.VirtualFile;
/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
@MessageLogger(projectCode = "WFLYEE", length = 4)
public interface EeLogger extends BasicLogger {
/**
* A logger with a category of the package name.
*/
EeLogger ROOT_LOGGER = Logger.getMessageLogger(EeLogger.class, "org.jboss.as.ee");
// /**
// * Logs a warning message indicating the transaction datasource, represented by the {@code className} parameter,
// * could not be proxied and will not be enlisted in the transactions automatically.
// *
// * @param cause the cause of the error.
// * @param className the datasource class name.
// */
// @LogMessage(level = WARN)
// @Message(id = 1, value = "Transactional datasource %s could not be proxied and will not be enlisted in transactions automatically")
// void cannotProxyTransactionalDatasource(@Cause Throwable cause, String className);
/**
* Logs a warning message indicating the resource-env-ref could not be resolved.
*
* @param elementName the name of the element.
* @param name the name resource environment reference.
*/
@LogMessage(level = WARN)
@Message(id = 2, value = "Could not resolve %s %s")
void cannotResolve(String elementName, String name);
// /**
// * Logs a warning message indicating the class path entry, represented by the {@code entry} parameter, was not found
// * in the file.
// *
// * @param entry the class path entry.
// * @param file the file.
// */
// @LogMessage(level = WARN)
// @Message(id = 3, value = "Class Path entry %s in %s does not point to a valid jar for a Class-Path reference.")
// void classPathEntryNotAJar(String entry, VirtualFile file);
// /**
// * Logs a warning message indicating the class path entry in file may not point to a sub deployment.
// *
// * @param file the file.
// */
// @LogMessage(level = WARN)
// @Message(id = 4, value = "Class Path entry in %s may not point to a sub deployment.")
// void classPathEntryASubDeployment(VirtualFile file);
// /**
// * Logs a warning message indicating the class path entry, represented by the {@code entry} parameter, was not found
// * in the file.
// *
// * @param entry the class path entry.
// * @param file the file.
// */
// @LogMessage(level = WARN)
// @Message(id = 5, value = "Class Path entry %s in %s not found.")
// void classPathEntryNotFound(String entry, VirtualFile file);
/**
* Logs a warning message indicating a failure to destroy the component instance.
*
* @param cause the cause of the error.
* @param component the component instance.
*/
@LogMessage(level = WARN)
@Message(id = 6, value = "Failed to destroy component instance %s")
void componentDestroyFailure(@Cause Throwable cause, ComponentInstance component);
/**
* Logs a warning message indicating the component is not being installed due to an exception.
*
* @param name the name of the component.
*/
@LogMessage(level = WARN)
@Message(id = 7, value = "Not installing optional component %s due to an exception (enable DEBUG log level to see the cause)")
void componentInstallationFailure(String name);
// /**
// * Logs a warning message indicating the property, represented by the {@code name} parameter, is be ignored due to
// * missing on the setter method on the datasource class.
// *
// * @param name the name of the property.
// * @param methodName the name of the method.
// * @param parameterType the name of the parameter type.
// * @param className the name of the datasource class.
// */
// @LogMessage(level = WARN)
// @Message(id = 8, value = "Ignoring property %s due to missing setter method: %s(%s) on datasource class: %s")
// void ignoringProperty(String name, String methodName, String parameterType, String className);
/**
* Logs a warning message indicating the managed bean implementation class MUST NOT be an interface.
*
* @param sectionId the section id of the managed bean spec.
* @param className the class name
*/
@LogMessage(level = WARN)
@Message(id = 9, value = "[Managed Bean spec, section %s] Managed bean implementation class MUST NOT be an interface - " +
"%s is an interface, hence won't be considered as a managed bean.")
void invalidManagedBeanAbstractOrFinal(String sectionId, String className);
/**
* Logs a warning message indicating the managed bean implementation class MUST NOT be abstract or final.
*
* @param sectionId the section id of the managed bean spec.
* @param className the class name
*/
@LogMessage(level = WARN)
@Message(id = 10, value = "[Managed Bean spec, section %s] Managed bean implementation class MUST NOT be abstract or final - " +
"%s won't be considered as a managed bean, since it doesn't meet that requirement.")
void invalidManagedBeanInterface(String sectionId, String className);
/**
* Logs a warning message indicating an exception occurred while invoking the pre-destroy on the interceptor
* component class, represented by the {@code component} parameter.
*
* @param cause the cause of the error.
* @param component the component.
*/
@LogMessage(level = WARN)
@Message(id = 11, value = "Exception while invoking pre-destroy interceptor for component class: %s")
void preDestroyInterceptorFailure(@Cause Throwable cause, Class<?> component);
// /**
// * Logs a warning message indicating the transaction datasource, represented by the {@code className} parameter,
// * will not be enlisted in the transaction as the transaction subsystem is not available.
// *
// * @param className the name of the datasource class.
// */
// @LogMessage(level = WARN)
// @Message(id = 12, value = "Transactional datasource %s will not be enlisted in the transaction as the transaction subsystem is not available")
// void transactionSubsystemNotAvailable(String className);
//@Message(id = 13, value = "Injection for a member with static modifier is only acceptable on application clients, ignoring injection for target %s")
//void ignoringStaticInjectionTarget(InjectionTarget injectionTarget);
@LogMessage(level = WARN)
@Message(id = 14, value = "%s in subdeployment ignored. jboss-ejb-client.xml is only parsed for top level deployments.")
void subdeploymentIgnored(String pathName);
@LogMessage(level = WARN)
@Message(id = 15, value = "Transaction started in EE Concurrent invocation left open, starting rollback to prevent leak.")
void rollbackOfTransactionStartedInEEConcurrentInvocation();
@LogMessage(level = WARN)
@Message(id = 16, value = "Failed to rollback transaction.")
void failedToRollbackTransaction(@Cause Throwable cause);
@LogMessage(level = WARN)
@Message(id = 17, value = "Failed to suspend transaction.")
void failedToSuspendTransaction(@Cause Throwable cause);
@LogMessage(level = WARN)
@Message(id = 18, value = "System error while checking for transaction leak in EE Concurrent invocation.")
void systemErrorWhileCheckingForTransactionLeak(@Cause Throwable cause);
/**
* Creates an exception indicating the alternate deployment descriptor specified for the module file could not be
* found.
*
* @param deploymentDescriptor the alternate deployment descriptor.
* @param moduleFile the module file.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 19, value = "Could not find alternate deployment descriptor %s specified for %s")
DeploymentUnitProcessingException alternateDeploymentDescriptor(VirtualFile deploymentDescriptor, VirtualFile moduleFile);
/**
* Creates an exception indicating the annotation must provide the attribute.
*
* @param annotation the annotation.
* @param attribute the attribute.
*
* @return an {@link IllegalArgumentException} for the exception.
*/
@Message(id = 20, value = "%s annotations must provide a %s.")
IllegalArgumentException annotationAttributeMissing(String annotation, String attribute);
/**
* Creates an exception indicating more items cannot be added once getSortedItems() has been called.
*
* @return an {@link IllegalStateException} for the error.
*/
@Message(id = 21, value = "Cannot add any more items once getSortedItems() has been called")
IllegalStateException cannotAddMoreItems();
/**
* Creates an exception indicating the {@code name} cannot be empty.
*
* @param name the name that cannot be empty.
*
* @return a {@link RuntimeException} for the error.
*/
@Message(id = 22, value = "%s may not be empty")
RuntimeException cannotBeEmpty(String name);
/**
* Creates an exception indicating the {@code name} cannot be {@code null} or empty.
*
* @param name the name that cannot be empty.
* @param value the value of the object.
*
* @return a {@link IllegalArgumentException} for the error.
*/
@Message(id = 23, value = "%s cannot be null or empty: %s")
IllegalArgumentException cannotBeNullOrEmpty(String name, Object value);
/**
* Creates an exception indicating the component, represented by the {@code name} parameter, could not be
* configured.
*
* @param cause the cause of the error.
* @param name the name of the component.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 24, value = "Could not configure component %s")
DeploymentUnitProcessingException cannotConfigureComponent(@Cause Throwable cause, String name);
/**
* Creates an exception indicating the type for the resource-env-ref could not be determined.
*
* @param name the name of the of the resource environment reference.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 25, value = "Could not determine type for resource-env-ref %s")
DeploymentUnitProcessingException cannotDetermineType(String name);
/**
* Creates an exception indicating the type for the {@code tag} could not be determined.
*
* @param tag the tag name.
* @param value the value of the tag.
* @param typeTag the type tag.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 26, value = "Could not determine type for %s %s please specify the %s.")
DeploymentUnitProcessingException cannotDetermineType(String tag, String value, String typeTag);
/**
* Creates an exception indicating the injection target referenced in the env-entry injection point could not be
* loaded.
*
* @param injectionTarget the injection target.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 27, value = "Could not load %s referenced in env-entry")
DeploymentUnitProcessingException cannotLoad(String injectionTarget);
/**
* Creates an exception indicating the injection target referenced in the env-entry injection point could not be
* loaded.
*
* @param cause the cause of the error.
* @param injectionTarget the injection target.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
DeploymentUnitProcessingException cannotLoad(@Cause Throwable cause, String injectionTarget);
/**
* Creates an exception indicating an interceptor class could not be loaded.
*
* @param cause the cause of the error.
* @param className the name of the interceptor class.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 28, value = "Could not load interceptor class %s")
RuntimeException cannotLoadInterceptor(@Cause Throwable cause, String className);
/**
* Creates an exception indicating an interceptor class could not be loaded on the component.
*
* @param cause the cause of the error.
* @param className the name of the interceptor class.
* @param component the component.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 29, value = "Could not load interceptor class %s on component %s")
DeploymentUnitProcessingException cannotLoadInterceptor(@Cause Throwable cause, String className, Class<?> component);
/**
* Creates an exception indicating the view class, represented by the {@code className} parameter, for the
* component.
*
* @param cause the cause of the error.
* @param className the name of the class.
* @param component the component.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 30, value = "Could not load view class %s for component %s")
DeploymentUnitProcessingException cannotLoadViewClass(@Cause Throwable cause, String className, ComponentConfiguration component);
/**
* Creates an exception indicating the inability to process modules in the application.xml for the EAR, represented
* by the {@code earFile} parameter, module file was not found.
*
* @param earFile the EAR file.
* @param moduleFile the module file.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 31, value = "Unable to process modules in application.xml for EAR [%s], module file %s not found")
DeploymentUnitProcessingException cannotProcessEarModule(VirtualFile earFile, String moduleFile);
/**
* Creates an exception indicating the inability to parse the resource-ref URI.
*
* @param cause the cause of the error.
* @param uri the URI.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 32, value = "Unable to parse resource-ref URI: %s")
DeploymentUnitProcessingException cannotParseResourceRefUri(@Cause Throwable cause, String uri);
/**
* Creates an exception indicating the injection point could not be resolved on the class specified in the web.xml.
*
* @param targetName the injection point name.
* @param className the class name.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 33, value = "Could not resolve injection point %s on class %s specified in web.xml")
DeploymentUnitProcessingException cannotResolveInjectionPoint(String targetName, String className);
/**
* Creates an exception indicating the method could not be found on the class with the annotations.
*
* @param method the method.
* @param component the class.
* @param annotations the annotations.
*
* @return a {@link RuntimeException} for the error.
*/
@Message(id = 34, value = "Could not resolve method %s on class %s with annotations %s")
RuntimeException cannotResolveMethod(MethodIdentifier method, Class<?> component, Collection<?> annotations);
// /**
// * Creates an exception indicating the property, represented by the {@code name} parameter, could not be set on the
// * datasource class, represented by the {@code className} parameter.
// *
// * @param cause the cause of the error.
// * @param name the name of the property.
// * @param className the datasource class name.
// *
// * @return a {@link RuntimeException} for the error.
// */
// @Message(id = 35, value = "Could not set property %s on datasource class %s")
// RuntimeException cannotSetProperty(@Cause Throwable cause, String name, String className);
/**
* Creates an exception indicating both the {@code element1} and {@code element2} cannot be specified in an
* environment entry.
*
* @param element1 the first element.
* @param element2 the second element.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 36, value = "Cannot specify both a %s and a %s in an environment entry.")
DeploymentUnitProcessingException cannotSpecifyBoth(String element1, String element2);
/**
* Creates an exception indicating a circular dependency is installing.
*
* @param bindingName the binding name.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 37, value = "Circular dependency installing %s")
IllegalArgumentException circularDependency(String bindingName);
/**
* Creates an exception indicating the annotation is only allowed on a class.
*
* @param annotation the annotation.
* @param target the annotation target.
*
* @return an {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 38, value = "%s annotation is only allowed on a class. %s is not a class.")
DeploymentUnitProcessingException classOnlyAnnotation(String annotation, AnnotationTarget target);
// /**
// * Creates an exception indicating the annotation is only allowed on method or class targets.
// *
// * @param annotation the annotation.
// *
// * @return an {@link DeploymentUnitProcessingException} for the error.
// */
// @Message(id = 39, value = "@%s annotation is only allowed on methods and classes")
// DeploymentUnitProcessingException classOrMethodOnlyAnnotation(DotName annotation);
/**
* Creates an exception indicating a component, represented by the {@code name} parameter, is already defined in
* this module.
*
* @param name the name of the module.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 40, value = "Component '%s' in class '%s' is already defined in class '%s'")
IllegalArgumentException componentAlreadyDefined(String commonName, String addedClassName, String existingClassname);
/**
* Creates an exception indicating the component class, represented by the {@code className} parameter, for the
* component, represented by the {@code componentName} parameter, has errors.
*
* @param className the class name.
* @param componentName the name of the component.
* @param errorMsg the error message.
*
* @return an {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 41, value = "Component class %s for component %s has errors: %n%s")
DeploymentUnitProcessingException componentClassHasErrors(String className, String componentName, String errorMsg);
/**
* Creates an exception indicating a failure to construct a component instance.
*
* @param cause the cause of the error.
*
* @return an {@link IllegalStateException} for the error.
*/
@Message(id = 42, value = "Failed to construct component instance")
IllegalStateException componentConstructionFailure(@Cause Throwable cause);
/**
* Creates an exception indicating the component is stopped.
*
* @return an {@link IllegalStateException} for the error.
*/
@Message(id = 43, value = "Component is stopped")
ComponentIsStoppedException componentIsStopped();
/**
* Creates an exception indicating the component is not available.
*
* @return an {@link IllegalStateException} for the error.
*/
@Message(id = 44, value = "Component not available (interrupted)")
IllegalStateException componentNotAvailable();
/**
* Creates an exception indicating no component was found for the type.
*
* @param typeName the name of the component.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 45, value = "No component found for type '%s'")
DeploymentUnitProcessingException componentNotFound(String typeName);
/**
* Creates an exception indicating a failure to construct a component view.
*
* @param cause the cause of the error.
*
* @return an {@link IllegalStateException} for the error.
*/
@Message(id = 46, value = "Failed to instantiate component view")
IllegalStateException componentViewConstructionFailure(@Cause Throwable cause);
/**
* Creates an exception indicating an incompatible conflicting binding.
*
* @param bindingName the binding name.
* @param source the source.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 47, value = "Incompatible conflicting binding at %s source: %s")
IllegalArgumentException conflictingBinding(String bindingName, InjectionSource source);
/**
* Creates an exception indicating the default constructor for the class, represented by the {@code clazz}
* parameter, could not be found.
*
* @param clazz the class.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 48, value = "Could not find default constructor for %s")
DeploymentUnitProcessingException defaultConstructorNotFound(Class<?> clazz);
// /**
// * Creates an exception indicating the default constructor for the class, represented by the {@code className}
// * parameter, could not be found.
// *
// * @param annotation the annotation.
// * @param className the name of the class.
// *
// * @return a {@link DeploymentUnitProcessingException} for the error.
// */
// @Message(id = 49, value = "Could not find default constructor for %s class %s")
// DeploymentUnitProcessingException defaultConstructorNotFound(String annotation, String className);
/**
* Creates an exception indicating the default constructor for the class, represented by the {@code className}
* parameter, could not be found on the component.
*
* @param className the name of the class.
* @param component the component name.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 50, value = "No default constructor for interceptor class %s on component %s")
DeploymentUnitProcessingException defaultConstructorNotFoundOnComponent(String className, Class<?> component);
/**
* Creates an exception indicating the element must provide the attribute.
*
* @param element the element.
* @param attribute the attribute.
*
* @return an {@link IllegalArgumentException} for the exception.
*/
@Message(id = 51, value = "%s elements must provide a %s.")
IllegalArgumentException elementAttributeMissing(String element, String attribute);
/**
* Creates an exception indicating a failure to install the component.
*
* @param cause the cause of the error.
* @param name the name of the component.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 52, value = "Failed to install component %s")
DeploymentUnitProcessingException failedToInstallComponent(@Cause Throwable cause, String name);
/**
* Creates an exception indicating a failure to parse the {@code xmlFile}.
*
* @param cause the cause of the error.
* @param xmlFile the XML file.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 53, value = "Failed to parse %s")
DeploymentUnitProcessingException failedToParse(@Cause Throwable cause, VirtualFile xmlFile);
/**
* Creates an exception indicating a failure to process the children for the EAR.
*
* @param cause the cause of the error.
* @param earFile the EAR file.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 54, value = "Failed to process children for EAR [%s]")
DeploymentUnitProcessingException failedToProcessChild(@Cause Throwable cause, VirtualFile earFile);
/**
* A message indicating a failure to read the entries in the application.
*
* @param entryName the name of the entry.
* @param appName the application name.
*
* @return the message.
*/
@Message(id = 55, value = "Failed to read %s entries for application [%s]")
String failedToRead(String entryName, String appName);
/**
* A message indicating a failure to read the entries in the module.
*
* @param entryName the name of the entry.
* @param appName the application name.
* @param moduleName the module name.
*
* @return the message.
*/
@Message(id = 56, value = "Failed to read %s entries for module [%s, %s]")
String failedToRead(String entryName, String appName, String moduleName);
/**
* A message indicating a failure to read the entries in the module.
*
* @param entryName the name of the entry.
* @param appName the application name.
* @param moduleName the module name.
* @param componentName the component name
*
* @return the message.
*/
@Message(id = 57, value = "Failed to read %s entries for component [%s, %s, %s]")
String failedToRead(String entryName, String appName, String moduleName, String componentName);
/**
* Creates an exception indicating the field, represented by the {@code name} parameter, was not found.
*
* @param name the name of the field.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 58, value = "No matching field found for '%s'")
DeploymentUnitProcessingException fieldNotFound(String name);
/**
* Creates an exception indicating no injection target was found.
*
* @return an {@link IllegalStateException} for the error.
*/
@Message(id = 59, value = "No injection target found")
IllegalStateException injectionTargetNotFound();
/**
* Creates an exception indicating the {@code elementName} character type is not exactly one character long.
*
* @param elementName the element name.
* @param value the value.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 60, value = "%s of type java.lang.Character is not exactly one character long %s")
DeploymentUnitProcessingException invalidCharacterLength(String elementName, String value);
/**
* Creates an exception indicating the descriptor is not valid.
*
* @param descriptor the invalid descriptor
*
* @return a {@link RuntimeException} for the error.
*/
@Message(id = 61, value = "%s is not a valid descriptor")
RuntimeException invalidDescriptor(String descriptor);
/**
* Creates an exception indicating the injection target, represented by the {@code targetName} parameter, on the
* class, represented by the {@code targetType} parameter, is not compatible with the type of injection.
*
* @param targetName the name of the target.
* @param targetType the type of the target.
* @param type the type provided.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 62, value = "Injection target %s on class %s is not compatible with the type of injection: %s")
DeploymentUnitProcessingException invalidInjectionTarget(String targetName, String targetType, Class<?> type);
/**
* A message indicating there are an invalid number of arguments for the method, represented by the parameter,
* annotated with the {@code annotation} on the class, represented by the {@code className} parameter.
*
* @param methodName the name of the method.
* @param annotation the annotation.
* @param className the name of the class.
*
* @return the message.
*/
@Message(id = 63, value = "Invalid number of arguments for method %s annotated with %s on class %s")
String invalidNumberOfArguments(String methodName, DotName annotation, DotName className);
/**
* Creates an exception indicating a return type for the method, represented by the
* {@code methodName} parameter, annotated with the {@code annotation} on the class, represented by the
* {@code className} parameter.
*
* @param returnType the return type required.
* @param methodName the name of the method.
* @param annotation the annotation.
* @param className the name of the class.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 64, value = "A return type of %s is required for method %s annotated with %s on class %s")
IllegalArgumentException invalidReturnType(String returnType, String methodName, DotName annotation, DotName className);
/**
* A message indicating methods annotated with the {@code annotation} must have a single argument.
*
* @param name the name of the method.
* @param annotation the annotation.
* @param className the class name.
* @param signatureArg the signature argument.
*
* @return the message.
*/
@Message(id = 65, value = "Invalid signature for method %s annotated with %s on class %s, signature must be '%s'")
String invalidSignature(String name, DotName annotation, DotName className, String signatureArg);
/**
* Creates an exception indicating the value for the element is invalid.
*
* @param value the invalid value.
* @param element the element.
* @param location the location of the error.
*
* @return {@link XMLStreamException} for the error.
*/
@Message(id = 66, value = "Invalid value: %s for '%s' element")
XMLStreamException invalidValue(String value, String element, @Param Location location);
/**
* Creates an exception indicating the method does not exist.
*
* @param method the method that does not exist.
*
* @return an {@link IllegalStateException} for the error.
*/
@Message(id = 67, value = "Method does not exist %s")
IllegalStateException methodNotFound(Method method);
/**
* Creates an exception indicating the method does not exist.
*
* @param name the name of the method.
* @param paramType the parameter type.
* @param className the class name.
*
* @return an {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 68, value = "No matching method found for method %s (%s) on %s")
DeploymentUnitProcessingException methodNotFound(String name, String paramType, String className);
/**
* Creates an exception indicating the annotation is only allowed on method targets.
*
* @param annotation the annotation.
*
* @return an {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 69, value = "@%s is only valid on method targets.")
DeploymentUnitProcessingException methodOnlyAnnotation(DotName annotation);
/**
* Creates an exception indicating multiple components were found for the type.
*
* @param typeName the name of the component.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 70, value = "Multiple components found for type '%s'")
DeploymentUnitProcessingException multipleComponentsFound(String typeName);
/**
* Creates an exception indicating multiple methods found.
*
* @param name the name of the method.
* @param paramType the parameter type.
* @param className the class name.
*
* @return an {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 71, value = "More than one matching method found for method '%s (%s) on %s")
DeploymentUnitProcessingException multipleMethodsFound(String name, String paramType, String className);
/**
* Creates an exception indicating multiple setter methods found.
*
* @param targetName the name of the method.
* @param className the class name.
*
* @return an {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 72, value = "Multiple setter methods for %s on class %s found when applying <injection-target> for env-entry")
DeploymentUnitProcessingException multipleSetterMethodsFound(String targetName, String className);
/**
* Creates an exception indicating there is no component instance associated.
*
* @return an {@link IllegalStateException} for the error.
*/
@Message(id = 73, value = "No component instance associated")
IllegalStateException noComponentInstance();
/**
* Creates an exception indicating the binding name must not be {@code null}.
*
* @param config the binding configuration.
*
* @return an {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 74, value = "Binding name must not be null: %s")
DeploymentUnitProcessingException nullBindingName(BindingConfiguration config);
/**
* Creates an exception indicating a {@code null} or empty managed bean class name.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 75, value = "Managed bean class name cannot be null or empty")
IllegalArgumentException nullOrEmptyManagedBeanClassName();
/**
* Creates an exception indicating a {@code null} or empty resource reference type.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 76, value = "Resource reference type cannot be null or empty")
IllegalArgumentException nullOrEmptyResourceReferenceType();
/**
* Creates an exception indicating a {@code null} resource reference processor cannot be registered.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 77, value = "Cannot register a null resource reference processor")
IllegalArgumentException nullResourceReference();
/**
* Creates an exception indicating the variable, represented by the {@code name} parameter, is {@code null}.
*
* @param name the name of the variable.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 78, value = "%s is null")
IllegalArgumentException nullVar(String name);
/**
* Creates an exception indicating the item cannot be added because the priority is already taken.
*
* @param item the item that was not added.
* @param hexPriority the priority.
* @param current the current item at that priority.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 79, value = "Can't add %s, priority 0x%s is already taken by %s")
IllegalArgumentException priorityAlreadyExists(Object item, String hexPriority, Object current);
// /**
// * Creates an exception indicating the ResourceDescriptionResolver variant should be used.
// *
// * @return an {@link UnsupportedOperationException} for the error.
// */
// @Message(id = 80, value = "Use the ResourceDescriptionResolver variant")
// UnsupportedOperationException resourceDescriptionResolverError();
// /**
// * Creates an exception indicating the resource reference for the {@code type} is not registered.
// *
// * @param type the resource reference type.
// *
// * @return an {@link IllegalArgumentException} for the error.
// */
// @Message(id = 81, value = "Resource reference for type: %s is not registered. Cannot unregister")
// IllegalArgumentException resourceReferenceNotRegistered(String type);
/**
* Creates an exception indicating the service is not started.
*
* @return an {@link IllegalStateException} for the error.
*/
@Message(id = 82, value = "Service not started")
IllegalStateException serviceNotStarted();
/**
* Creates an exception indicating the {@code annotation} injection target is invalid and only setter methods are
* allowed.
*
* @param annotation the annotation.
* @param methodInfo the method information.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 83, value = "%s injection target is invalid. Only setter methods are allowed: %s")
IllegalArgumentException setterMethodOnly(String annotation, MethodInfo methodInfo);
/**
* Creates an exception indicating the {@link AnnotationTarget AnnotationTarget} type is unknown.
*
* @param target the annotation target.
*
* @return a {@link RuntimeException} for the error.
*/
@Message(id = 84, value = "Unknown AnnotationTarget type: %s")
RuntimeException unknownAnnotationTargetType(AnnotationTarget target);
/**
* Creates an exception indicating the type for the {@code elementName} for the {@code type} is unknown.
*
* @param elementName the name of the element.
* @param type the type.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 85, value = "Unknown %s type %s")
DeploymentUnitProcessingException unknownElementType(String elementName, String type);
/**
* Creates an exception indicating the method could not found on the view.
*
* @param name the name of the method.
* @param descriptor the method descriptor.
* @param viewClass the view class.
* @param component the component class.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 86, value = "Could not find method %s %s on view %s of %s")
IllegalArgumentException viewMethodNotFound(String name, String descriptor, Class<?> viewClass, Class<?> component);
// @Message(id = 87, value = "Could not load component class %s")
// DeploymentUnitProcessingException couldNotLoadComponentClass(@Cause Throwable cause, final String className);
/**
* Creates an exception indicating an unexpected element, represented by the {@code name} parameter, was
* encountered.
*
* @param name the unexpected element name.
* @param location the location of the error.
*
* @return a {@link XMLStreamException} for the error.
*/
@Message(id = 88, value = "Unexpected element '%s' encountered")
XMLStreamException unexpectedElement(QName name, @Param Location location);
/**
* Creates an exception indicating that the jboss-ejb-client.xml couldn't be processed
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 89, value = "Failed to process jboss-ejb-client.xml")
DeploymentUnitProcessingException failedToProcessEJBClientDescriptor(@Cause Throwable cause);
/**
* Creates an exception indicating that there was an exception while parsing a jboss-ejb-client.xml
*
*
* @param fileLocation the location of jboss-ejb-client.xml
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 90, value = "Exception while parsing jboss-ejb-client.xml file found at %s")
DeploymentUnitProcessingException xmlErrorParsingEJBClientDescriptor(@Cause XMLStreamException cause, String fileLocation);
/**
* Creates an exception indicating that there was an exception while parsing a jboss-ejb-client.xml
*
* @param message The error message
* @param location The location of the error
*
* @return a {@link XMLStreamException} for the error.
*/
@Message(id = 91, value = "%s")
XMLStreamException errorParsingEJBClientDescriptor(String message, @Param Location location);
/**
* If a message destination could not be resolved
*/
@Message(id = 92, value = "No message destination with name %s for binding %s")
String noMessageDestination(String name, String binding);
/**
* If a message destination could not be resolved
*/
@Message(id = 93, value = "More than one message destination with name %s for binding %s destinations: %s")
String moreThanOneMessageDestination(String name, String binding, Set<String> jndiNames);
@Message(id = 94, value = "Failed to load jboss.properties")
DeploymentUnitProcessingException failedToLoadJbossProperties(@Cause IOException e);
@Message(id = 95, value = "Unsupported ear module type: %s")
DeploymentUnitProcessingException unsupportedModuleType(String moduleFileName);
@Message(id = 96, value = "library-directory of value / is not supported")
DeploymentUnitProcessingException rootAsLibraryDirectory();
@Message(id = 97, value = "Module may not be a child of the EAR's library directory. Library directory: %s, module file name: %s")
DeploymentUnitProcessingException earModuleChildOfLibraryDirectory(String libraryDirectory, String moduleFileName);
@Message(id = 98, value = "ManagedReference was null and injection is not optional for injection into field %s")
RuntimeException managedReferenceWasNull(Field field);
// @Message(id = 99, value = "Only 'true' is allowed for 'jboss-descriptor-property-replacement' due to AS7-4892")
// String onlyTrueAllowedForJBossDescriptorPropertyReplacement_AS7_4892();
@Message(id = 100, value = "Global modules may not specify 'annotations', 'meta-inf' or 'services'.")
String propertiesNotAllowedOnGlobalModules();
//@Message(id = 101, value = "No concurrent context currently set, unable to locate the context service to delegate.")
//IllegalStateException noConcurrentContextCurrentlySet();
@Message(id = 102, value = "EE Concurrent Service's value uninitialized.")
IllegalStateException concurrentServiceValueUninitialized();
@Message(id = 103, value = "EE Concurrent ContextHandle serialization must be handled by the factory.")
IOException serializationMustBeHandledByTheFactory();
@Message(id = 104, value = "The EE Concurrent Context %s already has a factory named %s")
IllegalArgumentException factoryAlreadyExists(ConcurrentContext concurrentContext, String factoryName);
@Message(id = 105, value = "EE Concurrent Context %s does not has a factory named %s")
IOException factoryNotFound(ConcurrentContext concurrentContext, String factoryName);
@Message(id = 106, value = "EE Concurrent Context %s service not installed.")
IOException concurrentContextServiceNotInstalled(ServiceName serviceName);
@Message(id = 107, value = "EE Concurrent Transaction Setup Provider service not installed.")
IllegalStateException transactionSetupProviderServiceNotInstalled();
@Message(id = 108, value = "Instance data can only be set during construction")
IllegalStateException instanceDataCanOnlyBeSetDuringConstruction();
/**
* Creates an exception indicating that there was a exception while deploying AroundInvokeInterceptor
*
* @param className the name of the class.
* @param numberOfAnnotatedMethods the number of @aroundInvoke annotations in the specified class.
*
* @return a {@link DeploymentUnitProcessingException} for the error.
*/
@Message(id = 109, value = "A class must not declare more than one AroundInvoke method. %s has %s methods annotated.")
DeploymentUnitProcessingException aroundInvokeAnnotationUsedTooManyTimes(DotName className, int numberOfAnnotatedMethods);
@LogMessage(level = ERROR)
@Message(id = 110, value = "Failed to run scheduled task: %s")
void failedToRunTask(Object delegate, @Cause Exception e);
@Message(id = 111, value = "Cannot run scheduled task %s as container is suspended")
IllegalStateException cannotRunScheduledTask(Object delegate);
/**
* Creates an exception indicating the core-threads must be greater than 0 for the task queue.
*
* @param queueLengthValue the queue length value
*
* @return an {@link OperationFailedException} for the exception
*/
@Message(id = 112, value = "The core-threads value must be greater than 0 when the queue-length is %s")
OperationFailedException invalidCoreThreadsSize(String queueLengthValue);
/**
* Creates an exception indicating the max-threads value cannot be less than the core-threads value.
*
* @param maxThreads the size for the max threads
* @param coreThreads the size for the core threads
*
* @return an {@link OperationFailedException} for the exception
*/
@Message(id = 113, value = "The max-threads value %d cannot be less than the core-threads value %d.")
OperationFailedException invalidMaxThreads(int maxThreads, int coreThreads);
@Message(id = 114, value = "Class does not implement all of the provided interfaces")
IllegalArgumentException classDoesNotImplementAllInterfaces();
/**
* Creates an exception indicating the name of the @{code objectType}, is {@code null}.
*
* @param objectType the type of the object.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 115, value = "The name of the %s is null")
IllegalArgumentException nullName(String objectType);
/**
* Creates an exception indicating the variable, represented by the {@code variable} parameter in the @{code objectType} {@code objectName}, is {@code null}.
*
* @param variable the name of the variable.
* @param objectType the type of the object.
* @param objectName the name of the object.
*
* @return an {@link IllegalArgumentException} for the error.
*/
@Message(id = 116, value = "%s is null in the %s %s")
IllegalArgumentException nullVar(String variable, String objectType, String objectName);
@Message(id = 117, value = "Field %s cannot be set - object of %s loaded by %s is not assignable to %s loaded by %s")
IllegalArgumentException cannotSetField(String fieldName, Class<?> injectedClass, ClassLoader injectedClassloader, Class<?> fieldClass, ClassLoader fieldClassloader);
//@LogMessage(level = INFO)
//@Message(id = 118, value = "The system property 'ee8.preview.mode' is set to 'true'. For provided EE 8 APIs where the EE 8 " +
// "version of the API differs from what is supported in EE 7, the EE 8 variant of the API will be used. " +
// "Support for this setting will be removed once all EE 8 APIs are provided and certified.")
//void usingEE8PreviewMode();
//@LogMessage(level = INFO)
//@Message(id = 119, value = "The system property 'ee8.preview.mode' is NOT set to 'true'. For provided EE 8 APIs where the EE 8 " +
// "version of the API differs from what is supported in EE 7, the EE 7 variant of the API will be used. " +
// "Support for this setting will be removed once all EE 8 APIs are provided and certified.")
//void notUsingEE8PreviewMode();
@Message(id = 120, value = "Failed to locate executor service '%s'")
OperationFailedException executorServiceNotFound(ServiceName serviceName);
@Message(id = 121, value = "Unsupported attribute '%s'")
IllegalStateException unsupportedExecutorServiceMetric(String attributeName);
@Message(id = 122, value = "Directory path %s in %s global-directory resource does not point to a valid directory.")
StartException globalDirectoryDoNotExist(String globalDirectoryPath, String globalDirectoryName);
@Message(id = 123, value = "Global directory %s cannot be added, because global directory %s is already defined.")
OperationFailedException oneGlobalDirectory(String newGlobalDirectory, String existingGlobalDirectory);
@LogMessage(level = WARN)
@Message(id = 124, value = "Error deleting Jakarta Authorization Policy")
void errorDeletingJACCPolicy(@Cause Throwable t);
@Message(id = 125, value = "Unable to start the %s service")
StartException unableToStartException(String service, @Cause Throwable t);
@Message(id = 126, value = "Rejected due to maximum number of requests")
RejectedExecutionException rejectedDueToMaxRequests();
@LogMessage(level = WARN)
@Message(id = 127, value = "Invalid '%s' name segment for env, name can't start with '/' prefix, prefix has been removed")
void invalidNamePrefix(String name);
/**
* Logs a warning message indicating a failure when terminating a managed executor's hung task.
* @param cause the cause of the error.
* @param executorName the name of the executor.
* @param taskName the name of the hung task.
*/
@LogMessage(level = WARN)
@Message(id = 128, value = "Failure when terminating %s hung task %s")
void huntTaskTerminationFailure(@Cause Throwable cause, String executorName, String taskName);
/**
* Logs a message indicating a hung task was cancelled.
* @param executorName the name of the executor.
* @param taskName the name of the hung task.
*/
@LogMessage(level = INFO)
@Message(id = 129, value = "%s hung task %s cancelled")
void hungTaskCancelled(String executorName, String taskName);
/**
* Logs a message indicating a hung task was not cancelled.
* @param executorName the name of the executor.
* @param taskName the name of the hung task.
*/
@LogMessage(level = INFO)
@Message(id = 130, value = "%s hung task %s not cancelled")
void hungTaskNotCancelled(String executorName, String taskName);
@Message(id = 131, value = "The attribute %s is no longer supported.")
XMLStreamException attributeNoLongerSupported(final String attribute);
@Message(id = 132, value = "ManagedReference was null and injection is not optional for injection into method %s")
RuntimeException managedReferenceMethodWasNull(Method method);
@LogMessage(level = ERROR)
@Message(id = 133, value = "A JNDI binding for component '%s' has already been installed under JNDI name '%s' in accordance with Jakarta EE " +
"specifications. The conflicting class is %s. Solutions include providing an alternate name for the component " +
"or renaming the class.")
void duplicateJndiBindingFound(String componentName, String jndiName, Class clazz);
@Message(id = 134, value = "Multiple uses of ContextServiceDefinition.ALL_REMAINING")
IllegalStateException multipleUsesOfAllRemaining();
@LogMessage(level = WARN)
@Message(id = 135, value = "Failed to resume transaction.")
void failedToResumeTransaction(@Cause Throwable cause);
@Message(id = 136, value = "Failed to run scheduled task: %s")
RuntimeException failureWhileRunningTask(Object delegate,@Cause Exception e);
}
| 53,893 | 42.67423 | 170 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EESubsystemParser12.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2015, 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.ee.subsystem;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.parsing.ParseUtils.missingRequired;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoAttributes;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoContent;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement;
/**
* @author <a href="mailto:[email protected]">Richard Opalka</a>
*/
class EESubsystemParser12 implements XMLStreamConstants, XMLElementReader<List<ModelNode>> {
EESubsystemParser12() {
}
/**
* {@inheritDoc}
*/
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
// EE subsystem doesn't have any attributes, so make sure that the xml doesn't have any
requireNoAttributes(reader);
final ModelNode eeSubSystem = Util.createAddOperation(PathAddress.pathAddress(EeExtension.PATH_SUBSYSTEM));
// add the subsystem to the ModelNode(s)
list.add(eeSubSystem);
// elements
final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Namespace.forUri(reader.getNamespaceURI())) {
case EE_1_2: {
final Element element = Element.forName(reader.getLocalName());
if (!encountered.add(element)) {
throw unexpectedElement(reader);
}
switch (element) {
case GLOBAL_MODULES: {
final ModelNode model = parseGlobalModules(reader);
eeSubSystem.get(GlobalModulesDefinition.GLOBAL_MODULES).set(model);
break;
}
case EAR_SUBDEPLOYMENTS_ISOLATED: {
final String earSubDeploymentsIsolated = parseEarSubDeploymentsIsolatedElement(reader);
// set the ear subdeployment isolation on the subsystem operation
EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.parseAndSetParameter(earSubDeploymentsIsolated, eeSubSystem, reader);
break;
}
case SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseSpecDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseJBossDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case ANNOTATION_PROPERTY_REPLACEMENT: {
final String enabled = parseEJBAnnotationPropertyReplacement(reader);
EeSubsystemRootResource.ANNOTATION_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
static String parseEJBAnnotationPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
return value.trim();
}
static ModelNode parseGlobalModules(XMLExtendedStreamReader reader) throws XMLStreamException {
ModelNode globalModules = new ModelNode();
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MODULE: {
final ModelNode module = new ModelNode();
final int count = reader.getAttributeCount();
String name = null;
String slot = null;
String annotations = null;
String metaInf = null;
String services = null;
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME:
if (name != null) {
throw unexpectedAttribute(reader, i);
}
name = value;
GlobalModulesDefinition.NAME_AD.parseAndSetParameter(name, module, reader);
break;
case SLOT:
if (slot != null) {
throw unexpectedAttribute(reader, i);
}
slot = value;
GlobalModulesDefinition.SLOT_AD.parseAndSetParameter(slot, module, reader);
break;
case ANNOTATIONS:
if (annotations != null) {
throw unexpectedAttribute(reader, i);
}
annotations = value;
GlobalModulesDefinition.ANNOTATIONS_AD.parseAndSetParameter(annotations, module, reader);
break;
case SERVICES:
if (services != null) {
throw unexpectedAttribute(reader, i);
}
services = value;
GlobalModulesDefinition.SERVICES_AD.parseAndSetParameter(services, module, reader);
break;
case META_INF:
if (metaInf != null) {
throw unexpectedAttribute(reader, i);
}
metaInf = value;
GlobalModulesDefinition.META_INF_AD.parseAndSetParameter(metaInf, module, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (name == null) {
throw missingRequired(reader, Collections.singleton(NAME));
}
globalModules.add(module);
requireNoContent(reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
return globalModules;
}
static String parseEarSubDeploymentsIsolatedElement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.EAR_SUBDEPLOYMENTS_ISOLATED.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseSpecDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseJBossDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
}
| 10,962 | 44.301653 | 149 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ManagedScheduledExecutorServiceAdd.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.subsystem;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.glassfish.enterprise.concurrent.AbstractManagedExecutorService;
import org.glassfish.enterprise.concurrent.ContextServiceImpl;
import org.glassfish.enterprise.concurrent.ManagedScheduledExecutorServiceAdapter;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.CapabilityServiceBuilder;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl;
import org.jboss.as.ee.concurrent.service.ConcurrentServiceNames;
import org.jboss.as.ee.concurrent.service.ManagedExecutorHungTasksPeriodicTerminationService;
import org.jboss.as.ee.concurrent.service.ManagedScheduledExecutorServiceService;
import org.jboss.dmr.ModelNode;
import org.wildfly.common.cpu.ProcessorInfo;
import org.wildfly.extension.requestcontroller.RequestController;
/**
* @author Eduardo Martins
*/
public class ManagedScheduledExecutorServiceAdd extends AbstractAddStepHandler {
private static final String REQUEST_CONTROLLER_CAPABILITY_NAME = "org.wildfly.request-controller";
static final ManagedScheduledExecutorServiceAdd INSTANCE = new ManagedScheduledExecutorServiceAdd();
private ManagedScheduledExecutorServiceAdd() {
super(ManagedScheduledExecutorServiceResourceDefinition.ATTRIBUTES);
}
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final String name = context.getCurrentAddressValue();
final String jndiName = ManagedExecutorServiceResourceDefinition.JNDI_NAME_AD.resolveModelAttribute(context, model).asString();
final long hungTaskTerminationPeriod = ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_TERMINATION_PERIOD_AD.resolveModelAttribute(context, model).asLong();
final long hungTaskThreshold = ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.resolveModelAttribute(context, model).asLong();
final boolean longRunningTasks = ManagedScheduledExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.resolveModelAttribute(context, model).asBoolean();
final int coreThreads;
final ModelNode coreThreadsModel = ManagedScheduledExecutorServiceResourceDefinition.CORE_THREADS_AD.resolveModelAttribute(context, model);
//value 0 means the same as undefined
if (coreThreadsModel.isDefined() && coreThreadsModel.asInt() != 0) {
coreThreads = coreThreadsModel.asInt();
} else {
coreThreads = (ProcessorInfo.availableProcessors() * 2);
}
final long keepAliveTime = ManagedScheduledExecutorServiceResourceDefinition.KEEPALIVE_TIME_AD.resolveModelAttribute(context, model).asLong();
final TimeUnit keepAliveTimeUnit = TimeUnit.MILLISECONDS;
final long threadLifeTime = 0L;
final AbstractManagedExecutorService.RejectPolicy rejectPolicy = AbstractManagedExecutorService.RejectPolicy.valueOf(ManagedScheduledExecutorServiceResourceDefinition.REJECT_POLICY_AD.resolveModelAttribute(context, model).asString());
final Integer threadPriority;
if(model.hasDefined(ManagedScheduledExecutorServiceResourceDefinition.THREAD_PRIORITY) || !model.hasDefined(ManagedScheduledExecutorServiceResourceDefinition.THREAD_FACTORY)) {
// defined, or use default value in case deprecated thread-factory also not defined
threadPriority = ManagedScheduledExecutorServiceResourceDefinition.THREAD_PRIORITY_AD.resolveModelAttribute(context, model).asInt();
} else {
// not defined and deprecated thread-factory is defined, use it instead
threadPriority = null;
}
final CapabilityServiceBuilder serviceBuilder = context.getCapabilityServiceTarget().addCapability(ManagedScheduledExecutorServiceResourceDefinition.CAPABILITY);
final Consumer<ManagedScheduledExecutorServiceAdapter> consumer = serviceBuilder.provides(ManagedScheduledExecutorServiceResourceDefinition.CAPABILITY);
final Supplier<ManagedExecutorHungTasksPeriodicTerminationService> hungTasksPeriodicTerminationService = serviceBuilder.requires(ConcurrentServiceNames.HUNG_TASK_PERIODIC_TERMINATION_SERVICE_NAME);
String contextService = null;
if (model.hasDefined(ManagedScheduledExecutorServiceResourceDefinition.CONTEXT_SERVICE)) {
contextService = ManagedScheduledExecutorServiceResourceDefinition.CONTEXT_SERVICE_AD.resolveModelAttribute(context, model).asString();
}
final Supplier<ContextServiceImpl> contextServiceSupplier = contextService != null ? serviceBuilder.requiresCapability(ContextServiceResourceDefinition.CAPABILITY.getName(), ContextServiceImpl.class, contextService) : null;
String threadFactory = null;
if (model.hasDefined(ManagedScheduledExecutorServiceResourceDefinition.THREAD_FACTORY)) {
threadFactory = ManagedScheduledExecutorServiceResourceDefinition.THREAD_FACTORY_AD.resolveModelAttribute(context, model).asString();
}
final Supplier<ManagedThreadFactoryImpl> managedThreadFactorySupplier = threadFactory != null ? serviceBuilder.requiresCapability(ManagedThreadFactoryResourceDefinition.CAPABILITY.getName(), ManagedThreadFactoryImpl.class, threadFactory) : null;
Supplier<RequestController> requestControllerSupplier = null;
if (context.hasOptionalCapability(REQUEST_CONTROLLER_CAPABILITY_NAME, null, null)) {
requestControllerSupplier = serviceBuilder.requiresCapability(REQUEST_CONTROLLER_CAPABILITY_NAME, RequestController.class);
}
final ManagedScheduledExecutorServiceService service = new ManagedScheduledExecutorServiceService(consumer, contextServiceSupplier, managedThreadFactorySupplier, requestControllerSupplier, name, jndiName, hungTaskThreshold, hungTaskTerminationPeriod, longRunningTasks, coreThreads, keepAliveTime, keepAliveTimeUnit, threadLifeTime, rejectPolicy, threadPriority, hungTasksPeriodicTerminationService);
serviceBuilder.setInstance(service);
serviceBuilder.install();
}
}
| 7,342 | 64.5625 | 407 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ManagedExecutorServiceAdd.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.subsystem;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.glassfish.enterprise.concurrent.AbstractManagedExecutorService;
import org.glassfish.enterprise.concurrent.ContextServiceImpl;
import org.glassfish.enterprise.concurrent.ManagedExecutorServiceAdapter;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.CapabilityServiceBuilder;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl;
import org.jboss.as.ee.concurrent.service.ConcurrentServiceNames;
import org.jboss.as.ee.concurrent.service.ManagedExecutorHungTasksPeriodicTerminationService;
import org.jboss.as.ee.concurrent.service.ManagedExecutorServiceService;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.subsystem.ManagedExecutorServiceResourceDefinition.ExecutorQueueValidationStepHandler;
import org.jboss.dmr.ModelNode;
import org.wildfly.common.cpu.ProcessorInfo;
import org.wildfly.extension.requestcontroller.RequestController;
/**
* @author Eduardo Martins
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
public class ManagedExecutorServiceAdd extends AbstractAddStepHandler {
private static final String REQUEST_CONTROLLER_CAPABILITY_NAME = "org.wildfly.request-controller";
static final ManagedExecutorServiceAdd INSTANCE = new ManagedExecutorServiceAdd();
private ManagedExecutorServiceAdd() {
super(ManagedExecutorServiceResourceDefinition.ATTRIBUTES);
}
@Override
protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
// Add a new step to validate the core-threads, max-threads and queue-length values
context.addStep(ExecutorQueueValidationStepHandler.MODEL_VALIDATION_INSTANCE, OperationContext.Stage.MODEL);
super.populateModel(context, operation, resource);
}
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final String name = context.getCurrentAddressValue();
final String jndiName = ManagedExecutorServiceResourceDefinition.JNDI_NAME_AD.resolveModelAttribute(context, model).asString();
final long hungTaskTerminationPeriod = ManagedExecutorServiceResourceDefinition.HUNG_TASK_TERMINATION_PERIOD_AD.resolveModelAttribute(context, model).asLong();
final long hungTaskThreshold = ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.resolveModelAttribute(context, model).asLong();
final boolean longRunningTasks = ManagedExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.resolveModelAttribute(context, model).asBoolean();
final int coreThreads;
final ModelNode coreThreadsModel = ManagedExecutorServiceResourceDefinition.CORE_THREADS_AD.resolveModelAttribute(context, model);
if (coreThreadsModel.isDefined()) {
coreThreads = coreThreadsModel.asInt();
} else {
coreThreads = (ProcessorInfo.availableProcessors() * 2);
}
final int maxThreads;
final ModelNode maxThreadsModel = ManagedExecutorServiceResourceDefinition.MAX_THREADS_AD.resolveModelAttribute(context, model);
if (maxThreadsModel.isDefined()) {
maxThreads = maxThreadsModel.asInt();
} else {
maxThreads = coreThreads;
}
// Note that this must be done in the runtime stage since the core-threads value may be calculated
if (maxThreads < coreThreads) {
throw EeLogger.ROOT_LOGGER.invalidMaxThreads(maxThreads, coreThreads);
}
final long keepAliveTime = ManagedExecutorServiceResourceDefinition.KEEPALIVE_TIME_AD.resolveModelAttribute(context, model).asLong();
final TimeUnit keepAliveTimeUnit = TimeUnit.MILLISECONDS;
final long threadLifeTime = 0L;
final int queueLength;
final ModelNode queueLengthModel = ManagedExecutorServiceResourceDefinition.QUEUE_LENGTH_AD.resolveModelAttribute(context, model);
if (queueLengthModel.isDefined()) {
queueLength = queueLengthModel.asInt();
} else {
queueLength = Integer.MAX_VALUE;
}
final AbstractManagedExecutorService.RejectPolicy rejectPolicy = AbstractManagedExecutorService.RejectPolicy.valueOf(ManagedExecutorServiceResourceDefinition.REJECT_POLICY_AD.resolveModelAttribute(context, model).asString());
final Integer threadPriority;
if(model.hasDefined(ManagedExecutorServiceResourceDefinition.THREAD_PRIORITY) || !model.hasDefined(ManagedExecutorServiceResourceDefinition.THREAD_FACTORY)) {
// defined, or use default value in case deprecated thread-factory also not defined
threadPriority = ManagedExecutorServiceResourceDefinition.THREAD_PRIORITY_AD.resolveModelAttribute(context, model).asInt();
} else {
// not defined and deprecated thread-factory is defined, use it instead
threadPriority = null;
}
final CapabilityServiceBuilder serviceBuilder = context.getCapabilityServiceTarget().addCapability(ManagedExecutorServiceResourceDefinition.CAPABILITY);
final Consumer<ManagedExecutorServiceAdapter> consumer = serviceBuilder.provides(ManagedExecutorServiceResourceDefinition.CAPABILITY);
final Supplier<ManagedExecutorHungTasksPeriodicTerminationService> hungTasksPeriodicTerminationService = serviceBuilder.requires(ConcurrentServiceNames.HUNG_TASK_PERIODIC_TERMINATION_SERVICE_NAME);
String contextService = null;
if (model.hasDefined(ManagedExecutorServiceResourceDefinition.CONTEXT_SERVICE)) {
contextService = ManagedExecutorServiceResourceDefinition.CONTEXT_SERVICE_AD.resolveModelAttribute(context, model).asString();
}
final Supplier<ContextServiceImpl> contextServiceSupplier = contextService != null ? serviceBuilder.requiresCapability(ContextServiceResourceDefinition.CAPABILITY.getName(), ContextServiceImpl.class, contextService) : null;
String threadFactory = null;
if (model.hasDefined(ManagedExecutorServiceResourceDefinition.THREAD_FACTORY)) {
threadFactory = ManagedExecutorServiceResourceDefinition.THREAD_FACTORY_AD.resolveModelAttribute(context, model).asString();
}
final Supplier<ManagedThreadFactoryImpl> threadFactorySupplier = threadFactory != null ? serviceBuilder.requiresCapability(ManagedThreadFactoryResourceDefinition.CAPABILITY.getName(), ManagedThreadFactoryImpl.class, threadFactory) : null;
Supplier<RequestController> requestControllerSupplier = null;
if (context.hasOptionalCapability(REQUEST_CONTROLLER_CAPABILITY_NAME, null, null)) {
requestControllerSupplier = serviceBuilder.requiresCapability(REQUEST_CONTROLLER_CAPABILITY_NAME, RequestController.class);
}
final ManagedExecutorServiceService service = new ManagedExecutorServiceService(consumer, contextServiceSupplier, threadFactorySupplier, requestControllerSupplier, name, jndiName, hungTaskThreshold, hungTaskTerminationPeriod, longRunningTasks, coreThreads, maxThreads, keepAliveTime, keepAliveTimeUnit, threadLifeTime, queueLength, rejectPolicy, threadPriority, hungTasksPeriodicTerminationService);
serviceBuilder.setInstance(service);
serviceBuilder.install();
}
}
| 8,665 | 59.601399 | 407 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EESubsystemParser60.java | /*
* Copyright 2015 Red Hat, Inc.
*
* 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.jboss.as.ee.subsystem;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.parsing.ParseUtils.missingRequired;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoAttributes;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoContent;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement;
/**
*/
class EESubsystemParser60 implements XMLStreamConstants, XMLElementReader<List<ModelNode>> {
EESubsystemParser60() {
}
/**
* {@inheritDoc}
*/
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
// EE subsystem doesn't have any attributes, so make sure that the xml doesn't have any
requireNoAttributes(reader);
final PathAddress subsystemPathAddress = PathAddress.pathAddress(EeExtension.PATH_SUBSYSTEM);
final ModelNode eeSubSystem = Util.createAddOperation(subsystemPathAddress);
// add the subsystem to the ModelNode(s)
list.add(eeSubSystem);
// elements
final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Namespace.forUri(reader.getNamespaceURI())) {
case EE_6_0: {
final Element element = Element.forName(reader.getLocalName());
if (!encountered.add(element)) {
throw unexpectedElement(reader);
}
switch (element) {
case GLOBAL_MODULES: {
final ModelNode model = parseGlobalModules(reader);
eeSubSystem.get(GlobalModulesDefinition.GLOBAL_MODULES).set(model);
break;
}
case GLOBAL_DIRECTORIES: {
parseGlobalDirectories(reader, list, subsystemPathAddress);
break;
}
case EAR_SUBDEPLOYMENTS_ISOLATED: {
final String earSubDeploymentsIsolated = parseEarSubDeploymentsIsolatedElement(reader);
// set the ear subdeployment isolation on the subsystem operation
EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.parseAndSetParameter(earSubDeploymentsIsolated, eeSubSystem, reader);
break;
}
case SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseSpecDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseJBossDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case ANNOTATION_PROPERTY_REPLACEMENT: {
final String enabled = parseEJBAnnotationPropertyReplacement(reader);
EeSubsystemRootResource.ANNOTATION_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case CONCURRENT: {
parseConcurrent(reader, list, subsystemPathAddress);
break;
}
case DEFAULT_BINDINGS: {
parseDefaultBindings(reader, list, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
static ModelNode parseGlobalModules(XMLExtendedStreamReader reader) throws XMLStreamException {
ModelNode globalModules = new ModelNode();
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MODULE: {
final ModelNode module = new ModelNode();
final int count = reader.getAttributeCount();
String name = null;
String slot = null;
String annotations = null;
String metaInf = null;
String services = null;
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME:
if (name != null) {
throw unexpectedAttribute(reader, i);
}
name = value;
GlobalModulesDefinition.NAME_AD.parseAndSetParameter(name, module, reader);
break;
case SLOT:
if (slot != null) {
throw unexpectedAttribute(reader, i);
}
slot = value;
GlobalModulesDefinition.SLOT_AD.parseAndSetParameter(slot, module, reader);
break;
case ANNOTATIONS:
if (annotations != null) {
throw unexpectedAttribute(reader, i);
}
annotations = value;
GlobalModulesDefinition.ANNOTATIONS_AD.parseAndSetParameter(annotations, module, reader);
break;
case SERVICES:
if (services != null) {
throw unexpectedAttribute(reader, i);
}
services = value;
GlobalModulesDefinition.SERVICES_AD.parseAndSetParameter(services, module, reader);
break;
case META_INF:
if (metaInf != null) {
throw unexpectedAttribute(reader, i);
}
metaInf = value;
GlobalModulesDefinition.META_INF_AD.parseAndSetParameter(metaInf, module, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (name == null) {
throw missingRequired(reader, Collections.singleton(NAME));
}
globalModules.add(module);
requireNoContent(reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
return globalModules;
}
static String parseEarSubDeploymentsIsolatedElement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.EAR_SUBDEPLOYMENTS_ISOLATED.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseSpecDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseJBossDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseEJBAnnotationPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
return value.trim();
}
static void parseConcurrent(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case CONTEXT_SERVICES: {
parseContextServices(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_THREAD_FACTORIES: {
parseManagedThreadFactories(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_EXECUTOR_SERVICES: {
parseManagedExecutorServices(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_SCHEDULED_EXECUTOR_SERVICES: {
parseManagedScheduledExecutorServices(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
static void parseContextServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case CONTEXT_SERVICE: {
empty = false;
parseContextService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.CONTEXT_SERVICE));
}
}
static void parseContextService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ContextServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case USE_TRANSACTION_SETUP_PROVIDER:
ContextServiceResourceDefinition.USE_TRANSACTION_SETUP_PROVIDER_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.CONTEXT_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedThreadFactories(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_THREAD_FACTORY: {
empty = false;
parseManagedThreadFactory(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_THREAD_FACTORY));
}
}
static void parseManagedThreadFactory(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedThreadFactoryResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedThreadFactoryResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case PRIORITY:
ManagedThreadFactoryResourceDefinition.PRIORITY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_THREAD_FACTORY, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedExecutorServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_EXECUTOR_SERVICE: {
empty = false;
parseManagedExecutorService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_EXECUTOR_SERVICE));
}
}
static void parseManagedExecutorService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedExecutorServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedExecutorServiceResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_FACTORY:
ManagedExecutorServiceResourceDefinition.THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_PRIORITY:
ManagedExecutorServiceResourceDefinition.THREAD_PRIORITY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case HUNG_TASK_TERMINATION_PERIOD:
ManagedExecutorServiceResourceDefinition.HUNG_TASK_TERMINATION_PERIOD_AD.parseAndSetParameter(value, addOperation, reader);
break;
case HUNG_TASK_THRESHOLD:
ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.parseAndSetParameter(value, addOperation, reader);
break;
case LONG_RUNNING_TASKS:
ManagedExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CORE_THREADS:
ManagedExecutorServiceResourceDefinition.CORE_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MAX_THREADS:
ManagedExecutorServiceResourceDefinition.MAX_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case KEEPALIVE_TIME:
ManagedExecutorServiceResourceDefinition.KEEPALIVE_TIME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case QUEUE_LENGTH:
ManagedExecutorServiceResourceDefinition.QUEUE_LENGTH_AD.parseAndSetParameter(value, addOperation, reader);
break;
case REJECT_POLICY:
ManagedExecutorServiceResourceDefinition.REJECT_POLICY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedScheduledExecutorServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_SCHEDULED_EXECUTOR_SERVICE: {
empty = false;
parseManagedScheduledExecutorService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_SCHEDULED_EXECUTOR_SERVICE));
}
}
static void parseManagedScheduledExecutorService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedScheduledExecutorServiceResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_FACTORY:
ManagedScheduledExecutorServiceResourceDefinition.THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_PRIORITY:
ManagedScheduledExecutorServiceResourceDefinition.THREAD_PRIORITY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case HUNG_TASK_TERMINATION_PERIOD:
ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_TERMINATION_PERIOD_AD.parseAndSetParameter(value, addOperation, reader);
break;
case HUNG_TASK_THRESHOLD:
ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.parseAndSetParameter(value, addOperation, reader);
break;
case LONG_RUNNING_TASKS:
ManagedScheduledExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CORE_THREADS:
ManagedScheduledExecutorServiceResourceDefinition.CORE_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case KEEPALIVE_TIME:
ManagedScheduledExecutorServiceResourceDefinition.KEEPALIVE_TIME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case REJECT_POLICY:
ManagedScheduledExecutorServiceResourceDefinition.REJECT_POLICY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseDefaultBindings(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case CONTEXT_SERVICE:
DefaultBindingsResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case DATASOURCE:
DefaultBindingsResourceDefinition.DATASOURCE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case JMS_CONNECTION_FACTORY:
DefaultBindingsResourceDefinition.JMS_CONNECTION_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_EXECUTOR_SERVICE:
DefaultBindingsResourceDefinition.MANAGED_EXECUTOR_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_SCHEDULED_EXECUTOR_SERVICE:
DefaultBindingsResourceDefinition.MANAGED_SCHEDULED_EXECUTOR_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_THREAD_FACTORY:
DefaultBindingsResourceDefinition.MANAGED_THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.DEFAULT_BINDINGS_PATH);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseGlobalDirectories(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case DIRECTORY: {
empty = false;
parseDirectory(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.DIRECTORY));
}
}
static void parseDirectory(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.PATH);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case PATH:
GlobalDirectoryResourceDefinition.PATH.parseAndSetParameter(value, addOperation, reader);
break;
case RELATIVE_TO:
GlobalDirectoryResourceDefinition.RELATIVE_TO.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.GLOBAL_DIRECTORY, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
}
| 30,789 | 47.64139 | 175 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EeSubsystemAdd.java | /*
* 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.ee.subsystem;
import static org.jboss.as.ee.subsystem.EeCapabilities.LEGACY_JACC_CAPABILITY;
import static org.jboss.as.ee.subsystem.EeCapabilities.ELYTRON_JACC_CAPABILITY;
import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.ee.component.ReflectiveClassIntrospector;
import org.jboss.as.ee.component.deployers.ApplicationClassesAggregationProcessor;
import org.jboss.as.ee.component.deployers.AroundInvokeAnnotationParsingProcessor;
import org.jboss.as.ee.component.deployers.ComponentInstallProcessor;
import org.jboss.as.ee.component.deployers.DefaultEarSubDeploymentsIsolationProcessor;
import org.jboss.as.ee.component.deployers.DescriptorEnvironmentLifecycleMethodProcessor;
import org.jboss.as.ee.component.deployers.EEAnnotationProcessor;
import org.jboss.as.ee.component.deployers.EECleanUpProcessor;
import org.jboss.as.ee.component.deployers.EEDefaultPermissionsProcessor;
import org.jboss.as.ee.component.deployers.EEDistinctNameProcessor;
import org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor;
import org.jboss.as.ee.component.deployers.EEModuleInitialProcessor;
import org.jboss.as.ee.component.deployers.EEModuleNameProcessor;
import org.jboss.as.ee.component.deployers.EarApplicationNameProcessor;
import org.jboss.as.ee.component.deployers.EarMessageDestinationProcessor;
import org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor;
import org.jboss.as.ee.component.deployers.LifecycleAnnotationParsingProcessor;
import org.jboss.as.ee.component.deployers.MessageDestinationResolutionProcessor;
import org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor;
import org.jboss.as.ee.component.deployers.ResourceInjectionAnnotationParsingProcessor;
import org.jboss.as.ee.component.deployers.ResourceReferenceProcessor;
import org.jboss.as.ee.component.deployers.ResourceReferenceRegistrySetupProcessor;
import org.jboss.as.ee.concurrent.deployers.EEConcurrentContextProcessor;
import org.jboss.as.ee.concurrent.deployers.EEConcurrentDefaultBindingProcessor;
import org.jboss.as.ee.concurrent.resource.definition.ContextServiceDefinitionAnnotationProcessor;
import org.jboss.as.ee.concurrent.resource.definition.ContextServiceDefinitionDescriptorProcessor;
import org.jboss.as.ee.concurrent.resource.definition.ManagedExecutorDefinitionAnnotationProcessor;
import org.jboss.as.ee.concurrent.resource.definition.ManagedExecutorDefinitionDescriptorProcessor;
import org.jboss.as.ee.concurrent.resource.definition.ManagedScheduledExecutorDefinitionAnnotationProcessor;
import org.jboss.as.ee.concurrent.resource.definition.ManagedScheduledExecutorDefinitionDescriptorProcessor;
import org.jboss.as.ee.concurrent.resource.definition.ManagedThreadFactoryDefinitionAnnotationProcessor;
import org.jboss.as.ee.concurrent.resource.definition.ManagedThreadFactoryDefinitionDescriptorProcessor;
import org.jboss.as.ee.concurrent.service.ManagedExecutorHungTasksPeriodicTerminationService;
import org.jboss.as.ee.managedbean.processors.JavaEEDependencyProcessor;
import org.jboss.as.ee.managedbean.processors.ManagedBeanAnnotationProcessor;
import org.jboss.as.ee.managedbean.processors.ManagedBeanSubDeploymentMarkingProcessor;
import org.jboss.as.ee.metadata.property.DeploymentPropertiesProcessor;
import org.jboss.as.ee.metadata.property.DeploymentPropertyResolverProcessor;
import org.jboss.as.ee.metadata.property.PropertyResolverProcessor;
import org.jboss.as.ee.naming.ApplicationContextProcessor;
import org.jboss.as.ee.naming.InApplicationClientBindingProcessor;
import org.jboss.as.ee.naming.InstanceNameBindingProcessor;
import org.jboss.as.ee.naming.ModuleContextProcessor;
import org.jboss.as.ee.security.JaccEarDeploymentProcessor;
import org.jboss.as.ee.structure.AnnotationPropertyReplacementProcessor;
import org.jboss.as.ee.structure.AppJBossAllParser;
import org.jboss.as.ee.structure.ApplicationClientDeploymentProcessor;
import org.jboss.as.ee.structure.ComponentAggregationProcessor;
import org.jboss.as.ee.structure.DescriptorPropertyReplacementProcessor;
import org.jboss.as.ee.structure.EJBClientDescriptorParsingProcessor;
import org.jboss.as.ee.structure.EarDependencyProcessor;
import org.jboss.as.ee.structure.EarInitializationProcessor;
import org.jboss.as.ee.structure.EarMetaDataParsingProcessor;
import org.jboss.as.ee.structure.EarStructureProcessor;
import org.jboss.as.ee.structure.EjbJarDeploymentProcessor;
import org.jboss.as.ee.structure.GlobalDirectoryDependencyProcessor;
import org.jboss.as.ee.structure.GlobalModuleDependencyProcessor;
import org.jboss.as.ee.structure.InitializeInOrderProcessor;
import org.jboss.as.naming.management.JndiViewExtensionRegistry;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.as.server.deployment.Phase;
import org.jboss.as.server.deployment.jbossallxml.JBossAllXmlParserRegisteringProcessor;
import org.jboss.dmr.ModelNode;
import org.jboss.metadata.ear.jboss.JBossAppMetaData;
/**
* Handler for adding the ee subsystem.
*
* @author Weston M. Price
* @author Emanuel Muckenhuber
*/
public class EeSubsystemAdd extends AbstractBoottimeAddStepHandler {
private final DefaultEarSubDeploymentsIsolationProcessor isolationProcessor;
private final GlobalModuleDependencyProcessor moduleDependencyProcessor;
private final DescriptorPropertyReplacementProcessor specDescriptorPropertyReplacementProcessor;
private final DescriptorPropertyReplacementProcessor jbossDescriptorPropertyReplacementProcessor;
private final AnnotationPropertyReplacementProcessor ejbAnnotationPropertyReplacementProcessor;
private final GlobalDirectoryDependencyProcessor directoryDependencyProcessor;
public EeSubsystemAdd(final DefaultEarSubDeploymentsIsolationProcessor isolationProcessor,
final GlobalModuleDependencyProcessor moduleDependencyProcessor,
final DescriptorPropertyReplacementProcessor specDescriptorPropertyReplacementProcessor,
final DescriptorPropertyReplacementProcessor jbossDescriptorPropertyReplacementProcessor,
final AnnotationPropertyReplacementProcessor ejbAnnotationPropertyReplacementProcessor,
final GlobalDirectoryDependencyProcessor directoryDependencyProcessor) {
this.isolationProcessor = isolationProcessor;
this.moduleDependencyProcessor = moduleDependencyProcessor;
this.specDescriptorPropertyReplacementProcessor = specDescriptorPropertyReplacementProcessor;
this.jbossDescriptorPropertyReplacementProcessor = jbossDescriptorPropertyReplacementProcessor;
this.ejbAnnotationPropertyReplacementProcessor = ejbAnnotationPropertyReplacementProcessor;
this.directoryDependencyProcessor = directoryDependencyProcessor;
}
protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
for (AttributeDefinition ad : EeSubsystemRootResource.ATTRIBUTES) {
ad.validateAndSet(operation, model);
}
}
protected void performBoottime(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
ModelNode model = resource.getModel();
final EEJndiViewExtension extension = new EEJndiViewExtension();
context.getServiceTarget().addService(EEJndiViewExtension.SERVICE_NAME, extension)
.addDependency(JndiViewExtensionRegistry.SERVICE_NAME, JndiViewExtensionRegistry.class, extension.getRegistryInjector())
.install();
final boolean appclient = context.getProcessType() == ProcessType.APPLICATION_CLIENT;
final ModelNode globalModules = GlobalModulesDefinition.INSTANCE.resolveModelAttribute(context, model);
// see if the ear subdeployment isolation flag is set. By default, we don't isolate subdeployments, so that
// they can see each other's classes.
final boolean earSubDeploymentsIsolated = EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.resolveModelAttribute(context, model).asBoolean();
final boolean specDescriptorPropertyReplacement = EeSubsystemRootResource.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.resolveModelAttribute(context, model).asBoolean();
final boolean jbossDescriptorPropertyReplacement = EeSubsystemRootResource.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.resolveModelAttribute(context, model).asBoolean();
final boolean ejbAnnotationPropertyReplacement = EeSubsystemRootResource.ANNOTATION_PROPERTY_REPLACEMENT.resolveModelAttribute(context, model).asBoolean();
moduleDependencyProcessor.setGlobalModules(GlobalModulesDefinition.createModuleList(context, globalModules));
isolationProcessor.setEarSubDeploymentsIsolated(earSubDeploymentsIsolated);
specDescriptorPropertyReplacementProcessor.setDescriptorPropertyReplacement(specDescriptorPropertyReplacement);
jbossDescriptorPropertyReplacementProcessor.setDescriptorPropertyReplacement(jbossDescriptorPropertyReplacement);
ejbAnnotationPropertyReplacementProcessor.setDescriptorPropertyReplacement(ejbAnnotationPropertyReplacement);
CapabilityServiceSupport capabilitySupport = context.getCapabilityServiceSupport();
final boolean elytronJacc = capabilitySupport.hasCapability(ELYTRON_JACC_CAPABILITY);
final boolean legacyJacc = !elytronJacc && capabilitySupport.hasCapability(LEGACY_JACC_CAPABILITY);
context.addStep(new AbstractDeploymentChainStep() {
protected void execute(DeploymentProcessorTarget processorTarget) {
ROOT_LOGGER.debug("Activating EE subsystem");
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EE_DEPLOYMENT_PROPERTIES, new DeploymentPropertiesProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EE_DEPLOYMENT_PROPERTY_RESOLVER, new DeploymentPropertyResolverProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EE_PROPERTY_RESOLVER, new PropertyResolverProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_REGISTER_JBOSS_ALL_EE_APP, new JBossAllXmlParserRegisteringProcessor<JBossAppMetaData>(AppJBossAllParser.ROOT_ELEMENT, AppJBossAllParser.ATTACHMENT_KEY, new AppJBossAllParser()));
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EE_SPEC_DESC_PROPERTY_REPLACEMENT, specDescriptorPropertyReplacementProcessor);
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EE_JBOSS_DESC_PROPERTY_REPLACEMENT, jbossDescriptorPropertyReplacementProcessor);
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EE_EJB_ANNOTATION_PROPERTY_REPLACEMENT, ejbAnnotationPropertyReplacementProcessor);
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EAR_DEPLOYMENT_INIT, new EarInitializationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EAR_APP_XML_PARSE, new EarMetaDataParsingProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_JBOSS_EJB_CLIENT_XML_PARSE, new EJBClientDescriptorParsingProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EJB_EAR_APPLICATION_NAME, new EarApplicationNameProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EAR, new EarStructureProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EJB_JAR_IN_EAR, new EjbJarDeploymentProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_APPLICATION_CLIENT_IN_EAR, new ApplicationClientDeploymentProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_MANAGED_BEAN_JAR_IN_EAR, new ManagedBeanSubDeploymentMarkingProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EAR_SUB_DEPLYOMENTS_ISOLATED, isolationProcessor);
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EE_MODULE_INIT, new EEModuleInitialProcessor(context.getProcessType() == ProcessType.APPLICATION_CLIENT));
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_EE_RESOURCE_INJECTION_REGISTRY, new ResourceReferenceRegistrySetupProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_GLOBAL_MODULES, moduleDependencyProcessor);
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_GLOBAL_DIRECTORIES, directoryDependencyProcessor);
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_EE_MODULE_NAME, new EEModuleNameProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_EE_ANNOTATIONS, new EEAnnotationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_LIFECYCLE_ANNOTATION, new LifecycleAnnotationParsingProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_AROUNDINVOKE_ANNOTATION, new AroundInvokeAnnotationParsingProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_DISTINCT_NAME, new EEDistinctNameProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_EAR_MESSAGE_DESTINATIONS, new EarMessageDestinationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_MANAGED_BEAN_ANNOTATION, new ManagedBeanAnnotationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_DESCRIPTOR_LIFECYCLE_METHOD_RESOLUTION, new DescriptorEnvironmentLifecycleMethodProcessor());
// TODO *FOLLOW UP* use new priorities (instead of Phase.PARSE_RESOURCE_DEF_ANNOTATION_DATA_SOURCE)
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_RESOURCE_DEF_ANNOTATION_DATA_SOURCE, new ContextServiceDefinitionAnnotationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_RESOURCE_DEF_ANNOTATION_DATA_SOURCE, new ManagedExecutorDefinitionAnnotationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_RESOURCE_DEF_ANNOTATION_DATA_SOURCE, new ManagedScheduledExecutorDefinitionAnnotationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_RESOURCE_DEF_ANNOTATION_DATA_SOURCE, new ManagedThreadFactoryDefinitionAnnotationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_EE_PERMISSIONS, new EEDefaultPermissionsProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_MANAGED_BEAN, new JavaEEDependencyProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_EE_CLASS_DESCRIPTIONS, new ApplicationClassesAggregationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_EAR_DEPENDENCY, new EarDependencyProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_INITIALIZE_IN_ORDER, new InitializeInOrderProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_INJECTION_ANNOTATION, new ResourceInjectionAnnotationParsingProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_ENV_ENTRY, new ResourceReferenceProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_INTERCEPTOR_ANNOTATIONS, new InterceptorAnnotationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_NAMING_CONTEXT, new ModuleContextProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_IN_APP_CLIENT, new InApplicationClientBindingProcessor(appclient));
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_EE_INSTANCE_NAME, new InstanceNameBindingProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_APP_NAMING_CONTEXT, new ApplicationContextProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_EE_CONCURRENT_CONTEXT, new EEConcurrentContextProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_EE_STARTUP_COUNTDOWN, new EEStartupCountdownProcessor());
// TODO *FOLLOW UP* use new priorities (instead of Phase.POST_MODULE_RESOURCE_DEF_XML_DATA_SOURCE)
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_RESOURCE_DEF_XML_DATA_SOURCE, new ContextServiceDefinitionDescriptorProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_RESOURCE_DEF_XML_DATA_SOURCE, new ManagedExecutorDefinitionDescriptorProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_RESOURCE_DEF_XML_DATA_SOURCE, new ManagedScheduledExecutorDefinitionDescriptorProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_RESOURCE_DEF_XML_DATA_SOURCE, new ManagedThreadFactoryDefinitionDescriptorProcessor());
if (legacyJacc || elytronJacc) {
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_JACC_POLICY, new JaccEarDeploymentProcessor(elytronJacc ? ELYTRON_JACC_CAPABILITY : LEGACY_JACC_CAPABILITY));
}
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_RESOLVE_MESSAGE_DESTINATIONS, new MessageDestinationResolutionProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_COMPONENT_AGGREGATION, new ComponentAggregationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_DEFAULT_BINDINGS_EE_CONCURRENCY, new EEConcurrentDefaultBindingProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_MODULE_JNDI_BINDINGS, new ModuleJndiBindingProcessor(appclient));
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_EE_MODULE_CONFIG, new EEModuleConfigurationProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_EE_COMPONENT, new ComponentInstallProcessor());
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.CLEANUP, Phase.CLEANUP_EE, new EECleanUpProcessor());
}
}, OperationContext.Stage.RUNTIME);
context.getServiceTarget().addService(ReflectiveClassIntrospector.SERVICE_NAME, new ReflectiveClassIntrospector()).install();
// installs the service which manages managed executor's hung task periodic termination
new ManagedExecutorHungTasksPeriodicTerminationService().install(context);
}
}
| 22,514 | 89.06 | 295 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/Element.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.subsystem;
import java.util.HashMap;
import java.util.Map;
/**
* Enumeration of elements used in the EE subsystem
*
* @author Stuart Douglas
*/
enum Element {
GLOBAL_MODULES(GlobalModulesDefinition.GLOBAL_MODULES),
MODULE("module"),
EAR_SUBDEPLOYMENTS_ISOLATED(EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.getXmlName()),
SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT(EeSubsystemRootResource.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.getXmlName()),
JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT(EeSubsystemRootResource.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.getXmlName()),
ANNOTATION_PROPERTY_REPLACEMENT(EeSubsystemRootResource.ANNOTATION_PROPERTY_REPLACEMENT.getXmlName()),
CONCURRENT("concurrent"),
CONTEXT_SERVICES("context-services"),
CONTEXT_SERVICE("context-service"),
MANAGED_THREAD_FACTORIES("managed-thread-factories"),
MANAGED_THREAD_FACTORY("managed-thread-factory"),
MANAGED_EXECUTOR_SERVICES("managed-executor-services"),
MANAGED_EXECUTOR_SERVICE("managed-executor-service"),
MANAGED_SCHEDULED_EXECUTOR_SERVICES("managed-scheduled-executor-services"),
MANAGED_SCHEDULED_EXECUTOR_SERVICE("managed-scheduled-executor-service"),
DEFAULT_BINDINGS("default-bindings"),
GLOBAL_DIRECTORIES("global-directories"),
DIRECTORY("directory"),
UNKNOWN(null);
private final String name;
Element(final String name) {
this.name = name;
}
/**
* Get the local name of this element.
*
* @return the local name
*/
public String getLocalName() {
return name;
}
private static final Map<String, Element> MAP;
static {
final Map<String, Element> map = new HashMap<String, Element>();
for (Element element : values()) {
final String name = element.getLocalName();
if (name != null) map.put(name, element);
}
MAP = map;
}
public static Element forName(String localName) {
final Element element = MAP.get(localName);
return element == null ? UNKNOWN : element;
}
}
| 3,124 | 32.602151 | 118 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EEJndiViewExtension.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, 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.ee.subsystem;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.structure.DeploymentType;
import org.jboss.as.ee.structure.DeploymentTypeMarker;
import org.jboss.as.naming.NamingContext;
import org.jboss.as.naming.NamingStore;
import org.jboss.as.naming.deployment.ContextNames;
import org.jboss.as.naming.management.JndiViewExtension;
import org.jboss.as.naming.management.JndiViewExtensionContext;
import org.jboss.as.naming.management.JndiViewExtensionRegistry;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.Services;
import org.jboss.as.server.deployment.SubDeploymentMarker;
import org.jboss.as.server.deployment.module.ResourceRoot;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import javax.naming.NamingException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEPLOYMENT;
/**
* @author John Bailey
*/
public class EEJndiViewExtension implements JndiViewExtension, Service<Void> {
static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("jndi-view", "extension", "ee");
private final InjectedValue<JndiViewExtensionRegistry> registry = new InjectedValue<JndiViewExtensionRegistry>();
public synchronized void start(StartContext startContext) throws StartException {
registry.getValue().addExtension(this);
}
public synchronized void stop(StopContext stopContext) {
registry.getValue().removeExtension(this);
}
public Void getValue() throws IllegalStateException, IllegalArgumentException {
return null;
}
public void execute(final JndiViewExtensionContext context) throws OperationFailedException {
final ModelNode applicationsNode = context.getResult().get("applications");
final ServiceRegistry serviceRegistry = context.getOperationContext().getServiceRegistry(false);
final Set<Resource.ResourceEntry> deploymentResource = context.getOperationContext().readResourceFromRoot(PathAddress.EMPTY_ADDRESS, false).getChildren(DEPLOYMENT);
for (final Resource.ResourceEntry entry : deploymentResource) {
final ServiceController<?> deploymentUnitServiceController = serviceRegistry.getService(ServiceName.JBOSS.append("deployment", "unit", entry.getName()));
if (deploymentUnitServiceController != null) {
final ModelNode deploymentNode = applicationsNode.get(entry.getName());
final DeploymentUnit deploymentUnit = DeploymentUnit.class.cast(deploymentUnitServiceController.getValue());
final String appName = cleanName(deploymentUnit.getName());
final ServiceName appContextName = ContextNames.contextServiceNameOfApplication(appName);
final ServiceController<?> appContextController = serviceRegistry.getService(appContextName);
if (appContextController != null) {
final NamingStore appStore = NamingStore.class.cast(appContextController.getValue());
try {
context.addEntries(deploymentNode.get("java:app"), new NamingContext(appStore, null));
} catch (NamingException e) {
throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:app", appName)));
}
}
if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
final List<ResourceRoot> roots = deploymentUnit.getAttachmentList(org.jboss.as.server.deployment.Attachments.RESOURCE_ROOTS);
if(roots != null) for(ResourceRoot root : roots) {
if(SubDeploymentMarker.isSubDeployment(root)) {
final ResourceRoot parentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
final String relativePath = root.getRoot().getPathNameRelativeTo(parentRoot.getRoot());
final ServiceName subDeploymentServiceName = Services.deploymentUnitName(deploymentUnit.getName(), relativePath);
final ServiceController<?> subDeploymentController = serviceRegistry.getService(subDeploymentServiceName);
if(subDeploymentController != null) {
final DeploymentUnit subDeploymentUnit = DeploymentUnit.class.cast(subDeploymentController.getValue());
handleModule(context, subDeploymentUnit, deploymentNode.get("modules"), serviceRegistry);
}
}
}
} else {
handleModule(context, deploymentUnit, deploymentNode.get("modules"), serviceRegistry);
}
}
}
}
private void handleModule(final JndiViewExtensionContext context, final DeploymentUnit deploymentUnit, final ModelNode modulesNode, final ServiceRegistry serviceRegistry) throws OperationFailedException {
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
// If it isn't an EE module, just return
if (moduleDescription == null) {
return;
}
final String appName = moduleDescription.getApplicationName();
final String moduleName = moduleDescription.getModuleName();
final ModelNode moduleNode = modulesNode.get(moduleDescription.getModuleName());
final ServiceName moduleContextName = ContextNames.contextServiceNameOfModule(appName, moduleName);
final ServiceController<?> moduleContextController = serviceRegistry.getService(moduleContextName);
if (moduleContextController != null) {
final NamingStore moduleStore = NamingStore.class.cast(moduleContextController.getValue());
try {
context.addEntries(moduleNode.get("java:module"), new NamingContext(moduleStore, null));
} catch (NamingException e) {
throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:module", appName, moduleName)));
}
final Collection<ComponentDescription> componentDescriptions = moduleDescription.getComponentDescriptions();
for (ComponentDescription componentDescription : componentDescriptions) {
final String componentName = componentDescription.getComponentName();
final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(appName, moduleName, componentName);
final ServiceController<?> compContextController = serviceRegistry.getService(compContextServiceName);
if (compContextController != null) {
final ModelNode componentNode = moduleNode.get("components").get(componentName);
final NamingStore compStore = NamingStore.class.cast(compContextController.getValue());
try {
context.addEntries(componentNode.get("java:comp"), new NamingContext(compStore, null));
} catch (NamingException e) {
throw new OperationFailedException(e, new ModelNode().set(EeLogger.ROOT_LOGGER.failedToRead("java:comp", appName, moduleName, componentName)));
}
}
}
}
}
private String cleanName(final String name) {
final String cleaned;
if (name.endsWith(".war") || name.endsWith(".jar") || name.endsWith(".ear") || name.endsWith(".rar")) {
cleaned = name.substring(0, name.length() - 4);
} else {
cleaned = name;
}
return cleaned;
}
public Injector<JndiViewExtensionRegistry> getRegistryInjector() {
return registry;
}
}
| 9,704 | 52.618785 | 208 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EeWriteAttributeHandler.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, 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.ee.subsystem;
import org.jboss.as.controller.AbstractWriteAttributeHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.ee.component.deployers.DefaultEarSubDeploymentsIsolationProcessor;
import org.jboss.as.ee.structure.AnnotationPropertyReplacementProcessor;
import org.jboss.as.ee.structure.DescriptorPropertyReplacementProcessor;
import org.jboss.as.ee.structure.GlobalModuleDependencyProcessor;
import org.jboss.dmr.ModelNode;
/**
* Handles the "write-attribute" operation for the EE subsystem.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public class EeWriteAttributeHandler extends AbstractWriteAttributeHandler<Void> {
private final DefaultEarSubDeploymentsIsolationProcessor isolationProcessor;
private final GlobalModuleDependencyProcessor moduleDependencyProcessor;
private final DescriptorPropertyReplacementProcessor specDescriptorPropertyReplacementProcessor;
private final DescriptorPropertyReplacementProcessor jbossDescriptorPropertyReplacementProcessor;
private final AnnotationPropertyReplacementProcessor annotationPropertyReplacementProcessor;
public EeWriteAttributeHandler(final DefaultEarSubDeploymentsIsolationProcessor isolationProcessor,
final GlobalModuleDependencyProcessor moduleDependencyProcessor,
final DescriptorPropertyReplacementProcessor specDescriptorPropertyReplacementProcessor,
final DescriptorPropertyReplacementProcessor jbossDescriptorPropertyReplacementProcessor,
final AnnotationPropertyReplacementProcessor annotationPropertyReplacementProcessor) {
super(EeSubsystemRootResource.ATTRIBUTES);
this.isolationProcessor = isolationProcessor;
this.moduleDependencyProcessor = moduleDependencyProcessor;
this.specDescriptorPropertyReplacementProcessor = specDescriptorPropertyReplacementProcessor;
this.jbossDescriptorPropertyReplacementProcessor = jbossDescriptorPropertyReplacementProcessor;
this.annotationPropertyReplacementProcessor = annotationPropertyReplacementProcessor;
}
public void registerAttributes(final ManagementResourceRegistration registry) {
for (AttributeDefinition ad : EeSubsystemRootResource.ATTRIBUTES) {
registry.registerReadWriteAttribute(ad, null, this);
}
}
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName,
ModelNode newValue, ModelNode currentValue, HandbackHolder<Void> handbackHolder) throws OperationFailedException {
applyUpdateToDeploymentUnitProcessor(context, newValue, attributeName);
return false;
}
@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName,
ModelNode valueToRestore, ModelNode valueToRevert, Void handback) throws OperationFailedException {
applyUpdateToDeploymentUnitProcessor(context, valueToRestore, attributeName);
}
private void applyUpdateToDeploymentUnitProcessor(final OperationContext context, ModelNode newValue, String attributeName) throws OperationFailedException {
if (GlobalModulesDefinition.INSTANCE.getName().equals(attributeName)) {
moduleDependencyProcessor.setGlobalModules(GlobalModulesDefinition.createModuleList(context, newValue));
} else if (EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.getName().equals(attributeName)) {
boolean isolate = newValue.asBoolean();
isolationProcessor.setEarSubDeploymentsIsolated(isolate);
} else if (EeSubsystemRootResource.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.getName().equals(attributeName)) {
boolean enabled = newValue.asBoolean();
specDescriptorPropertyReplacementProcessor.setDescriptorPropertyReplacement(enabled);
} else if (EeSubsystemRootResource.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.getName().equals(attributeName)) {
boolean enabled = newValue.asBoolean();
jbossDescriptorPropertyReplacementProcessor.setDescriptorPropertyReplacement(enabled);
} else if(EeSubsystemRootResource.ANNOTATION_PROPERTY_REPLACEMENT.getName().equals(attributeName)){
boolean enabled = newValue.asBoolean();
annotationPropertyReplacementProcessor.setDescriptorPropertyReplacement(enabled);
}
}
}
| 5,794 | 56.376238 | 161 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ManagedExecutorServiceResourceDefinition.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.subsystem;
import org.glassfish.enterprise.concurrent.AbstractManagedExecutorService;
import org.glassfish.enterprise.concurrent.ManagedExecutorServiceAdapter;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
import org.jboss.as.controller.ServiceRemoveStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.client.helpers.MeasurementUnit;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.operations.validation.EnumValidator;
import org.jboss.as.controller.operations.validation.IntRangeValidator;
import org.jboss.as.controller.operations.validation.LongRangeValidator;
import org.jboss.as.controller.operations.validation.StringLengthValidator;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.transform.description.DiscardAttributeChecker;
import org.jboss.as.controller.transform.description.RejectAttributeChecker;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.as.ee.concurrent.service.ManagedExecutorServiceService;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* @author Eduardo Martins
*/
public class ManagedExecutorServiceResourceDefinition extends SimpleResourceDefinition {
/**
* the resource definition's dynamic runtime capability
*/
public static final RuntimeCapability<Void> CAPABILITY = RuntimeCapability.Builder.of("org.wildfly.ee.concurrent.executor", true, ManagedExecutorServiceAdapter.class)
.build();
public static final String JNDI_NAME = "jndi-name";
public static final String CONTEXT_SERVICE = "context-service";
public static final String THREAD_FACTORY = "thread-factory";
public static final String THREAD_PRIORITY = "thread-priority";
public static final String HUNG_TASK_TERMINATION_PERIOD = "hung-task-termination-period";
public static final String HUNG_TASK_THRESHOLD = "hung-task-threshold";
public static final String LONG_RUNNING_TASKS = "long-running-tasks";
public static final String CORE_THREADS = "core-threads";
public static final String MAX_THREADS = "max-threads";
public static final String KEEPALIVE_TIME = "keepalive-time";
public static final String QUEUE_LENGTH = "queue-length";
public static final String REJECT_POLICY = "reject-policy";
public static final SimpleAttributeDefinition JNDI_NAME_AD =
new SimpleAttributeDefinitionBuilder(JNDI_NAME, ModelType.STRING, false)
.setAllowExpression(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition CONTEXT_SERVICE_AD =
new SimpleAttributeDefinitionBuilder(CONTEXT_SERVICE, ModelType.STRING, true)
.setAllowExpression(false)
.setValidator(new StringLengthValidator(0, true))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setCapabilityReference(ContextServiceResourceDefinition.CAPABILITY.getName(), CAPABILITY)
.build();
public static final SimpleAttributeDefinition THREAD_FACTORY_AD =
new SimpleAttributeDefinitionBuilder(THREAD_FACTORY, ModelType.STRING, true)
.setAllowExpression(false)
.setValidator(new StringLengthValidator(0, true))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setCapabilityReference(ManagedThreadFactoryResourceDefinition.CAPABILITY.getName(), CAPABILITY)
.setDeprecated(EESubsystemModel.Version.v5_0_0)
.setAlternatives(THREAD_PRIORITY)
.build();
public static final SimpleAttributeDefinition THREAD_PRIORITY_AD =
new SimpleAttributeDefinitionBuilder(THREAD_PRIORITY, ModelType.INT, true)
.setAllowExpression(true)
.setValidator(new IntRangeValidator(Thread.MIN_PRIORITY, Thread.MAX_PRIORITY, true, true))
.setDefaultValue(new ModelNode(Thread.NORM_PRIORITY))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setAlternatives(THREAD_FACTORY)
.build();
public static final SimpleAttributeDefinition HUNG_TASK_TERMINATION_PERIOD_AD =
new SimpleAttributeDefinitionBuilder(HUNG_TASK_TERMINATION_PERIOD, ModelType.LONG, true)
.setAllowExpression(true)
.setValidator(new LongRangeValidator(0, Long.MAX_VALUE, true, true))
.setMeasurementUnit(MeasurementUnit.MILLISECONDS)
.setDefaultValue(ModelNode.ZERO)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition HUNG_TASK_THRESHOLD_AD =
new SimpleAttributeDefinitionBuilder(HUNG_TASK_THRESHOLD, ModelType.LONG, true)
.setAllowExpression(true)
.setValidator(new LongRangeValidator(0, Long.MAX_VALUE, true, true))
.setMeasurementUnit(MeasurementUnit.MILLISECONDS)
.setDefaultValue(ModelNode.ZERO)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition LONG_RUNNING_TASKS_AD =
new SimpleAttributeDefinitionBuilder(LONG_RUNNING_TASKS, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition CORE_THREADS_AD =
new SimpleAttributeDefinitionBuilder(CORE_THREADS, ModelType.INT, true)
.setAllowExpression(true)
.setValidator(new IntRangeValidator(0, Integer.MAX_VALUE, true, true))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition MAX_THREADS_AD =
new SimpleAttributeDefinitionBuilder(MAX_THREADS, ModelType.INT, true)
.setAllowExpression(true)
.setValidator(new IntRangeValidator(0, Integer.MAX_VALUE, true, true))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition KEEPALIVE_TIME_AD =
new SimpleAttributeDefinitionBuilder(KEEPALIVE_TIME, ModelType.LONG, true)
.setAllowExpression(true)
.setValidator(new LongRangeValidator(0, Long.MAX_VALUE, true, true))
.setMeasurementUnit(MeasurementUnit.MILLISECONDS)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setDefaultValue(new ModelNode(60000))
.build();
public static final SimpleAttributeDefinition QUEUE_LENGTH_AD =
new SimpleAttributeDefinitionBuilder(QUEUE_LENGTH, ModelType.INT, true)
.setAllowExpression(true)
.setValidator(new IntRangeValidator(0, Integer.MAX_VALUE, true, true))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition REJECT_POLICY_AD =
new SimpleAttributeDefinitionBuilder(REJECT_POLICY, ModelType.STRING, true)
.setAllowExpression(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setDefaultValue(new ModelNode(AbstractManagedExecutorService.RejectPolicy.ABORT.toString()))
.setValidator(EnumValidator.create(AbstractManagedExecutorService.RejectPolicy.class))
.build();
static final SimpleAttributeDefinition[] ATTRIBUTES = {JNDI_NAME_AD, CONTEXT_SERVICE_AD, THREAD_FACTORY_AD, THREAD_PRIORITY_AD, HUNG_TASK_TERMINATION_PERIOD_AD, HUNG_TASK_THRESHOLD_AD, LONG_RUNNING_TASKS_AD, CORE_THREADS_AD, MAX_THREADS_AD, KEEPALIVE_TIME_AD, QUEUE_LENGTH_AD, REJECT_POLICY_AD};
public static final PathElement PATH_ELEMENT = PathElement.pathElement(EESubsystemModel.MANAGED_EXECUTOR_SERVICE);
private static final ResourceDescriptionResolver RESOLVER = EeExtension.getResourceDescriptionResolver(EESubsystemModel.MANAGED_EXECUTOR_SERVICE);
/**
* metrics op step handler
*/
private static final ManagedExecutorServiceMetricsHandler METRICS_HANDLER = new ManagedExecutorServiceMetricsHandler.Builder<ManagedExecutorServiceService>(CAPABILITY)
.addMetric(ManagedExecutorServiceMetricsAttributes.ACTIVE_THREAD_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getActiveThreadsCount()))
.addMetric(ManagedExecutorServiceMetricsAttributes.COMPLETED_TASK_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getCompletedTaskCount()))
.addMetric(ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getQueueSize()))
.addMetric(ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getHungThreadsCount()))
.addMetric(ManagedExecutorServiceMetricsAttributes.MAX_THREAD_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getMaxThreadsCount()))
.addMetric(ManagedExecutorServiceMetricsAttributes.TASK_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getTaskCount()))
.addMetric(ManagedExecutorServiceMetricsAttributes.THREAD_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getThreadsCount()))
.build();
/**
* terminate hung threads op
*/
private static final ManagedExecutorTerminateHungTasksOperation<ManagedExecutorServiceService> TERMINATE_HUNG_TASKS_OP = new ManagedExecutorTerminateHungTasksOperation<>(CAPABILITY, RESOLVER, service -> service.getExecutorService());
/**
*
*/
private final boolean registerRuntimeOnly;
ManagedExecutorServiceResourceDefinition(boolean registerRuntimeOnly) {
super(new SimpleResourceDefinition.Parameters(PATH_ELEMENT, RESOLVER)
.setAddHandler(ManagedExecutorServiceAdd.INSTANCE)
.setRemoveHandler(new ServiceRemoveStepHandler(ManagedExecutorServiceAdd.INSTANCE))
.addCapabilities(CAPABILITY));
this.registerRuntimeOnly = registerRuntimeOnly;
}
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
super.registerOperations(resourceRegistration);
TERMINATE_HUNG_TASKS_OP.registerOperation(resourceRegistration);
}
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
OperationStepHandler writeHandler = new ValidatingWriteHandler(ATTRIBUTES);
for (AttributeDefinition attr : ATTRIBUTES) {
resourceRegistration.registerReadWriteAttribute(attr, null, writeHandler);
}
if (registerRuntimeOnly) {
METRICS_HANDLER.registerAttributes(resourceRegistration);
}
}
static void registerTransformers_4_0(final ResourceTransformationDescriptionBuilder builder) {
final ResourceTransformationDescriptionBuilder resourceBuilder = builder.addChildResource(PATH_ELEMENT);
resourceBuilder.getAttributeBuilder()
.addRejectCheck(RejectAttributeChecker.UNDEFINED, CORE_THREADS_AD)
.end();
}
static void registerTransformers5_0(final ResourceTransformationDescriptionBuilder builder) {
final ResourceTransformationDescriptionBuilder resourceBuilder = builder.addChildResource(PATH_ELEMENT);
resourceBuilder.getAttributeBuilder()
.setDiscard(DiscardAttributeChecker.UNDEFINED, THREAD_PRIORITY_AD)
.addRejectCheck(RejectAttributeChecker.DEFINED, THREAD_PRIORITY_AD)
.end();
}
static void registerTransformers6_0(final ResourceTransformationDescriptionBuilder builder) {
final ResourceTransformationDescriptionBuilder resourceBuilder = builder.addChildResource(PATH_ELEMENT);
resourceBuilder.getAttributeBuilder()
.setDiscard(DiscardAttributeChecker.UNDEFINED, HUNG_TASK_TERMINATION_PERIOD_AD)
.addRejectCheck(RejectAttributeChecker.DEFINED, HUNG_TASK_TERMINATION_PERIOD_AD)
.end();
}
static class ValidatingWriteHandler extends ReloadRequiredWriteAttributeHandler {
public ValidatingWriteHandler(final AttributeDefinition... definitions) {
super(definitions);
}
@Override
protected void validateUpdatedModel(final OperationContext context, final Resource model) throws OperationFailedException {
context.addStep(ExecutorQueueValidationStepHandler.MODEL_VALIDATION_INSTANCE, OperationContext.Stage.MODEL);
super.validateUpdatedModel(context, model);
}
}
static class ExecutorQueueValidationStepHandler implements OperationStepHandler {
static final ExecutorQueueValidationStepHandler MODEL_VALIDATION_INSTANCE = new ExecutorQueueValidationStepHandler(false);
private final boolean isRuntimeStage;
private ExecutorQueueValidationStepHandler(final boolean isRuntimeStage) {
this.isRuntimeStage = isRuntimeStage;
}
@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
final ModelNode coreThreads;
final ModelNode maxThreads;
final ModelNode queueLength;
if (isRuntimeStage) {
coreThreads = CORE_THREADS_AD.resolveModelAttribute(context, model);
maxThreads = MAX_THREADS_AD.resolveModelAttribute(context, model);
queueLength = QUEUE_LENGTH_AD.resolveModelAttribute(context, model);
} else {
coreThreads = model.get(CORE_THREADS);
maxThreads = model.get(MAX_THREADS);
queueLength = model.get(QUEUE_LENGTH);
}
if (coreThreads.getType() == ModelType.EXPRESSION
|| maxThreads.getType() == ModelType.EXPRESSION
|| queueLength.getType() == ModelType.EXPRESSION) {
context.addStep(new ExecutorQueueValidationStepHandler(true), OperationContext.Stage.RUNTIME, true);
return;
}
// Validate an unbounded queue
if ((!queueLength.isDefined() || queueLength.asInt() == Integer.MAX_VALUE)
&& coreThreads.isDefined()
&& coreThreads.asInt() <= 0) {
throw EeLogger.ROOT_LOGGER.invalidCoreThreadsSize(queueLength.asString());
}
// Validate a hand-off queue
if (queueLength.isDefined()
&& queueLength.asInt() == 0
&& coreThreads.isDefined()
&& coreThreads.asInt() <= 0) {
throw EeLogger.ROOT_LOGGER.invalidCoreThreadsSize(queueLength.asString());
}
// max-threads must be defined and greater than 0 if core-threads is 0
if (coreThreads.isDefined()
&& coreThreads.asInt() == 0
&& (!maxThreads.isDefined() || maxThreads.asInt() <= 0)) {
throw EeLogger.ROOT_LOGGER.invalidMaxThreads(maxThreads.isDefined() ? maxThreads.asInt() : 0,
coreThreads.asInt());
}
// max-threads must be greater than or equal to core-threads
if (coreThreads.isDefined()
&& maxThreads.isDefined()
&& maxThreads.asInt() < coreThreads.asInt()) {
throw EeLogger.ROOT_LOGGER.invalidMaxThreads(maxThreads.asInt(), coreThreads.asInt());
}
}
}
}
| 18,434 | 55.204268 | 299 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EESubsystemParser50.java | /*
* Copyright 2015 Red Hat, Inc.
*
* 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.jboss.as.ee.subsystem;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.parsing.ParseUtils.missingRequired;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoAttributes;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoContent;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement;
/**
*/
class EESubsystemParser50 implements XMLStreamConstants, XMLElementReader<List<ModelNode>> {
EESubsystemParser50() {
}
/**
* {@inheritDoc}
*/
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
// EE subsystem doesn't have any attributes, so make sure that the xml doesn't have any
requireNoAttributes(reader);
final PathAddress subsystemPathAddress = PathAddress.pathAddress(EeExtension.PATH_SUBSYSTEM);
final ModelNode eeSubSystem = Util.createAddOperation(subsystemPathAddress);
// add the subsystem to the ModelNode(s)
list.add(eeSubSystem);
// elements
final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Namespace.forUri(reader.getNamespaceURI())) {
case EE_5_0: {
final Element element = Element.forName(reader.getLocalName());
if (!encountered.add(element)) {
throw unexpectedElement(reader);
}
switch (element) {
case GLOBAL_MODULES: {
final ModelNode model = parseGlobalModules(reader);
eeSubSystem.get(GlobalModulesDefinition.GLOBAL_MODULES).set(model);
break;
}
case GLOBAL_DIRECTORIES: {
parseGlobalDirectories(reader, list, subsystemPathAddress);
break;
}
case EAR_SUBDEPLOYMENTS_ISOLATED: {
final String earSubDeploymentsIsolated = parseEarSubDeploymentsIsolatedElement(reader);
// set the ear subdeployment isolation on the subsystem operation
EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.parseAndSetParameter(earSubDeploymentsIsolated, eeSubSystem, reader);
break;
}
case SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseSpecDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseJBossDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case ANNOTATION_PROPERTY_REPLACEMENT: {
final String enabled = parseEJBAnnotationPropertyReplacement(reader);
EeSubsystemRootResource.ANNOTATION_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case CONCURRENT: {
parseConcurrent(reader, list, subsystemPathAddress);
break;
}
case DEFAULT_BINDINGS: {
parseDefaultBindings(reader, list, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
static ModelNode parseGlobalModules(XMLExtendedStreamReader reader) throws XMLStreamException {
ModelNode globalModules = new ModelNode();
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MODULE: {
final ModelNode module = new ModelNode();
final int count = reader.getAttributeCount();
String name = null;
String slot = null;
String annotations = null;
String metaInf = null;
String services = null;
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME:
if (name != null) {
throw unexpectedAttribute(reader, i);
}
name = value;
GlobalModulesDefinition.NAME_AD.parseAndSetParameter(name, module, reader);
break;
case SLOT:
if (slot != null) {
throw unexpectedAttribute(reader, i);
}
slot = value;
GlobalModulesDefinition.SLOT_AD.parseAndSetParameter(slot, module, reader);
break;
case ANNOTATIONS:
if (annotations != null) {
throw unexpectedAttribute(reader, i);
}
annotations = value;
GlobalModulesDefinition.ANNOTATIONS_AD.parseAndSetParameter(annotations, module, reader);
break;
case SERVICES:
if (services != null) {
throw unexpectedAttribute(reader, i);
}
services = value;
GlobalModulesDefinition.SERVICES_AD.parseAndSetParameter(services, module, reader);
break;
case META_INF:
if (metaInf != null) {
throw unexpectedAttribute(reader, i);
}
metaInf = value;
GlobalModulesDefinition.META_INF_AD.parseAndSetParameter(metaInf, module, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (name == null) {
throw missingRequired(reader, Collections.singleton(NAME));
}
globalModules.add(module);
requireNoContent(reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
return globalModules;
}
static String parseEarSubDeploymentsIsolatedElement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.EAR_SUBDEPLOYMENTS_ISOLATED.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseSpecDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseJBossDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseEJBAnnotationPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
return value.trim();
}
static void parseConcurrent(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case CONTEXT_SERVICES: {
parseContextServices(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_THREAD_FACTORIES: {
parseManagedThreadFactories(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_EXECUTOR_SERVICES: {
parseManagedExecutorServices(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_SCHEDULED_EXECUTOR_SERVICES: {
parseManagedScheduledExecutorServices(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
static void parseContextServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case CONTEXT_SERVICE: {
empty = false;
parseContextService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.CONTEXT_SERVICE));
}
}
static void parseContextService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ContextServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case USE_TRANSACTION_SETUP_PROVIDER:
ContextServiceResourceDefinition.USE_TRANSACTION_SETUP_PROVIDER_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.CONTEXT_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedThreadFactories(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_THREAD_FACTORY: {
empty = false;
parseManagedThreadFactory(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_THREAD_FACTORY));
}
}
static void parseManagedThreadFactory(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedThreadFactoryResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedThreadFactoryResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case PRIORITY:
ManagedThreadFactoryResourceDefinition.PRIORITY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_THREAD_FACTORY, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedExecutorServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_EXECUTOR_SERVICE: {
empty = false;
parseManagedExecutorService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_EXECUTOR_SERVICE));
}
}
static void parseManagedExecutorService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedExecutorServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedExecutorServiceResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_FACTORY:
ManagedExecutorServiceResourceDefinition.THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_PRIORITY:
ManagedExecutorServiceResourceDefinition.THREAD_PRIORITY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case HUNG_TASK_THRESHOLD:
ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.parseAndSetParameter(value, addOperation, reader);
break;
case LONG_RUNNING_TASKS:
ManagedExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CORE_THREADS:
ManagedExecutorServiceResourceDefinition.CORE_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MAX_THREADS:
ManagedExecutorServiceResourceDefinition.MAX_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case KEEPALIVE_TIME:
ManagedExecutorServiceResourceDefinition.KEEPALIVE_TIME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case QUEUE_LENGTH:
ManagedExecutorServiceResourceDefinition.QUEUE_LENGTH_AD.parseAndSetParameter(value, addOperation, reader);
break;
case REJECT_POLICY:
ManagedExecutorServiceResourceDefinition.REJECT_POLICY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedScheduledExecutorServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_SCHEDULED_EXECUTOR_SERVICE: {
empty = false;
parseManagedScheduledExecutorService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_SCHEDULED_EXECUTOR_SERVICE));
}
}
static void parseManagedScheduledExecutorService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedScheduledExecutorServiceResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_FACTORY:
ManagedScheduledExecutorServiceResourceDefinition.THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_PRIORITY:
ManagedScheduledExecutorServiceResourceDefinition.THREAD_PRIORITY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case HUNG_TASK_THRESHOLD:
ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.parseAndSetParameter(value, addOperation, reader);
break;
case LONG_RUNNING_TASKS:
ManagedScheduledExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CORE_THREADS:
ManagedScheduledExecutorServiceResourceDefinition.CORE_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case KEEPALIVE_TIME:
ManagedScheduledExecutorServiceResourceDefinition.KEEPALIVE_TIME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case REJECT_POLICY:
ManagedScheduledExecutorServiceResourceDefinition.REJECT_POLICY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseDefaultBindings(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case CONTEXT_SERVICE:
DefaultBindingsResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case DATASOURCE:
DefaultBindingsResourceDefinition.DATASOURCE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case JMS_CONNECTION_FACTORY:
DefaultBindingsResourceDefinition.JMS_CONNECTION_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_EXECUTOR_SERVICE:
DefaultBindingsResourceDefinition.MANAGED_EXECUTOR_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_SCHEDULED_EXECUTOR_SERVICE:
DefaultBindingsResourceDefinition.MANAGED_SCHEDULED_EXECUTOR_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_THREAD_FACTORY:
DefaultBindingsResourceDefinition.MANAGED_THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.DEFAULT_BINDINGS_PATH);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseGlobalDirectories(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case DIRECTORY: {
empty = false;
parseDirectory(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.DIRECTORY));
}
}
static void parseDirectory(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.PATH);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case PATH:
GlobalDirectoryResourceDefinition.PATH.parseAndSetParameter(value, addOperation, reader);
break;
case RELATIVE_TO:
GlobalDirectoryResourceDefinition.RELATIVE_TO.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.GLOBAL_DIRECTORY, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
}
| 30,336 | 47.38437 | 175 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EeSubsystemRootResource.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.subsystem;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.RuntimePackageDependency;
import org.jboss.as.ee.component.deployers.DefaultEarSubDeploymentsIsolationProcessor;
import org.jboss.as.ee.structure.AnnotationPropertyReplacementProcessor;
import org.jboss.as.ee.structure.Attachments;
import org.jboss.as.ee.structure.DescriptorPropertyReplacementProcessor;
import org.jboss.as.ee.structure.GlobalDirectoryDependencyProcessor;
import org.jboss.as.ee.structure.GlobalModuleDependencyProcessor;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* {@link org.jboss.as.controller.ResourceDefinition} for the EE subsystem's root management resource.
*
* @author Stuart Douglas
*/
public class EeSubsystemRootResource extends SimpleResourceDefinition {
public static final String WILDFLY_NAMING = "org.wildfly.naming";
public static final String JBOSS_INVOCATION = "org.jboss.invocation";
public static final String JSON_API = "jakarta.json.api";
public static final String GLASSFISH_EL = "org.glassfish.javax.el";
public static final SimpleAttributeDefinition EAR_SUBDEPLOYMENTS_ISOLATED =
new SimpleAttributeDefinitionBuilder(EESubsystemModel.EAR_SUBDEPLOYMENTS_ISOLATED, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(ModelNode.FALSE)
.build();
public static final SimpleAttributeDefinition SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT =
new SimpleAttributeDefinitionBuilder(EESubsystemModel.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(ModelNode.TRUE)
.build();
public static final SimpleAttributeDefinition JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT =
new SimpleAttributeDefinitionBuilder(EESubsystemModel.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(ModelNode.TRUE)
.build();
public static final SimpleAttributeDefinition ANNOTATION_PROPERTY_REPLACEMENT =
new SimpleAttributeDefinitionBuilder(EESubsystemModel.ANNOTATION_PROPERTY_REPLACEMENT, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(ModelNode.FALSE)
.build();
static final AttributeDefinition[] ATTRIBUTES = {GlobalModulesDefinition.INSTANCE, EAR_SUBDEPLOYMENTS_ISOLATED,
SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT, JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT, ANNOTATION_PROPERTY_REPLACEMENT};
// Our different operation handlers manipulate the state of the subsystem's DUPs, so they need to share a ref
private final DefaultEarSubDeploymentsIsolationProcessor isolationProcessor = new DefaultEarSubDeploymentsIsolationProcessor();
private final GlobalModuleDependencyProcessor moduleDependencyProcessor = new GlobalModuleDependencyProcessor();
private final GlobalDirectoryDependencyProcessor directoryDependencyProcessor = new GlobalDirectoryDependencyProcessor();
private final DescriptorPropertyReplacementProcessor specDescriptorPropertyReplacementProcessor = new DescriptorPropertyReplacementProcessor(Attachments.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT);
private final DescriptorPropertyReplacementProcessor jbossDescriptorPropertyReplacementProcessor = new DescriptorPropertyReplacementProcessor(Attachments.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT);
private final AnnotationPropertyReplacementProcessor annotationPropertyReplacementProcessor = new AnnotationPropertyReplacementProcessor(Attachments.ANNOTATION_PROPERTY_REPLACEMENT);
private EeSubsystemRootResource() {
super(EeExtension.PATH_SUBSYSTEM,
EeExtension.getResourceDescriptionResolver(EeExtension.SUBSYSTEM_NAME),
null,
ReloadRequiredRemoveStepHandler.INSTANCE
);
}
@Override
public void registerOperations(final ManagementResourceRegistration rootResourceRegistration) {
super.registerOperations(rootResourceRegistration);
final EeSubsystemAdd subsystemAdd = new EeSubsystemAdd(isolationProcessor, moduleDependencyProcessor,
specDescriptorPropertyReplacementProcessor,
jbossDescriptorPropertyReplacementProcessor,
annotationPropertyReplacementProcessor,
directoryDependencyProcessor
);
registerAddOperation(rootResourceRegistration, subsystemAdd);
}
@Override
public void registerAttributes(final ManagementResourceRegistration rootResourceRegistration) {
EeWriteAttributeHandler writeHandler = new EeWriteAttributeHandler(isolationProcessor, moduleDependencyProcessor,
specDescriptorPropertyReplacementProcessor, jbossDescriptorPropertyReplacementProcessor, annotationPropertyReplacementProcessor);
writeHandler.registerAttributes(rootResourceRegistration);
}
protected static EeSubsystemRootResource create(){
return new EeSubsystemRootResource();
}
@Override
public void registerAdditionalRuntimePackages(ManagementResourceRegistration resourceRegistration) {
resourceRegistration.registerAdditionalRuntimePackages(RuntimePackageDependency.required(WILDFLY_NAMING),
RuntimePackageDependency.required(JBOSS_INVOCATION),
RuntimePackageDependency.optional(JSON_API),
RuntimePackageDependency.optional(GLASSFISH_EL));
}
}
| 6,989 | 54.47619 | 197 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EESubsystemParser20.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, 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.ee.subsystem;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.parsing.ParseUtils.*;
/**
*/
class EESubsystemParser20 implements XMLStreamConstants, XMLElementReader<List<ModelNode>> {
EESubsystemParser20() {
}
/**
* {@inheritDoc}
*/
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
// EE subsystem doesn't have any attributes, so make sure that the xml doesn't have any
requireNoAttributes(reader);
final PathAddress subsystemPathAddress = PathAddress.pathAddress(EeExtension.PATH_SUBSYSTEM);
final ModelNode eeSubSystem = Util.createAddOperation(subsystemPathAddress);
// add the subsystem to the ModelNode(s)
list.add(eeSubSystem);
// elements
final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Namespace.forUri(reader.getNamespaceURI())) {
case EE_2_0:
case EE_3_0: {
final Element element = Element.forName(reader.getLocalName());
if (!encountered.add(element)) {
throw unexpectedElement(reader);
}
switch (element) {
case GLOBAL_MODULES: {
final ModelNode model = parseGlobalModules(reader);
eeSubSystem.get(GlobalModulesDefinition.GLOBAL_MODULES).set(model);
break;
}
case EAR_SUBDEPLOYMENTS_ISOLATED: {
final String earSubDeploymentsIsolated = parseEarSubDeploymentsIsolatedElement(reader);
// set the ear subdeployment isolation on the subsystem operation
EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.parseAndSetParameter(earSubDeploymentsIsolated, eeSubSystem, reader);
break;
}
case SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseSpecDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseJBossDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case ANNOTATION_PROPERTY_REPLACEMENT: {
final String enabled = parseEJBAnnotationPropertyReplacement(reader);
EeSubsystemRootResource.ANNOTATION_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case CONCURRENT: {
parseConcurrent(reader, list, subsystemPathAddress);
break;
}
case DEFAULT_BINDINGS: {
parseDefaultBindings(reader, list, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
static ModelNode parseGlobalModules(XMLExtendedStreamReader reader) throws XMLStreamException {
ModelNode globalModules = new ModelNode();
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MODULE: {
final ModelNode module = new ModelNode();
final int count = reader.getAttributeCount();
String name = null;
String slot = null;
String annotations = null;
String metaInf = null;
String services = null;
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME:
if (name != null) {
throw unexpectedAttribute(reader, i);
}
name = value;
GlobalModulesDefinition.NAME_AD.parseAndSetParameter(name, module, reader);
break;
case SLOT:
if (slot != null) {
throw unexpectedAttribute(reader, i);
}
slot = value;
GlobalModulesDefinition.SLOT_AD.parseAndSetParameter(slot, module, reader);
break;
case ANNOTATIONS:
if (annotations != null) {
throw unexpectedAttribute(reader, i);
}
annotations = value;
GlobalModulesDefinition.ANNOTATIONS_AD.parseAndSetParameter(annotations, module, reader);
break;
case SERVICES:
if (services != null) {
throw unexpectedAttribute(reader, i);
}
services = value;
GlobalModulesDefinition.SERVICES_AD.parseAndSetParameter(services, module, reader);
break;
case META_INF:
if (metaInf != null) {
throw unexpectedAttribute(reader, i);
}
metaInf = value;
GlobalModulesDefinition.META_INF_AD.parseAndSetParameter(metaInf, module, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (name == null) {
throw missingRequired(reader, Collections.singleton(NAME));
}
globalModules.add(module);
requireNoContent(reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
return globalModules;
}
static String parseEarSubDeploymentsIsolatedElement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.EAR_SUBDEPLOYMENTS_ISOLATED.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseSpecDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseJBossDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseEJBAnnotationPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
return value.trim();
}
static void parseConcurrent(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case CONTEXT_SERVICES: {
parseContextServices(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_THREAD_FACTORIES: {
parseManagedThreadFactories(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_EXECUTOR_SERVICES: {
parseManagedExecutorServices(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_SCHEDULED_EXECUTOR_SERVICES: {
parseManagedScheduledExecutorServices(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
static void parseContextServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case CONTEXT_SERVICE: {
empty = false;
parseContextService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if(empty) {
throw missingRequired(reader, EnumSet.of(Element.CONTEXT_SERVICE));
}
}
static void parseContextService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ContextServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case USE_TRANSACTION_SETUP_PROVIDER:
ContextServiceResourceDefinition.USE_TRANSACTION_SETUP_PROVIDER_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.CONTEXT_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedThreadFactories(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_THREAD_FACTORY: {
empty = false;
parseManagedThreadFactory(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if(empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_THREAD_FACTORY));
}
}
static void parseManagedThreadFactory(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedThreadFactoryResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedThreadFactoryResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case PRIORITY:
ManagedThreadFactoryResourceDefinition.PRIORITY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_THREAD_FACTORY, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedExecutorServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_EXECUTOR_SERVICE: {
empty = false;
parseManagedExecutorService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if(empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_EXECUTOR_SERVICE));
}
}
static void parseManagedExecutorService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME, Attribute.CORE_THREADS);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedExecutorServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedExecutorServiceResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_FACTORY:
ManagedScheduledExecutorServiceResourceDefinition.THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case HUNG_TASK_THRESHOLD:
ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.parseAndSetParameter(value, addOperation, reader);
break;
case LONG_RUNNING_TASKS:
ManagedExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CORE_THREADS:
ManagedExecutorServiceResourceDefinition.CORE_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MAX_THREADS:
ManagedExecutorServiceResourceDefinition.MAX_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case KEEPALIVE_TIME:
ManagedExecutorServiceResourceDefinition.KEEPALIVE_TIME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case QUEUE_LENGTH:
ManagedExecutorServiceResourceDefinition.QUEUE_LENGTH_AD.parseAndSetParameter(value, addOperation, reader);
break;
case REJECT_POLICY:
ManagedExecutorServiceResourceDefinition.REJECT_POLICY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedScheduledExecutorServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_SCHEDULED_EXECUTOR_SERVICE: {
empty = false;
parseManagedScheduledExecutorService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if(empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_SCHEDULED_EXECUTOR_SERVICE));
}
}
static void parseManagedScheduledExecutorService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME, Attribute.CORE_THREADS);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedScheduledExecutorServiceResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_FACTORY:
ManagedScheduledExecutorServiceResourceDefinition.THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case HUNG_TASK_THRESHOLD:
ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.parseAndSetParameter(value, addOperation, reader);
break;
case LONG_RUNNING_TASKS:
ManagedScheduledExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CORE_THREADS:
ManagedScheduledExecutorServiceResourceDefinition.CORE_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case KEEPALIVE_TIME:
ManagedScheduledExecutorServiceResourceDefinition.KEEPALIVE_TIME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case REJECT_POLICY:
ManagedScheduledExecutorServiceResourceDefinition.REJECT_POLICY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseDefaultBindings(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case CONTEXT_SERVICE:
DefaultBindingsResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case DATASOURCE:
DefaultBindingsResourceDefinition.DATASOURCE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case JMS_CONNECTION_FACTORY:
DefaultBindingsResourceDefinition.JMS_CONNECTION_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_EXECUTOR_SERVICE:
DefaultBindingsResourceDefinition.MANAGED_EXECUTOR_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_SCHEDULED_EXECUTOR_SERVICE:
DefaultBindingsResourceDefinition.MANAGED_SCHEDULED_EXECUTOR_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_THREAD_FACTORY:
DefaultBindingsResourceDefinition.MANAGED_THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.DEFAULT_BINDINGS_PATH);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
}
| 27,458 | 47.428571 | 175 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ManagedExecutorServiceMetricsAttributes.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2019 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.subsystem;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* The managed executor service resource's runtime metrics attribute names and definitions.
* @author emmartins
*/
public interface ManagedExecutorServiceMetricsAttributes {
String ACTIVE_THREAD_COUNT = "active-thread-count";
String COMPLETED_TASK_COUNT = "completed-task-count";
String CURRENT_QUEUE_SIZE = "current-queue-size";
String HUNG_THREAD_COUNT = "hung-thread-count";
String MAX_THREAD_COUNT = "max-thread-count";
String TASK_COUNT = "task-count";
String THREAD_COUNT = "thread-count";
AttributeDefinition ACTIVE_THREAD_COUNT_AD = new SimpleAttributeDefinitionBuilder(ACTIVE_THREAD_COUNT, ModelType.INT)
.setUndefinedMetricValue(ModelNode.ZERO)
.build();
AttributeDefinition COMPLETED_TASK_COUNT_AD = new SimpleAttributeDefinitionBuilder(COMPLETED_TASK_COUNT, ModelType.LONG)
.setUndefinedMetricValue(ModelNode.ZERO)
.build();
AttributeDefinition CURRENT_QUEUE_SIZE_AD = new SimpleAttributeDefinitionBuilder(CURRENT_QUEUE_SIZE, ModelType.INT)
.setUndefinedMetricValue(ModelNode.ZERO)
.build();
AttributeDefinition HUNG_THREAD_COUNT_AD = new SimpleAttributeDefinitionBuilder(HUNG_THREAD_COUNT, ModelType.INT)
.setUndefinedMetricValue(ModelNode.ZERO)
.build();
AttributeDefinition MAX_THREAD_COUNT_AD = new SimpleAttributeDefinitionBuilder(MAX_THREAD_COUNT, ModelType.INT)
.setUndefinedMetricValue(ModelNode.ZERO)
.build();
AttributeDefinition TASK_COUNT_AD = new SimpleAttributeDefinitionBuilder(TASK_COUNT, ModelType.LONG)
.setUndefinedMetricValue(ModelNode.ZERO)
.build();
AttributeDefinition THREAD_COUNT_AD = new SimpleAttributeDefinitionBuilder(THREAD_COUNT, ModelType.INT)
.setUndefinedMetricValue(ModelNode.ZERO)
.build();
}
| 2,798 | 44.885246 | 124 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EEStartupCountdownProcessor.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2020 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.subsystem;
import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.deployers.StartupCountdown;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
public class EEStartupCountdownProcessor implements DeploymentUnitProcessor {
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final int startupBeansCount = moduleDescription.getStartupBeansCount();
if (deploymentUnit.getParent() == null) {
deploymentUnit.putAttachment(Attachments.STARTUP_COUNTDOWN, new StartupCountdown(startupBeansCount));
} else {
final StartupCountdown countdown = deploymentUnit.getParent().getAttachment(Attachments.STARTUP_COUNTDOWN);
// copy ref to child deployment
deploymentUnit.putAttachment(Attachments.STARTUP_COUNTDOWN, countdown);
countdown.countUp(startupBeansCount);
}
}
}
| 2,129 | 46.333333 | 119 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/DefaultBindingsAdd.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.subsystem;
import static org.jboss.as.server.deployment.Phase.STRUCTURE_EE_DEFAULT_BINDINGS_CONFIG;
import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.ee.component.deployers.DefaultBindingsConfigurationProcessor;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.as.server.deployment.Phase;
import org.jboss.dmr.ModelNode;
/**
* @author Eduardo Martins
*/
public class DefaultBindingsAdd extends AbstractBoottimeAddStepHandler {
private final DefaultBindingsConfigurationProcessor defaultBindingsConfigurationProcessor;
public DefaultBindingsAdd(DefaultBindingsConfigurationProcessor defaultBindingsConfigurationProcessor) {
super(DefaultBindingsResourceDefinition.ATTRIBUTES);
this.defaultBindingsConfigurationProcessor = defaultBindingsConfigurationProcessor;
}
@Override
protected void performBoottime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
ModelNode model = resource.getModel();
if(model.hasDefined(DefaultBindingsResourceDefinition.CONTEXT_SERVICE)) {
final String contextService = DefaultBindingsResourceDefinition.CONTEXT_SERVICE_AD.resolveModelAttribute(context, model).asString();
defaultBindingsConfigurationProcessor.setContextService(contextService);
}
if(model.hasDefined(DefaultBindingsResourceDefinition.DATASOURCE)) {
final String dataSource = DefaultBindingsResourceDefinition.DATASOURCE_AD.resolveModelAttribute(context, model).asString();
defaultBindingsConfigurationProcessor.setDataSource(dataSource);
}
if(model.hasDefined(DefaultBindingsResourceDefinition.JMS_CONNECTION_FACTORY)) {
final String jmsConnectionFactory = DefaultBindingsResourceDefinition.JMS_CONNECTION_FACTORY_AD.resolveModelAttribute(context, model).asString();
defaultBindingsConfigurationProcessor.setJmsConnectionFactory(jmsConnectionFactory);
}
if(model.hasDefined(DefaultBindingsResourceDefinition.MANAGED_EXECUTOR_SERVICE)) {
final String managedExecutorService = DefaultBindingsResourceDefinition.MANAGED_EXECUTOR_SERVICE_AD.resolveModelAttribute(context, model).asString();
defaultBindingsConfigurationProcessor.setManagedExecutorService(managedExecutorService);
}
if(model.hasDefined(DefaultBindingsResourceDefinition.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
final String managedScheduledExecutorService = DefaultBindingsResourceDefinition.MANAGED_SCHEDULED_EXECUTOR_SERVICE_AD.resolveModelAttribute(context, model).asString();
defaultBindingsConfigurationProcessor.setManagedScheduledExecutorService(managedScheduledExecutorService);
}
if(model.hasDefined(DefaultBindingsResourceDefinition.MANAGED_THREAD_FACTORY)) {
final String managedThreadFactory = DefaultBindingsResourceDefinition.MANAGED_THREAD_FACTORY_AD.resolveModelAttribute(context, model).asString();
defaultBindingsConfigurationProcessor.setManagedThreadFactory(managedThreadFactory);
}
context.addStep(new AbstractDeploymentChainStep() {
protected void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(EeExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, STRUCTURE_EE_DEFAULT_BINDINGS_CONFIG, defaultBindingsConfigurationProcessor);
}
}, OperationContext.Stage.RUNTIME);
}
}
| 4,798 | 56.819277 | 180 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EESubsystemXmlPersister.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, 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.ee.subsystem;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
import org.jboss.staxmapper.XMLElementWriter;
import org.jboss.staxmapper.XMLExtendedStreamWriter;
/**
*/
class EESubsystemXmlPersister implements XMLStreamConstants, XMLElementWriter<SubsystemMarshallingContext> {
public static final EESubsystemXmlPersister INSTANCE = new EESubsystemXmlPersister();
private EESubsystemXmlPersister() {
}
/**
* {@inheritDoc}
*/
@Override
public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
context.startSubsystemElement(Namespace.CURRENT.getUriString(), false);
ModelNode eeSubSystem = context.getModelNode();
GlobalModulesDefinition.INSTANCE.marshallAsElement(eeSubSystem, writer);
writeGlobalDirectoryElement(writer, eeSubSystem);
EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.marshallAsElement(eeSubSystem, writer);
EeSubsystemRootResource.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.marshallAsElement(eeSubSystem, writer);
EeSubsystemRootResource.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.marshallAsElement(eeSubSystem, writer);
EeSubsystemRootResource.ANNOTATION_PROPERTY_REPLACEMENT.marshallAsElement(eeSubSystem, writer);
writeConcurrentElement(writer,eeSubSystem);
writeDefaultBindingsElement(writer,eeSubSystem);
writer.writeEndElement();
}
private void writeConcurrentElement(XMLExtendedStreamWriter writer, ModelNode eeSubSystem) throws XMLStreamException {
boolean started = false;
if (eeSubSystem.hasDefined(EESubsystemModel.CONTEXT_SERVICE)) {
writer.writeStartElement(Element.CONCURRENT.getLocalName());
started = true;
writeContextServices(writer, eeSubSystem.get(EESubsystemModel.CONTEXT_SERVICE));
}
if (eeSubSystem.hasDefined(EESubsystemModel.MANAGED_THREAD_FACTORY)) {
if(!started) {
writer.writeStartElement(Element.CONCURRENT.getLocalName());
started = true;
}
writeManagedThreadFactories(writer, eeSubSystem.get(EESubsystemModel.MANAGED_THREAD_FACTORY));
}
if (eeSubSystem.hasDefined(EESubsystemModel.MANAGED_EXECUTOR_SERVICE)) {
if(!started) {
writer.writeStartElement(Element.CONCURRENT.getLocalName());
started = true;
}
writeManagedExecutorServices(writer, eeSubSystem.get(EESubsystemModel.MANAGED_EXECUTOR_SERVICE));
}
if (eeSubSystem.hasDefined(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
if(!started) {
writer.writeStartElement(Element.CONCURRENT.getLocalName());
started = true;
}
writeManagedScheduledExecutorServices(writer, eeSubSystem.get(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE));
}
if(started) {
writer.writeEndElement();
}
}
private void writeContextServices(final XMLExtendedStreamWriter writer, final ModelNode subModel) throws XMLStreamException {
writer.writeStartElement(Element.CONTEXT_SERVICES.getLocalName());
for (Property property : subModel.asPropertyList()) {
writer.writeStartElement(Element.CONTEXT_SERVICE.getLocalName());
writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
for(SimpleAttributeDefinition ad : ContextServiceResourceDefinition.ATTRIBUTES) {
ad.marshallAsAttribute(property.getValue(), writer);
}
writer.writeEndElement();
}
writer.writeEndElement();
}
private void writeManagedThreadFactories(final XMLExtendedStreamWriter writer, final ModelNode subModel) throws XMLStreamException {
writer.writeStartElement(Element.MANAGED_THREAD_FACTORIES.getLocalName());
for (Property property : subModel.asPropertyList()) {
writer.writeStartElement(Element.MANAGED_THREAD_FACTORY.getLocalName());
writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
for(SimpleAttributeDefinition ad : ManagedThreadFactoryResourceDefinition.ATTRIBUTES) {
ad.marshallAsAttribute(property.getValue(), writer);
}
writer.writeEndElement();
}
writer.writeEndElement();
}
private void writeManagedExecutorServices(final XMLExtendedStreamWriter writer, final ModelNode subModel) throws XMLStreamException {
writer.writeStartElement(Element.MANAGED_EXECUTOR_SERVICES.getLocalName());
for (Property property : subModel.asPropertyList()) {
writer.writeStartElement(Element.MANAGED_EXECUTOR_SERVICE.getLocalName());
writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
for(SimpleAttributeDefinition ad : ManagedExecutorServiceResourceDefinition.ATTRIBUTES) {
ad.marshallAsAttribute(property.getValue(), writer);
}
writer.writeEndElement();
}
writer.writeEndElement();
}
private void writeManagedScheduledExecutorServices(final XMLExtendedStreamWriter writer, final ModelNode subModel) throws XMLStreamException {
writer.writeStartElement(Element.MANAGED_SCHEDULED_EXECUTOR_SERVICES.getLocalName());
for (Property property : subModel.asPropertyList()) {
writer.writeStartElement(Element.MANAGED_SCHEDULED_EXECUTOR_SERVICE.getLocalName());
writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
for(SimpleAttributeDefinition ad : ManagedScheduledExecutorServiceResourceDefinition.ATTRIBUTES) {
ad.marshallAsAttribute(property.getValue(), writer);
}
writer.writeEndElement();
}
writer.writeEndElement();
}
private void writeDefaultBindingsElement(XMLExtendedStreamWriter writer, ModelNode eeSubSystem) throws XMLStreamException {
if (eeSubSystem.hasDefined(EESubsystemModel.SERVICE) && eeSubSystem.get(EESubsystemModel.SERVICE).hasDefined(EESubsystemModel.DEFAULT_BINDINGS)) {
ModelNode defaultBindingsNode = eeSubSystem.get(EESubsystemModel.SERVICE, EESubsystemModel.DEFAULT_BINDINGS);
writer.writeStartElement(Element.DEFAULT_BINDINGS.getLocalName());
for(SimpleAttributeDefinition ad : DefaultBindingsResourceDefinition.ATTRIBUTES) {
ad.marshallAsAttribute(defaultBindingsNode,writer);
}
writer.writeEndElement();
}
}
private void writeGlobalDirectoryElement(XMLExtendedStreamWriter writer, ModelNode eeSubSystem) throws XMLStreamException {
if (eeSubSystem.hasDefined(EESubsystemModel.GLOBAL_DIRECTORY)) {
writer.writeStartElement(Element.GLOBAL_DIRECTORIES.getLocalName());
writeDirectoryElement(writer, eeSubSystem.get(EESubsystemModel.GLOBAL_DIRECTORY));
writer.writeEndElement();
}
}
private void writeDirectoryElement(final XMLExtendedStreamWriter writer, final ModelNode subModel) throws XMLStreamException {
for (Property property : subModel.asPropertyList()) {
writer.writeStartElement(Element.DIRECTORY.getLocalName());
writer.writeAttribute(Attribute.NAME.getLocalName(), property.getName());
for (SimpleAttributeDefinition ad : GlobalDirectoryResourceDefinition.ATTRIBUTES) {
ad.marshallAsAttribute(property.getValue(), writer);
}
writer.writeEndElement();
}
}
}
| 8,967 | 49.100559 | 154 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/GlobalModulesDefinition.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2011, 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.ee.subsystem;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MODULE;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.AttributeMarshaller;
import org.jboss.as.controller.ObjectListAttributeDefinition;
import org.jboss.as.controller.ObjectTypeAttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.ParameterCorrector;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.modules.ModuleIdentifier;
/**
* {@link AttributeDefinition} implementation for the "global-modules" attribute.
*
* @author Brian Stansberry (c) 2011 Red Hat Inc.
*/
public class GlobalModulesDefinition {
public static final String NAME = "name";
public static final String SLOT = "slot";
public static final String ANNOTATIONS = "annotations";
public static final String META_INF = "meta-inf";
public static final String SERVICES = "services";
public static final String GLOBAL_MODULES = "global-modules";
public static final String DEFAULT_SLOT = "main";
public static final SimpleAttributeDefinition NAME_AD = new SimpleAttributeDefinitionBuilder(NAME, ModelType.STRING).build();
public static final SimpleAttributeDefinition SLOT_AD = new SimpleAttributeDefinitionBuilder(SLOT, ModelType.STRING, true)
.setDefaultValue(new ModelNode(DEFAULT_SLOT))
.build();
public static final SimpleAttributeDefinition ANNOTATIONS_AD = new SimpleAttributeDefinitionBuilder(ANNOTATIONS, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(ModelNode.FALSE)
.build();
public static final SimpleAttributeDefinition SERVICES_AD = new SimpleAttributeDefinitionBuilder(SERVICES, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(ModelNode.FALSE)
.build();
public static final SimpleAttributeDefinition META_INF_AD = new SimpleAttributeDefinitionBuilder(META_INF, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(ModelNode.TRUE)
.build();
private static final SimpleAttributeDefinition[] VALUE_TYPE_FIELDS = { NAME_AD, SLOT_AD, ANNOTATIONS_AD, SERVICES_AD, META_INF_AD };
// TODO the default marshalling in ObjectListAttributeDefinition is not so great since it delegates each
// element to ObjectTypeAttributeDefinition, and OTAD assumes it's used for complex attributes bound in a
// ModelType.OBJECT node under key=OTAD.getName(). So provide a custom marshaller to OTAD. This could be made reusable.
private static final AttributeMarshaller VALUE_TYPE_MARSHALLER = new AttributeMarshaller() {
@Override
public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException {
if (resourceModel.isDefined()) {
writer.writeEmptyElement(Element.MODULE.getLocalName());
for (SimpleAttributeDefinition valueType : VALUE_TYPE_FIELDS) {
valueType.getMarshaller().marshall(valueType, resourceModel, true, writer);
}
}
}
};
private static final ObjectTypeAttributeDefinition VALUE_TYPE_AD =
ObjectTypeAttributeDefinition.Builder.of(MODULE, VALUE_TYPE_FIELDS)
.setAttributeMarshaller(VALUE_TYPE_MARSHALLER)
.build();
private static final ParameterCorrector DUPLICATE_CORRECTOR = new ParameterCorrector() {
@Override
public ModelNode correct(ModelNode newValue, ModelNode currentValue) {
ModelNode result = null;
if (newValue.isDefined()) {
ArrayList<ModelNode> elementSet = new ArrayList<>();
LinkedHashSet<String> identifierSet = new LinkedHashSet<>();
List<ModelNode> asList = newValue.asList();
for (int i = asList.size() -1; i >= 0; i--) {
ModelNode element = asList.get(i);
ModelNode name = element.get(GlobalModulesDefinition.NAME);
ModelNode slot = element.get(GlobalModulesDefinition.SLOT);
if (!identifierSet.add(name + ":" + slot)) {
// Leave this at debug for now. WFCORE-5070 may add a formalized i18n log message in WFLYCTL
EeLogger.ROOT_LOGGER.debugf("Removing duplicate entry %s from %s attribute %s", element.toString(), GLOBAL_MODULES);
} else {
elementSet.add(element);
}
}
if (!elementSet.isEmpty()) {
Collections.reverse(elementSet);
result = new ModelNode();
for (ModelNode element : elementSet) {
result.add(element);
}
}
}
return result == null ? newValue : result;
}
};
public static final AttributeDefinition INSTANCE = ObjectListAttributeDefinition.Builder.of(GLOBAL_MODULES, VALUE_TYPE_AD)
.setRequired(false)
.setCorrector(DUPLICATE_CORRECTOR)
.build();
public static List<GlobalModule> createModuleList(final OperationContext context, final ModelNode globalMods) throws OperationFailedException {
final List<GlobalModule> ret = new ArrayList<>();
if (globalMods.isDefined()) {
for (final ModelNode module : globalMods.asList()) {
String name = NAME_AD.resolveModelAttribute(context, module).asString();
String slot = SLOT_AD.resolveModelAttribute(context, module).asString();
boolean annotations = ANNOTATIONS_AD.resolveModelAttribute(context, module).asBoolean();
boolean services = SERVICES_AD.resolveModelAttribute(context, module).asBoolean();
boolean metaInf = META_INF_AD.resolveModelAttribute(context, module).asBoolean();
ret.add(new GlobalModule(ModuleIdentifier.create(name, slot), annotations, services, metaInf));
}
}
return ret;
}
public static final class GlobalModule {
private final ModuleIdentifier moduleIdentifier;
private final boolean annotations;
private final boolean services;
private final boolean metaInf;
GlobalModule(final ModuleIdentifier moduleIdentifier, final boolean annotations, final boolean services, final boolean metaInf) {
this.moduleIdentifier = moduleIdentifier;
this.annotations = annotations;
this.services = services;
this.metaInf = metaInf;
}
public ModuleIdentifier getModuleIdentifier() {
return moduleIdentifier;
}
public boolean isAnnotations() {
return annotations;
}
public boolean isServices() {
return services;
}
public boolean isMetaInf() {
return metaInf;
}
}
}
| 8,638 | 43.302564 | 170 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/DefaultBindingsResourceDefinition.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.subsystem;
import org.jboss.as.controller.AbstractWriteAttributeHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.ee.component.deployers.DefaultBindingsConfigurationProcessor;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* The resource definition wrt EE default bindings configuration.
* @author Eduardo Martins
*/
public class DefaultBindingsResourceDefinition extends SimpleResourceDefinition {
public static final String CONTEXT_SERVICE = "context-service";
public static final String DATASOURCE = "datasource";
public static final String JMS_CONNECTION_FACTORY = "jms-connection-factory";
public static final String MANAGED_EXECUTOR_SERVICE = "managed-executor-service";
public static final String MANAGED_SCHEDULED_EXECUTOR_SERVICE = "managed-scheduled-executor-service";
public static final String MANAGED_THREAD_FACTORY = "managed-thread-factory";
public static final SimpleAttributeDefinition CONTEXT_SERVICE_AD =
new SimpleAttributeDefinitionBuilder(CONTEXT_SERVICE, ModelType.STRING, true)
.setAllowExpression(true)
.build();
public static final SimpleAttributeDefinition DATASOURCE_AD =
new SimpleAttributeDefinitionBuilder(DATASOURCE, ModelType.STRING, true)
.setAllowExpression(true)
.build();
public static final SimpleAttributeDefinition JMS_CONNECTION_FACTORY_AD =
new SimpleAttributeDefinitionBuilder(JMS_CONNECTION_FACTORY, ModelType.STRING, true)
.setAllowExpression(true)
.build();
public static final SimpleAttributeDefinition MANAGED_EXECUTOR_SERVICE_AD =
new SimpleAttributeDefinitionBuilder(MANAGED_EXECUTOR_SERVICE, ModelType.STRING, true)
.setAllowExpression(true)
.build();
public static final SimpleAttributeDefinition MANAGED_SCHEDULED_EXECUTOR_SERVICE_AD =
new SimpleAttributeDefinitionBuilder(MANAGED_SCHEDULED_EXECUTOR_SERVICE, ModelType.STRING, true)
.setAllowExpression(true)
.build();
public static final SimpleAttributeDefinition MANAGED_THREAD_FACTORY_AD =
new SimpleAttributeDefinitionBuilder(MANAGED_THREAD_FACTORY, ModelType.STRING, true)
.setAllowExpression(true)
.build();
static final SimpleAttributeDefinition[] ATTRIBUTES = { CONTEXT_SERVICE_AD, DATASOURCE_AD, JMS_CONNECTION_FACTORY_AD, MANAGED_EXECUTOR_SERVICE_AD, MANAGED_SCHEDULED_EXECUTOR_SERVICE_AD, MANAGED_THREAD_FACTORY_AD };
private final DefaultBindingsConfigurationProcessor defaultBindingsConfigurationProcessor;
public DefaultBindingsResourceDefinition(DefaultBindingsConfigurationProcessor defaultBindingsConfigurationProcessor) {
super(EESubsystemModel.DEFAULT_BINDINGS_PATH, EeExtension.getResourceDescriptionResolver(EESubsystemModel.DEFAULT_BINDINGS), new DefaultBindingsAdd(defaultBindingsConfigurationProcessor), ReloadRequiredRemoveStepHandler.INSTANCE);
this.defaultBindingsConfigurationProcessor = defaultBindingsConfigurationProcessor;
}
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
OperationStepHandler writeHandler = new WriteAttributeHandler();
for (AttributeDefinition attr : ATTRIBUTES) {
resourceRegistration.registerReadWriteAttribute(attr, null, writeHandler);
}
}
private class WriteAttributeHandler extends AbstractWriteAttributeHandler<Void> {
private WriteAttributeHandler() {
super(DefaultBindingsResourceDefinition.ATTRIBUTES);
}
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName,
ModelNode newValue, ModelNode currentValue, HandbackHolder<Void> handbackHolder) throws OperationFailedException {
applyUpdateToDeploymentUnitProcessor(attributeName, newValue);
return false;
}
@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName,
ModelNode valueToRestore, ModelNode valueToRevert, Void handback) throws OperationFailedException {
applyUpdateToDeploymentUnitProcessor(attributeName, valueToRestore);
}
private void applyUpdateToDeploymentUnitProcessor(final String attributeName, final ModelNode newValue) throws OperationFailedException {
final String attributeValue = newValue.isDefined() ? newValue.asString() : null;
if (DefaultBindingsResourceDefinition.CONTEXT_SERVICE.equals(attributeName)) {
defaultBindingsConfigurationProcessor.setContextService(attributeValue);
} else if (DefaultBindingsResourceDefinition.DATASOURCE.equals(attributeName)) {
defaultBindingsConfigurationProcessor.setDataSource(attributeValue);
} else if (DefaultBindingsResourceDefinition.JMS_CONNECTION_FACTORY.equals(attributeName)) {
defaultBindingsConfigurationProcessor.setJmsConnectionFactory(attributeValue);
} else if (DefaultBindingsResourceDefinition.MANAGED_EXECUTOR_SERVICE.equals(attributeName)) {
defaultBindingsConfigurationProcessor.setManagedExecutorService(attributeValue);
} else if (DefaultBindingsResourceDefinition.MANAGED_SCHEDULED_EXECUTOR_SERVICE.equals(attributeName)) {
defaultBindingsConfigurationProcessor.setManagedScheduledExecutorService(attributeValue);
} else if (DefaultBindingsResourceDefinition.MANAGED_THREAD_FACTORY.equals(attributeName)) {
defaultBindingsConfigurationProcessor.setManagedThreadFactory(attributeValue);
}
}
}
}
| 7,515 | 54.674074 | 238 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EESubsystemModel.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, 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.ee.subsystem;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathElement;
/**
* @author Stuart Douglas
* @author Eduardo Martins
*/
public interface EESubsystemModel {
String EAR_SUBDEPLOYMENTS_ISOLATED = "ear-subdeployments-isolated";
String SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT = "spec-descriptor-property-replacement";
String JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT = "jboss-descriptor-property-replacement";
String ANNOTATION_PROPERTY_REPLACEMENT = "annotation-property-replacement";
String DEFAULT_BINDINGS = "default-bindings";
String CONTEXT_SERVICE = "context-service";
String MANAGED_THREAD_FACTORY = "managed-thread-factory";
String MANAGED_EXECUTOR_SERVICE = "managed-executor-service";
String MANAGED_SCHEDULED_EXECUTOR_SERVICE = "managed-scheduled-executor-service";
String SERVICE = "service";
PathElement DEFAULT_BINDINGS_PATH = PathElement.pathElement(SERVICE,DEFAULT_BINDINGS);
String GLOBAL_DIRECTORY = "global-directory";
/**
* Versions of the EE subsystem model
*/
interface Version {
ModelVersion v1_0_0 = ModelVersion.create(1, 0, 0); //EAP 6.2.0
ModelVersion v1_1_0 = ModelVersion.create(1, 1, 0);
ModelVersion v3_0_0 = ModelVersion.create(3, 0, 0);
ModelVersion v4_0_0 = ModelVersion.create(4, 0, 0);
ModelVersion v5_0_0 = ModelVersion.create(5, 0, 0);
ModelVersion v6_0_0 = ModelVersion.create(6, 0, 0);
}
}
| 2,534 | 39.238095 | 91 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ManagedThreadFactoryAdd.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.subsystem;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.glassfish.enterprise.concurrent.ContextServiceImpl;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.CapabilityServiceBuilder;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.ee.concurrent.service.ManagedThreadFactoryService;
import org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl;
import org.jboss.dmr.ModelNode;
/**
* @author Eduardo Martins
*/
public class ManagedThreadFactoryAdd extends AbstractAddStepHandler {
static final ManagedThreadFactoryAdd INSTANCE = new ManagedThreadFactoryAdd();
private ManagedThreadFactoryAdd() {
super(ManagedThreadFactoryResourceDefinition.ATTRIBUTES);
}
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final String name = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
final String jndiName = ManagedExecutorServiceResourceDefinition.JNDI_NAME_AD.resolveModelAttribute(context, model).asString();
final int priority = ManagedThreadFactoryResourceDefinition.PRIORITY_AD.resolveModelAttribute(context, model).asInt();
final CapabilityServiceBuilder serviceBuilder = context.getCapabilityServiceTarget().addCapability(ManagedThreadFactoryResourceDefinition.CAPABILITY);
String contextService = null;
if (model.hasDefined(ManagedThreadFactoryResourceDefinition.CONTEXT_SERVICE)) {
contextService = ManagedThreadFactoryResourceDefinition.CONTEXT_SERVICE_AD.resolveModelAttribute(context, model).asString();
}
final Consumer<ManagedThreadFactoryImpl> consumer = serviceBuilder.provides(ManagedThreadFactoryResourceDefinition.CAPABILITY);
final Supplier<ContextServiceImpl> ctxServiceSupplier = contextService != null ? serviceBuilder.requiresCapability(ContextServiceResourceDefinition.CAPABILITY.getName(), ContextServiceImpl.class, contextService) : null;
final ManagedThreadFactoryService service = new ManagedThreadFactoryService(consumer, ctxServiceSupplier, name, jndiName, priority);
serviceBuilder.setInstance(service);
serviceBuilder.install();
}
}
| 3,561 | 51.382353 | 227 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EESubsystemParser11.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, 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.ee.subsystem;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.parsing.ParseUtils.missingRequired;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoAttributes;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoContent;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement;
/**
*/
class EESubsystemParser11 implements XMLStreamConstants, XMLElementReader<List<ModelNode>> {
EESubsystemParser11() {
}
/**
* {@inheritDoc}
*/
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
// EE subsystem doesn't have any attributes, so make sure that the xml doesn't have any
requireNoAttributes(reader);
final ModelNode eeSubSystem = Util.createAddOperation(PathAddress.pathAddress(EeExtension.PATH_SUBSYSTEM));
// add the subsystem to the ModelNode(s)
list.add(eeSubSystem);
// elements
final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Namespace.forUri(reader.getNamespaceURI())) {
case EE_1_1: {
final Element element = Element.forName(reader.getLocalName());
if (!encountered.add(element)) {
throw unexpectedElement(reader);
}
switch (element) {
case GLOBAL_MODULES: {
final ModelNode model = parseGlobalModules(reader);
eeSubSystem.get(GlobalModulesDefinition.GLOBAL_MODULES).set(model);
break;
}
case EAR_SUBDEPLOYMENTS_ISOLATED: {
final String earSubDeploymentsIsolated = parseEarSubDeploymentsIsolatedElement(reader);
// set the ear subdeployment isolation on the subsystem operation
EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.parseAndSetParameter(earSubDeploymentsIsolated, eeSubSystem, reader);
break;
}
case SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseSpecDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseJBossDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
static ModelNode parseGlobalModules(XMLExtendedStreamReader reader) throws XMLStreamException {
ModelNode globalModules = new ModelNode();
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MODULE: {
final ModelNode module = new ModelNode();
final int count = reader.getAttributeCount();
String name = null;
String slot = null;
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME:
if (name != null) {
throw unexpectedAttribute(reader, i);
}
name = value;
GlobalModulesDefinition.NAME_AD.parseAndSetParameter(name, module, reader);
break;
case SLOT:
if (slot != null) {
throw unexpectedAttribute(reader, i);
}
slot = value;
GlobalModulesDefinition.SLOT_AD.parseAndSetParameter(slot, module, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (name == null) {
throw missingRequired(reader, Collections.singleton(NAME));
}
globalModules.add(module);
requireNoContent(reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
return globalModules;
}
static String parseEarSubDeploymentsIsolatedElement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.EAR_SUBDEPLOYMENTS_ISOLATED.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseSpecDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseJBossDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
}
| 8,851 | 42.605911 | 149 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EESubsystemParser40.java | /*
* Copyright 2015 Red Hat, Inc.
*
* 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.jboss.as.ee.subsystem;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.parsing.ParseUtils.missingRequired;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoAttributes;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoContent;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
*/
class EESubsystemParser40 implements XMLStreamConstants, XMLElementReader<List<ModelNode>> {
EESubsystemParser40() {
}
/**
* {@inheritDoc}
*/
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
// EE subsystem doesn't have any attributes, so make sure that the xml doesn't have any
requireNoAttributes(reader);
final PathAddress subsystemPathAddress = PathAddress.pathAddress(EeExtension.PATH_SUBSYSTEM);
final ModelNode eeSubSystem = Util.createAddOperation(subsystemPathAddress);
// add the subsystem to the ModelNode(s)
list.add(eeSubSystem);
// elements
final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Namespace.forUri(reader.getNamespaceURI())) {
case EE_4_0: {
final Element element = Element.forName(reader.getLocalName());
if (!encountered.add(element)) {
throw unexpectedElement(reader);
}
readElement(reader, list, subsystemPathAddress, eeSubSystem);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
protected void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list, final PathAddress subsystemPathAddress, final ModelNode eeSubSystem) throws XMLStreamException {
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case GLOBAL_MODULES: {
final ModelNode model = parseGlobalModules(reader);
eeSubSystem.get(GlobalModulesDefinition.GLOBAL_MODULES).set(model);
break;
}
case EAR_SUBDEPLOYMENTS_ISOLATED: {
final String earSubDeploymentsIsolated = parseEarSubDeploymentsIsolatedElement(reader);
// set the ear subdeployment isolation on the subsystem operation
EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.parseAndSetParameter(earSubDeploymentsIsolated, eeSubSystem, reader);
break;
}
case SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseSpecDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT: {
final String enabled = parseJBossDescriptorPropertyReplacement(reader);
EeSubsystemRootResource.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case ANNOTATION_PROPERTY_REPLACEMENT: {
final String enabled = parseEJBAnnotationPropertyReplacement(reader);
EeSubsystemRootResource.ANNOTATION_PROPERTY_REPLACEMENT.parseAndSetParameter(enabled, eeSubSystem, reader);
break;
}
case CONCURRENT: {
parseConcurrent(reader, list, subsystemPathAddress);
break;
}
case DEFAULT_BINDINGS: {
parseDefaultBindings(reader, list, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
static ModelNode parseGlobalModules(XMLExtendedStreamReader reader) throws XMLStreamException {
ModelNode globalModules = new ModelNode();
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MODULE: {
final ModelNode module = new ModelNode();
final int count = reader.getAttributeCount();
String name = null;
String slot = null;
String annotations = null;
String metaInf = null;
String services = null;
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME:
if (name != null) {
throw unexpectedAttribute(reader, i);
}
name = value;
GlobalModulesDefinition.NAME_AD.parseAndSetParameter(name, module, reader);
break;
case SLOT:
if (slot != null) {
throw unexpectedAttribute(reader, i);
}
slot = value;
GlobalModulesDefinition.SLOT_AD.parseAndSetParameter(slot, module, reader);
break;
case ANNOTATIONS:
if (annotations != null) {
throw unexpectedAttribute(reader, i);
}
annotations = value;
GlobalModulesDefinition.ANNOTATIONS_AD.parseAndSetParameter(annotations, module, reader);
break;
case SERVICES:
if (services != null) {
throw unexpectedAttribute(reader, i);
}
services = value;
GlobalModulesDefinition.SERVICES_AD.parseAndSetParameter(services, module, reader);
break;
case META_INF:
if (metaInf != null) {
throw unexpectedAttribute(reader, i);
}
metaInf = value;
GlobalModulesDefinition.META_INF_AD.parseAndSetParameter(metaInf, module, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (name == null) {
throw missingRequired(reader, Collections.singleton(NAME));
}
globalModules.add(module);
requireNoContent(reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
return globalModules;
}
static String parseEarSubDeploymentsIsolatedElement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.EAR_SUBDEPLOYMENTS_ISOLATED.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseSpecDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.SPEC_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseJBossDescriptorPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.JBOSS_DESCRIPTOR_PROPERTY_REPLACEMENT.getLocalName(), reader.getLocation());
}
return value.trim();
}
static String parseEJBAnnotationPropertyReplacement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
return value.trim();
}
static void parseConcurrent(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final Element element = Element.forName(reader.getLocalName());
switch (element) {
case CONTEXT_SERVICES: {
parseContextServices(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_THREAD_FACTORIES: {
parseManagedThreadFactories(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_EXECUTOR_SERVICES: {
parseManagedExecutorServices(reader, operations, subsystemPathAddress);
break;
}
case MANAGED_SCHEDULED_EXECUTOR_SERVICES: {
parseManagedScheduledExecutorServices(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
static void parseContextServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case CONTEXT_SERVICE: {
empty = false;
parseContextService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.CONTEXT_SERVICE));
}
}
static void parseContextService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ContextServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case USE_TRANSACTION_SETUP_PROVIDER:
ContextServiceResourceDefinition.USE_TRANSACTION_SETUP_PROVIDER_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.CONTEXT_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedThreadFactories(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_THREAD_FACTORY: {
empty = false;
parseManagedThreadFactory(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_THREAD_FACTORY));
}
}
static void parseManagedThreadFactory(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedThreadFactoryResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedThreadFactoryResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case PRIORITY:
ManagedThreadFactoryResourceDefinition.PRIORITY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_THREAD_FACTORY, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedExecutorServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_EXECUTOR_SERVICE: {
empty = false;
parseManagedExecutorService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_EXECUTOR_SERVICE));
}
}
static void parseManagedExecutorService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedExecutorServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedExecutorServiceResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_FACTORY:
ManagedScheduledExecutorServiceResourceDefinition.THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case HUNG_TASK_THRESHOLD:
ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.parseAndSetParameter(value, addOperation, reader);
break;
case LONG_RUNNING_TASKS:
ManagedExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CORE_THREADS:
ManagedExecutorServiceResourceDefinition.CORE_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MAX_THREADS:
ManagedExecutorServiceResourceDefinition.MAX_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case KEEPALIVE_TIME:
ManagedExecutorServiceResourceDefinition.KEEPALIVE_TIME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case QUEUE_LENGTH:
ManagedExecutorServiceResourceDefinition.QUEUE_LENGTH_AD.parseAndSetParameter(value, addOperation, reader);
break;
case REJECT_POLICY:
ManagedExecutorServiceResourceDefinition.REJECT_POLICY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_EXECUTOR_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseManagedScheduledExecutorServices(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
requireNoAttributes(reader);
boolean empty = true;
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MANAGED_SCHEDULED_EXECUTOR_SERVICE: {
empty = false;
parseManagedScheduledExecutorService(reader, operations, subsystemPathAddress);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
if (empty) {
throw missingRequired(reader, EnumSet.of(Element.MANAGED_SCHEDULED_EXECUTOR_SERVICE));
}
}
static void parseManagedScheduledExecutorService(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
String name = null;
final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.JNDI_NAME);
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
required.remove(attribute);
switch (attribute) {
case NAME:
name = value.trim();
break;
case JNDI_NAME:
ManagedScheduledExecutorServiceResourceDefinition.JNDI_NAME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CONTEXT_SERVICE:
ManagedScheduledExecutorServiceResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case THREAD_FACTORY:
ManagedScheduledExecutorServiceResourceDefinition.THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case HUNG_TASK_THRESHOLD:
ManagedScheduledExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD_AD.parseAndSetParameter(value, addOperation, reader);
break;
case LONG_RUNNING_TASKS:
ManagedScheduledExecutorServiceResourceDefinition.LONG_RUNNING_TASKS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case CORE_THREADS:
ManagedScheduledExecutorServiceResourceDefinition.CORE_THREADS_AD.parseAndSetParameter(value, addOperation, reader);
break;
case KEEPALIVE_TIME:
ManagedScheduledExecutorServiceResourceDefinition.KEEPALIVE_TIME_AD.parseAndSetParameter(value, addOperation, reader);
break;
case REJECT_POLICY:
ManagedScheduledExecutorServiceResourceDefinition.REJECT_POLICY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingRequired(reader, required);
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE, name);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
static void parseDefaultBindings(XMLExtendedStreamReader reader, List<ModelNode> operations, PathAddress subsystemPathAddress) throws XMLStreamException {
final ModelNode addOperation = Util.createAddOperation();
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case CONTEXT_SERVICE:
DefaultBindingsResourceDefinition.CONTEXT_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case DATASOURCE:
DefaultBindingsResourceDefinition.DATASOURCE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case JMS_CONNECTION_FACTORY:
DefaultBindingsResourceDefinition.JMS_CONNECTION_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_EXECUTOR_SERVICE:
DefaultBindingsResourceDefinition.MANAGED_EXECUTOR_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_SCHEDULED_EXECUTOR_SERVICE:
DefaultBindingsResourceDefinition.MANAGED_SCHEDULED_EXECUTOR_SERVICE_AD.parseAndSetParameter(value, addOperation, reader);
break;
case MANAGED_THREAD_FACTORY:
DefaultBindingsResourceDefinition.MANAGED_THREAD_FACTORY_AD.parseAndSetParameter(value, addOperation, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
requireNoContent(reader);
final PathAddress address = subsystemPathAddress.append(EESubsystemModel.DEFAULT_BINDINGS_PATH);
addOperation.get(OP_ADDR).set(address.toModelNode());
operations.add(addOperation);
}
}
| 27,246 | 46.885764 | 193 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ContextServiceAdd.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.subsystem;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.ee.concurrent.ContextServiceTypesConfiguration;
import org.jboss.as.ee.concurrent.DefaultContextSetupProviderImpl;
import org.jboss.as.ee.concurrent.service.ContextServiceService;
import org.jboss.dmr.ModelNode;
/**
* @author Eduardo Martins
*/
public class ContextServiceAdd extends AbstractAddStepHandler {
static final ContextServiceAdd INSTANCE = new ContextServiceAdd();
private ContextServiceAdd() {
super(ContextServiceResourceDefinition.ATTRIBUTES);
}
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
final ModelNode model = resource.getModel();
final String name = context.getCurrentAddressValue();
final String jndiName = ContextServiceResourceDefinition.JNDI_NAME_AD.resolveModelAttribute(context, model).asString();
// WFLY-16705 deprecated USE_TRANSACTION_SETUP_PROVIDER_AD is ignored since it's of no use anymore (replaced by spec's context service config of context type Transaction)
// TODO https://issues.redhat.com/browse/WFLY-17912 -- allow Context Service configuration via the subsystem management API
// install the service which manages the default context service
final ContextServiceService contextServiceService = new ContextServiceService(name, jndiName, new DefaultContextSetupProviderImpl(), ContextServiceTypesConfiguration.DEFAULT);
context.getCapabilityServiceTarget().addCapability(ContextServiceResourceDefinition.CAPABILITY).setInstance(contextServiceService).install();
}
}
| 2,893 | 50.678571 | 183 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ManagedScheduledExecutorServiceResourceDefinition.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.subsystem;
import org.glassfish.enterprise.concurrent.AbstractManagedExecutorService;
import org.glassfish.enterprise.concurrent.ManagedScheduledExecutorServiceAdapter;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
import org.jboss.as.controller.ServiceRemoveStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.client.helpers.MeasurementUnit;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.operations.validation.EnumValidator;
import org.jboss.as.controller.operations.validation.IntRangeValidator;
import org.jboss.as.controller.operations.validation.LongRangeValidator;
import org.jboss.as.controller.operations.validation.StringLengthValidator;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.transform.description.DiscardAttributeChecker;
import org.jboss.as.controller.transform.description.RejectAttributeChecker;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.as.ee.concurrent.service.ManagedScheduledExecutorServiceService;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* @author Eduardo Martins
*/
public class ManagedScheduledExecutorServiceResourceDefinition extends SimpleResourceDefinition {
/**
* the resource definition's dynamic runtime capability
*/
public static final RuntimeCapability<Void> CAPABILITY = RuntimeCapability.Builder.of("org.wildfly.ee.concurrent.scheduled-executor", true, ManagedScheduledExecutorServiceAdapter.class)
.build();
public static final String JNDI_NAME = "jndi-name";
public static final String CONTEXT_SERVICE = "context-service";
public static final String THREAD_FACTORY = "thread-factory";
public static final String THREAD_PRIORITY = "thread-priority";
public static final String HUNG_TASK_TERMINATION_PERIOD = "hung-task-termination-period";
public static final String HUNG_TASK_THRESHOLD = "hung-task-threshold";
public static final String LONG_RUNNING_TASKS = "long-running-tasks";
public static final String CORE_THREADS = "core-threads";
public static final String KEEPALIVE_TIME = "keepalive-time";
public static final String REJECT_POLICY = "reject-policy";
public static final SimpleAttributeDefinition JNDI_NAME_AD =
new SimpleAttributeDefinitionBuilder(JNDI_NAME, ModelType.STRING, false)
.setAllowExpression(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition CONTEXT_SERVICE_AD =
new SimpleAttributeDefinitionBuilder(CONTEXT_SERVICE, ModelType.STRING, true)
.setAllowExpression(false)
.setValidator(new StringLengthValidator(0, true))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setCapabilityReference(ContextServiceResourceDefinition.CAPABILITY.getName(), CAPABILITY)
.build();
public static final SimpleAttributeDefinition THREAD_FACTORY_AD =
new SimpleAttributeDefinitionBuilder(THREAD_FACTORY, ModelType.STRING, true)
.setAllowExpression(false)
.setValidator(new StringLengthValidator(0, true))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setCapabilityReference(ManagedThreadFactoryResourceDefinition.CAPABILITY.getName(), CAPABILITY)
.setDeprecated(EESubsystemModel.Version.v5_0_0)
.setAlternatives(THREAD_PRIORITY)
.build();
public static final SimpleAttributeDefinition THREAD_PRIORITY_AD =
new SimpleAttributeDefinitionBuilder(THREAD_PRIORITY, ModelType.INT, true)
.setAllowExpression(true)
.setValidator(new IntRangeValidator(Thread.MIN_PRIORITY, Thread.MAX_PRIORITY, true, true))
.setDefaultValue(new ModelNode(Thread.NORM_PRIORITY))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setAlternatives(THREAD_FACTORY)
.build();
public static final SimpleAttributeDefinition HUNG_TASK_TERMINATION_PERIOD_AD =
new SimpleAttributeDefinitionBuilder(HUNG_TASK_TERMINATION_PERIOD, ModelType.LONG, true)
.setAllowExpression(true)
.setValidator(new LongRangeValidator(0, Long.MAX_VALUE, true, true))
.setMeasurementUnit(MeasurementUnit.MILLISECONDS)
.setDefaultValue(ModelNode.ZERO)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition HUNG_TASK_THRESHOLD_AD =
new SimpleAttributeDefinitionBuilder(HUNG_TASK_THRESHOLD, ModelType.LONG, true)
.setAllowExpression(true)
.setValidator(new LongRangeValidator(0, Long.MAX_VALUE, true, true))
.setMeasurementUnit(MeasurementUnit.MILLISECONDS)
.setDefaultValue(ModelNode.ZERO)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition LONG_RUNNING_TASKS_AD =
new SimpleAttributeDefinitionBuilder(LONG_RUNNING_TASKS, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition CORE_THREADS_AD =
new SimpleAttributeDefinitionBuilder(CORE_THREADS, ModelType.INT, true)
.setAllowExpression(true)
.setValidator(new IntRangeValidator(0, Integer.MAX_VALUE, true, true))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition KEEPALIVE_TIME_AD =
new SimpleAttributeDefinitionBuilder(KEEPALIVE_TIME, ModelType.LONG, true)
.setAllowExpression(true)
.setValidator(new LongRangeValidator(0, Long.MAX_VALUE, true, true))
.setMeasurementUnit(MeasurementUnit.MILLISECONDS)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setDefaultValue(new ModelNode(60000))
.build();
public static final SimpleAttributeDefinition REJECT_POLICY_AD =
new SimpleAttributeDefinitionBuilder(REJECT_POLICY, ModelType.STRING, true)
.setAllowExpression(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setDefaultValue(new ModelNode(AbstractManagedExecutorService.RejectPolicy.ABORT.toString()))
.setValidator(EnumValidator.create(AbstractManagedExecutorService.RejectPolicy.class))
.build();
static final SimpleAttributeDefinition[] ATTRIBUTES = {JNDI_NAME_AD, CONTEXT_SERVICE_AD, THREAD_FACTORY_AD, THREAD_PRIORITY_AD, HUNG_TASK_TERMINATION_PERIOD_AD, HUNG_TASK_THRESHOLD_AD, LONG_RUNNING_TASKS_AD, CORE_THREADS_AD, KEEPALIVE_TIME_AD, REJECT_POLICY_AD};
public static final PathElement PATH_ELEMENT = PathElement.pathElement(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE);
private static final ResourceDescriptionResolver RESOLVER = EeExtension.getResourceDescriptionResolver(EESubsystemModel.MANAGED_SCHEDULED_EXECUTOR_SERVICE);
/**
* metrics op step handler
*/
private static final ManagedExecutorServiceMetricsHandler METRICS_HANDLER = new ManagedExecutorServiceMetricsHandler.Builder<ManagedScheduledExecutorServiceService>(CAPABILITY)
.addMetric(ManagedExecutorServiceMetricsAttributes.ACTIVE_THREAD_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getActiveThreadsCount()))
.addMetric(ManagedExecutorServiceMetricsAttributes.COMPLETED_TASK_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getCompletedTaskCount()))
.addMetric(ManagedExecutorServiceMetricsAttributes.CURRENT_QUEUE_SIZE_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getQueueSize()))
.addMetric(ManagedExecutorServiceMetricsAttributes.HUNG_THREAD_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getHungThreadsCount()))
.addMetric(ManagedExecutorServiceMetricsAttributes.MAX_THREAD_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getMaxThreadsCount()))
.addMetric(ManagedExecutorServiceMetricsAttributes.TASK_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getTaskCount()))
.addMetric(ManagedExecutorServiceMetricsAttributes.THREAD_COUNT_AD, (context, service) -> context.getResult().set(service.getExecutorService().getRuntimeStats().getThreadsCount()))
.build();
/**
* terminate hung threads op
*/
private static final ManagedExecutorTerminateHungTasksOperation<ManagedScheduledExecutorServiceService> TERMINATE_HUNG_TASKS_OP = new ManagedExecutorTerminateHungTasksOperation<>(CAPABILITY, RESOLVER, service -> service.getExecutorService());
/**
*
*/
private final boolean registerRuntimeOnly;
ManagedScheduledExecutorServiceResourceDefinition(boolean registerRuntimeOnly) {
super(new SimpleResourceDefinition.Parameters(PATH_ELEMENT, RESOLVER)
.setAddHandler(ManagedScheduledExecutorServiceAdd.INSTANCE)
.setRemoveHandler(new ServiceRemoveStepHandler(ManagedScheduledExecutorServiceAdd.INSTANCE))
.addCapabilities(CAPABILITY));
this.registerRuntimeOnly = registerRuntimeOnly;
}
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(ATTRIBUTES);
for (AttributeDefinition attr : ATTRIBUTES) {
resourceRegistration.registerReadWriteAttribute(attr, null, writeHandler);
}
if (registerRuntimeOnly) {
METRICS_HANDLER.registerAttributes(resourceRegistration);
}
}
@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
super.registerOperations(resourceRegistration);
TERMINATE_HUNG_TASKS_OP.registerOperation(resourceRegistration);
}
static void registerTransformers_4_0(final ResourceTransformationDescriptionBuilder builder) {
final ResourceTransformationDescriptionBuilder resourceBuilder = builder.addChildResource(PATH_ELEMENT);
resourceBuilder.getAttributeBuilder()
.addRejectCheck(RejectAttributeChecker.UNDEFINED, CORE_THREADS_AD)
.end();
}
static void registerTransformers5_0(final ResourceTransformationDescriptionBuilder builder) {
final ResourceTransformationDescriptionBuilder resourceBuilder = builder.addChildResource(PATH_ELEMENT);
resourceBuilder.getAttributeBuilder()
.setDiscard(DiscardAttributeChecker.UNDEFINED, THREAD_PRIORITY_AD)
.addRejectCheck(RejectAttributeChecker.DEFINED, THREAD_PRIORITY_AD)
.end();
}
static void registerTransformers6_0(final ResourceTransformationDescriptionBuilder builder) {
final ResourceTransformationDescriptionBuilder resourceBuilder = builder.addChildResource(PATH_ELEMENT);
resourceBuilder.getAttributeBuilder()
.setDiscard(DiscardAttributeChecker.UNDEFINED, HUNG_TASK_TERMINATION_PERIOD_AD)
.addRejectCheck(RejectAttributeChecker.DEFINED, HUNG_TASK_TERMINATION_PERIOD_AD)
.end();
}
}
| 13,755 | 58.549784 | 266 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ManagedThreadFactoryResourceDefinition.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.subsystem;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
import org.jboss.as.controller.ServiceRemoveStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.operations.validation.IntRangeValidator;
import org.jboss.as.controller.operations.validation.StringLengthValidator;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.ee.concurrent.ManagedThreadFactoryImpl;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* @author Eduardo Martins
*/
public class ManagedThreadFactoryResourceDefinition extends SimpleResourceDefinition {
/**
* the resource definition's dynamic runtime capability
*/
public static final RuntimeCapability<Void> CAPABILITY = RuntimeCapability.Builder.of("org.wildfly.ee.concurrent.thread-factory", true, ManagedThreadFactoryImpl.class)
.build();
public static final String JNDI_NAME = "jndi-name";
public static final String CONTEXT_SERVICE = "context-service";
public static final String PRIORITY = "priority";
public static final SimpleAttributeDefinition JNDI_NAME_AD =
new SimpleAttributeDefinitionBuilder(JNDI_NAME, ModelType.STRING, false)
.setAllowExpression(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition CONTEXT_SERVICE_AD =
new SimpleAttributeDefinitionBuilder(CONTEXT_SERVICE, ModelType.STRING, true)
.setAllowExpression(false)
.setValidator(new StringLengthValidator(0,true))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setCapabilityReference(ContextServiceResourceDefinition.CAPABILITY.getName(), CAPABILITY)
.build();
public static final SimpleAttributeDefinition PRIORITY_AD =
new SimpleAttributeDefinitionBuilder(PRIORITY, ModelType.INT, true)
.setAllowExpression(true)
.setValidator(new IntRangeValidator(Thread.MIN_PRIORITY, Thread.MAX_PRIORITY, true, true))
.setDefaultValue(new ModelNode(Thread.NORM_PRIORITY))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
static final SimpleAttributeDefinition[] ATTRIBUTES = {JNDI_NAME_AD, CONTEXT_SERVICE_AD, PRIORITY_AD};
ManagedThreadFactoryResourceDefinition() {
super(new SimpleResourceDefinition.Parameters(PathElement.pathElement(EESubsystemModel.MANAGED_THREAD_FACTORY), EeExtension.getResourceDescriptionResolver(EESubsystemModel.MANAGED_THREAD_FACTORY))
.setAddHandler(ManagedThreadFactoryAdd.INSTANCE)
.setRemoveHandler(new ServiceRemoveStepHandler(ManagedThreadFactoryAdd.INSTANCE))
.addCapabilities(CAPABILITY));
}
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(ATTRIBUTES);
for (AttributeDefinition attr : ATTRIBUTES) {
resourceRegistration.registerReadWriteAttribute(attr, null, writeHandler);
}
}
}
| 4,772 | 49.242105 | 204 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EeExtension.java | /*
* 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.ee.subsystem;
import org.jboss.as.controller.Extension;
import org.jboss.as.controller.ExtensionContext;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver;
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
import org.jboss.as.controller.parsing.ExtensionParsingContext;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.ee.component.deployers.DefaultBindingsConfigurationProcessor;
/**
* JBossAS domain extension used to initialize the ee subsystem handlers and associated classes.
*
* @author Weston M. Price
* @author Emanuel Muckenhuber
*/
public class EeExtension implements Extension {
public static final String SUBSYSTEM_NAME = "ee";
private static final String RESOURCE_NAME = EeExtension.class.getPackage().getName() + ".LocalDescriptions";
private static final ModelVersion CURRENT_MODEL_VERSION = EESubsystemModel.Version.v6_0_0;
protected static final PathElement PATH_SUBSYSTEM = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME);
static ResourceDescriptionResolver getResourceDescriptionResolver(final String keyPrefix) {
return new StandardResourceDescriptionResolver(keyPrefix, RESOURCE_NAME, EeExtension.class.getClassLoader(), true, true);
}
/**
* {@inheritDoc}
*/
@Override
public void initialize(ExtensionContext context) {
final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION);
// Register the root subsystem resource.
final ManagementResourceRegistration rootResource = subsystem.registerSubsystemModel(EeSubsystemRootResource.create());
// Mandatory describe operation
rootResource.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE);
// register submodels
final boolean runtimeOnlyRegistrationValid = context.isRuntimeOnlyRegistrationValid();
rootResource.registerSubModel(new ContextServiceResourceDefinition());
rootResource.registerSubModel(new ManagedThreadFactoryResourceDefinition());
rootResource.registerSubModel(new ManagedExecutorServiceResourceDefinition(runtimeOnlyRegistrationValid));
rootResource.registerSubModel(new ManagedScheduledExecutorServiceResourceDefinition(runtimeOnlyRegistrationValid));
rootResource.registerSubModel(new DefaultBindingsResourceDefinition(new DefaultBindingsConfigurationProcessor()));
rootResource.registerSubModel(new GlobalDirectoryResourceDefinition());
subsystem.registerXMLElementWriter(EESubsystemXmlPersister.INSTANCE);
}
/**
* {@inheritDoc}
*/
@Override
public void initializeParsers(ExtensionParsingContext context) {
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.EE_1_0.getUriString(), EESubsystemParser10::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.EE_1_1.getUriString(), EESubsystemParser11::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.EE_1_2.getUriString(), EESubsystemParser12::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.EE_2_0.getUriString(), EESubsystemParser20::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.EE_3_0.getUriString(), EESubsystemParser20::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.EE_4_0.getUriString(), EESubsystemParser40::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.EE_5_0.getUriString(), EESubsystemParser50::new);
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, Namespace.EE_6_0.getUriString(), EESubsystemParser60::new);
context.setProfileParsingCompletionHandler(new BeanValidationProfileParsingCompletionHandler());
}
}
| 5,213 | 50.623762 | 133 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/GlobalDirectoryResourceDefinition.java | /*
* Copyright 2019 Red Hat, Inc.
*
* 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.jboss.as.ee.subsystem;
import static org.jboss.as.controller.OperationContext.Stage.MODEL;
import static org.jboss.as.controller.SimpleAttributeDefinitionBuilder.create;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FILESYSTEM_PATH;
import static org.jboss.as.ee.subsystem.EeCapabilities.EE_GLOBAL_DIRECTORY_CAPABILITY;
import static org.jboss.as.ee.subsystem.EeCapabilities.PATH_MANAGER_CAPABILITY;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.AbstractRemoveStepHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.CapabilityServiceBuilder;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.ReloadRequiredRemoveStepHandler;
import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.controller.services.path.PathManager;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceController;
/**
* The resource definition for global-directory child resource in EE subsystem.
*
* @author Yeray Borges
*/
public class GlobalDirectoryResourceDefinition extends PersistentResourceDefinition {
static SimpleAttributeDefinition PATH = create(ModelDescriptionConstants.PATH, ModelType.STRING, false)
.setAllowExpression(true)
.addArbitraryDescriptor(FILESYSTEM_PATH, new ModelNode(true))
.setRestartAllServices()
.build();
static SimpleAttributeDefinition RELATIVE_TO = create(ModelDescriptionConstants.RELATIVE_TO, ModelType.STRING, true)
.setAllowExpression(false)
.setRestartAllServices()
.build();
static final SimpleAttributeDefinition[] ATTRIBUTES = new SimpleAttributeDefinition[]{PATH, RELATIVE_TO};
private static final AbstractAddStepHandler ADD = new GlobalDirectoryAddHandler();
private static final AbstractRemoveStepHandler REMOVE = ReloadRequiredRemoveStepHandler.INSTANCE;
GlobalDirectoryResourceDefinition() {
super(new SimpleResourceDefinition.Parameters(PathElement.pathElement(EESubsystemModel.GLOBAL_DIRECTORY), EeExtension.getResourceDescriptionResolver(EESubsystemModel.GLOBAL_DIRECTORY))
.setAddHandler(GlobalDirectoryResourceDefinition.ADD)
.setRemoveHandler(GlobalDirectoryResourceDefinition.REMOVE)
.setCapabilities(EE_GLOBAL_DIRECTORY_CAPABILITY)
);
}
@Override
public Collection<AttributeDefinition> getAttributes() {
return Arrays.asList(ATTRIBUTES);
}
private static class GlobalDirectoryAddHandler extends AbstractAddStepHandler {
public GlobalDirectoryAddHandler() {
super(ATTRIBUTES);
}
@Override
protected void populateModel(final OperationContext context, final ModelNode operation, final Resource resource)
throws OperationFailedException {
super.populateModel(context, operation, resource);
context.addStep(new OperationStepHandler() {
public void execute(OperationContext oc, ModelNode op) throws OperationFailedException {
Resource parentResource = context.readResourceFromRoot(context.getCurrentAddress().getParent(), false);
Set<String> globalDirectories = parentResource.getChildrenNames(EESubsystemModel.GLOBAL_DIRECTORY);
String newName = context.getCurrentAddressValue();
String firstAdded = !globalDirectories.isEmpty() ? globalDirectories.iterator().next() : null;
if (firstAdded != null && !firstAdded.equals(newName)) {
throw EeLogger.ROOT_LOGGER.oneGlobalDirectory(newName, firstAdded);
}
}
}, MODEL);
}
@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final String path = PATH.resolveModelAttribute(context, model).asString();
final String relativeTo = RELATIVE_TO.resolveModelAttribute(context, model).asStringOrNull();
final CapabilityServiceBuilder<?> serviceBuilder = context.getCapabilityServiceTarget()
.addCapability(EE_GLOBAL_DIRECTORY_CAPABILITY);
final Consumer<GlobalDirectory> provides = serviceBuilder.provides(EE_GLOBAL_DIRECTORY_CAPABILITY);
final Supplier<PathManager> pathManagerSupplier = serviceBuilder.requiresCapability(PATH_MANAGER_CAPABILITY, PathManager.class);
Service globalDirectoryService = new GlobalDirectoryService(pathManagerSupplier, provides, context.getCurrentAddressValue(), path, relativeTo);
serviceBuilder.setInstance(globalDirectoryService)
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
}
}
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
ReloadRequiredWriteAttributeHandler handler = new ReloadRequiredWriteAttributeHandler(ATTRIBUTES);
for (AttributeDefinition attribute : ATTRIBUTES) {
resourceRegistration.registerReadWriteAttribute(attribute, null, handler);
}
}
public static final class GlobalDirectory {
private final Path resolvedPath;
private final String name;
public GlobalDirectory(Path resolvedPath, String name) {
this.resolvedPath = resolvedPath;
this.name = name;
}
public Path getResolvedPath() {
return resolvedPath;
}
public String getName() {
return name;
}
public String getModuleName() {
return "global-directory." + name;
}
}
}
| 7,253 | 43.231707 | 192 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/Attribute.java | /*
* 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.ee.subsystem;
import java.util.HashMap;
import java.util.Map;
import org.jboss.as.domain.management.ModelDescriptionConstants;
/**
* Enumeration of attributes used in the EE subsystem.
*
* @author John E. Bailey
*/
enum Attribute {
UNKNOWN(null),
NAME(GlobalModulesDefinition.NAME),
SLOT(GlobalModulesDefinition.SLOT),
ANNOTATIONS(GlobalModulesDefinition.ANNOTATIONS),
SERVICES(GlobalModulesDefinition.SERVICES),
META_INF(GlobalModulesDefinition.META_INF),
// from ee concurrent
JNDI_NAME(ContextServiceResourceDefinition.JNDI_NAME),
USE_TRANSACTION_SETUP_PROVIDER(ContextServiceResourceDefinition.USE_TRANSACTION_SETUP_PROVIDER),
CONTEXT_SERVICE(ManagedThreadFactoryResourceDefinition.CONTEXT_SERVICE),
PRIORITY(ManagedThreadFactoryResourceDefinition.PRIORITY),
THREAD_FACTORY(ManagedExecutorServiceResourceDefinition.THREAD_FACTORY),
THREAD_PRIORITY(ManagedExecutorServiceResourceDefinition.THREAD_PRIORITY),
HUNG_TASK_TERMINATION_PERIOD(ManagedExecutorServiceResourceDefinition.HUNG_TASK_TERMINATION_PERIOD),
HUNG_TASK_THRESHOLD(ManagedExecutorServiceResourceDefinition.HUNG_TASK_THRESHOLD),
LONG_RUNNING_TASKS(ManagedExecutorServiceResourceDefinition.LONG_RUNNING_TASKS),
CORE_THREADS(ManagedExecutorServiceResourceDefinition.CORE_THREADS),
MAX_THREADS(ManagedExecutorServiceResourceDefinition.MAX_THREADS),
KEEPALIVE_TIME(ManagedExecutorServiceResourceDefinition.KEEPALIVE_TIME),
QUEUE_LENGTH(ManagedExecutorServiceResourceDefinition.QUEUE_LENGTH),
REJECT_POLICY(ManagedExecutorServiceResourceDefinition.REJECT_POLICY),
DATASOURCE(DefaultBindingsResourceDefinition.DATASOURCE),
JMS_CONNECTION_FACTORY(DefaultBindingsResourceDefinition.JMS_CONNECTION_FACTORY),
MANAGED_EXECUTOR_SERVICE(DefaultBindingsResourceDefinition.MANAGED_EXECUTOR_SERVICE),
MANAGED_SCHEDULED_EXECUTOR_SERVICE(DefaultBindingsResourceDefinition.MANAGED_SCHEDULED_EXECUTOR_SERVICE),
MANAGED_THREAD_FACTORY(DefaultBindingsResourceDefinition.MANAGED_THREAD_FACTORY),
PATH(ModelDescriptionConstants.PATH),
RELATIVE_TO(ModelDescriptionConstants.RELATIVE_TO)
;
private final String name;
Attribute(final String name) {
this.name = name;
}
/**
* Get the local name of this attribute.
*
* @return the local name
*/
public String getLocalName() {
return name;
}
private static final Map<String, Attribute> MAP;
static {
final Map<String, Attribute> map = new HashMap<String, Attribute>();
for (Attribute element : values()) {
final String name = element.getLocalName();
if (name != null) map.put(name, element);
}
MAP = map;
}
public static Attribute forName(String localName) {
final Attribute element = MAP.get(localName);
return element == null ? UNKNOWN : element;
}
public String toString() {
return getLocalName();
}
}
| 4,036 | 38.194175 | 109 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/GlobalDirectoryService.java | /*
* Copyright 2019 Red Hat, Inc.
*
* 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.jboss.as.ee.subsystem;
import static org.wildfly.common.Assert.checkNotNullParam;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.jboss.as.controller.services.path.AbsolutePathService;
import org.jboss.as.controller.services.path.PathEntry;
import org.jboss.as.controller.services.path.PathManager;
import org.jboss.as.ee.subsystem.GlobalDirectoryResourceDefinition.GlobalDirectory;
import org.jboss.modules.PathUtils;
import org.jboss.msc.Service;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
/**
* Service responsible creating a {@code GlobalDirectory} which contains the information of a configured global directory.
*
* @author Yeray Borges
*/
public class GlobalDirectoryService implements Service {
private final Supplier<PathManager> pathManagerSupplier;
private final String path;
private final String relativeTo;
private final PathResolver pathResolver;
private final Consumer<GlobalDirectory> consumer;
private final String name;
public GlobalDirectoryService(Supplier<PathManager> pathManagerSupplier, Consumer<GlobalDirectory> consumer, String name, String path, String relativeTo) {
this.pathManagerSupplier = checkNotNullParam("pathManagerSupplier", pathManagerSupplier);
this.path = checkNotNullParam("path", path);
this.name = checkNotNullParam("name", name);
this.relativeTo = relativeTo;
this.pathResolver = new PathResolver();
this.consumer = consumer;
}
@Override
public void start(StartContext context) throws StartException {
pathResolver.path(path);
pathResolver.relativeTo(relativeTo, pathManagerSupplier.get());
GlobalDirectory globaldirectory = new GlobalDirectory(pathResolver.resolve(), name);
consumer.accept(globaldirectory);
}
@Override
public void stop(StopContext context) {
pathResolver.clear();
}
private static class PathResolver {
private String path;
private String relativeTo;
private PathManager pathManager;
private PathManager.Callback.Handle callbackHandle;
PathResolver path(String path) {
this.path = path;
return this;
}
PathResolver relativeTo(String relativeTo, PathManager pathManager) {
this.relativeTo = relativeTo;
this.pathManager = pathManager;
return this;
}
Path resolve() {
String relativeToPath = AbsolutePathService.isAbsoluteUnixOrWindowsPath(path) ? null : relativeTo;
Path resolvedPath = Paths.get(PathUtils.canonicalize(pathManager.resolveRelativePathEntry(path, relativeToPath))).normalize();
if (relativeTo != null) {
callbackHandle = pathManager.registerCallback(relativeTo, new org.jboss.as.controller.services.path.PathManager.Callback() {
@Override
public void pathModelEvent(PathManager.PathEventContext eventContext, String name) {
if (eventContext.isResourceServiceRestartAllowed() == false) {
eventContext.reloadRequired();
}
}
@Override
public void pathEvent(PathManager.Event event, PathEntry pathEntry) {
// Service dependencies should trigger a stop and start.
}
}, PathManager.Event.REMOVED, PathManager.Event.UPDATED);
}
return resolvedPath;
}
void clear() {
if (callbackHandle != null) {
callbackHandle.remove();
callbackHandle = null;
}
}
}
}
| 4,504 | 36.231405 | 159 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ManagedExecutorServiceMetricsHandler.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2019 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.subsystem;
import org.jboss.as.controller.AbstractRuntimeOnlyHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* Operation step handler that expose a capability's metrics, through its service.
*
* @author emmartins
*/
public class ManagedExecutorServiceMetricsHandler<T> extends AbstractRuntimeOnlyHandler {
private final Map<String, Metric<T>> metrics;
private final RuntimeCapability capability;
public static <T> Builder<T> builder(RuntimeCapability capability) {
return new Builder<>(capability);
}
private ManagedExecutorServiceMetricsHandler(final Map<String, Metric<T>> metrics, final RuntimeCapability capability) {
this.metrics = metrics;
this.capability = capability;
}
/**
* Registers metrics attr definitions.
* @param registration
*/
public void registerAttributes(final ManagementResourceRegistration registration) {
for (Metric metric : metrics.values()) {
registration.registerMetric(metric.attributeDefinition, this);
}
}
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
if (context.getRunningMode() == RunningMode.NORMAL) {
ServiceName serviceName = capability.getCapabilityServiceName(context.getCurrentAddress());
ServiceController<?> controller = context.getServiceRegistry(false).getService(serviceName);
if (controller == null) {
throw EeLogger.ROOT_LOGGER.executorServiceNotFound(serviceName);
}
final T service = (T) controller.getService();
final Metric<T> metric = metrics.get(attributeName);
if (metric == null) {
throw EeLogger.ROOT_LOGGER.unsupportedExecutorServiceMetric(attributeName);
}
metric.resultSetter.setResult(context, service);
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
public static class Builder<T> {
private final RuntimeCapability capability;
private final Map<String, Metric<T>> metrics = new HashMap<>();
public Builder(RuntimeCapability capability) {
this.capability = capability;
}
/**
*
* @param attributeDefinition
* @param resultSetter
* @return
*/
public Builder<T> addMetric(AttributeDefinition attributeDefinition, MetricResultSetter<T> resultSetter) {
final String name = attributeDefinition.getName();
metrics.put(name, new Metric<>(attributeDefinition, resultSetter));
return this;
}
/**
*
* @return
*/
public ManagedExecutorServiceMetricsHandler<T> build() {
return new ManagedExecutorServiceMetricsHandler<>(Collections.unmodifiableMap(metrics), capability);
}
}
private static class Metric<T> {
final AttributeDefinition attributeDefinition;
final MetricResultSetter<T> resultSetter;
Metric(AttributeDefinition attributeDefinition, MetricResultSetter<T> resultSetter) {
this.attributeDefinition = attributeDefinition;
this.resultSetter = resultSetter;
}
}
public interface MetricResultSetter<T> {
void setResult(OperationContext context, T service) throws OperationFailedException;
}
}
| 4,901 | 37.296875 | 124 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/GlobalDirectoryDeploymentService.java | /*
* Copyright 2019 Red Hat, Inc.
*
* 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.jboss.as.ee.subsystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Supplier;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.as.ee.subsystem.GlobalDirectoryResourceDefinition.GlobalDirectory;
import org.jboss.as.server.deployment.module.ModuleDependency;
import org.jboss.as.server.deployment.module.ModuleSpecification;
import org.jboss.as.server.moduleservice.ExternalModule;
import org.jboss.modules.ModuleIdentifier;
import org.jboss.modules.ModuleLoader;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceRegistry;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
/**
* This service does the required steps to add a directory as a deployment dependency and as an {@link ExternalModule}.
* <p>
* Basically is used as an intermediate step in <code>GlobalDirectoryDependencyProcessor</code> to retrieve the global directories
* supplied by the services installed with the corresponding ee/global-directory resource. Those services are consumed here
* and for each supplied value an {@link ExternalModule} is created and added as system dependency to the current deployment.
*
* @author Yeray Borges
*/
public class GlobalDirectoryDeploymentService implements Service {
private List<Supplier<GlobalDirectory>> globalDirectories;
private final ExternalModule externalModuleService;
private final ModuleSpecification moduleSpecification;
private final ModuleLoader moduleLoader;
private final ServiceRegistry serviceRegistry;
private final ServiceTarget serviceTarget;
public GlobalDirectoryDeploymentService(List<Supplier<GlobalDirectory>> globalDirectories, final ExternalModule externalModuleService, final ModuleSpecification moduleSpecification, final ModuleLoader moduleLoader, final ServiceRegistry serviceRegistry, final ServiceTarget serviceTarget) {
this.globalDirectories = globalDirectories;
this.moduleSpecification = moduleSpecification;
this.externalModuleService = externalModuleService;
this.moduleLoader = moduleLoader;
this.serviceRegistry = serviceRegistry;
this.serviceTarget = serviceTarget;
}
@Override
public void start(StartContext context) throws StartException {
final List<GlobalDirectory> dataSorted = new ArrayList<>();
for (Supplier<GlobalDirectory> dataSupplier : globalDirectories) {
GlobalDirectory data = dataSupplier.get();
dataSorted.add(data);
}
//validate all exists
for(GlobalDirectory globalDirectory : dataSorted) {
if (!Files.exists(globalDirectory.getResolvedPath())) {
throw EeLogger.ROOT_LOGGER.globalDirectoryDoNotExist(globalDirectory.getResolvedPath().toString(), globalDirectory.getName());
}
}
//sort by name, it will allow setting the final deployment module dependencies in a deterministic way
Collections.sort(dataSorted, Comparator.comparing(GlobalDirectory::getModuleName));
synchronized (externalModuleService) {
for (GlobalDirectory data : dataSorted) {
Path resolvedPath = data.getResolvedPath();
String moduleName = data.getModuleName();
ModuleIdentifier moduleIdentifier = externalModuleService.addExternalModule(moduleName, resolvedPath.toString(), serviceRegistry, serviceTarget);
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, moduleIdentifier, false, false, true, false));
}
}
}
@Override
public void stop(StopContext context) {
}
}
| 4,484 | 44.30303 | 294 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/EESubsystemParser10.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2012, 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.ee.subsystem;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
import static org.jboss.as.controller.parsing.ParseUtils.missingRequired;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoAttributes;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoContent;
import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute;
import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement;
/**
*/
class EESubsystemParser10 implements XMLStreamConstants, XMLElementReader<List<ModelNode>> {
EESubsystemParser10() {
}
/**
* {@inheritDoc}
*/
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
// EE subsystem doesn't have any attributes, so make sure that the xml doesn't have any
requireNoAttributes(reader);
final ModelNode eeSubSystem = Util.createAddOperation(PathAddress.pathAddress(EeExtension.PATH_SUBSYSTEM));
// add the subsystem to the ModelNode(s)
list.add(eeSubSystem);
// elements
final EnumSet<Element> encountered = EnumSet.noneOf(Element.class);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Namespace.forUri(reader.getNamespaceURI())) {
case EE_1_0: {
final Element element = Element.forName(reader.getLocalName());
if (!encountered.add(element)) {
throw unexpectedElement(reader);
}
switch (element) {
case GLOBAL_MODULES: {
final ModelNode model = parseGlobalModules(reader);
eeSubSystem.get(GlobalModulesDefinition.GLOBAL_MODULES).set(model);
break;
}
case EAR_SUBDEPLOYMENTS_ISOLATED: {
final String earSubDeploymentsIsolated = parseEarSubDeploymentsIsolatedElement(reader);
// set the ear subdeployment isolation on the subsystem operation
EeSubsystemRootResource.EAR_SUBDEPLOYMENTS_ISOLATED.parseAndSetParameter(earSubDeploymentsIsolated, eeSubSystem, reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
}
static ModelNode parseGlobalModules(XMLExtendedStreamReader reader) throws XMLStreamException {
ModelNode globalModules = new ModelNode();
requireNoAttributes(reader);
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
switch (Element.forName(reader.getLocalName())) {
case MODULE: {
final ModelNode module = new ModelNode();
final int count = reader.getAttributeCount();
String name = null;
String slot = null;
for (int i = 0; i < count; i++) {
requireNoNamespaceAttribute(reader, i);
final String value = reader.getAttributeValue(i);
final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME:
if (name != null) {
throw unexpectedAttribute(reader, i);
}
name = value;
GlobalModulesDefinition.NAME_AD.parseAndSetParameter(name, module, reader);
break;
case SLOT:
if (slot != null) {
throw unexpectedAttribute(reader, i);
}
slot = value;
GlobalModulesDefinition.SLOT_AD.parseAndSetParameter(slot, module, reader);
break;
default:
throw unexpectedAttribute(reader, i);
}
}
if (name == null) {
throw missingRequired(reader, Collections.singleton(NAME));
}
globalModules.add(module);
requireNoContent(reader);
break;
}
default: {
throw unexpectedElement(reader);
}
}
}
return globalModules;
}
static String parseEarSubDeploymentsIsolatedElement(XMLExtendedStreamReader reader) throws XMLStreamException {
// we don't expect any attributes for this element.
requireNoAttributes(reader);
final String value = reader.getElementText();
if (value == null || value.trim().isEmpty()) {
throw EeLogger.ROOT_LOGGER.invalidValue(value, Element.EAR_SUBDEPLOYMENTS_ISOLATED.getLocalName(), reader.getLocation());
}
return value.trim();
}
}
| 7,074 | 41.620482 | 149 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/Namespace.java | /*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt 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.ee.subsystem;
import java.util.HashMap;
import java.util.Map;
/**
* @author Stuart Douglas
*/
enum Namespace {
// must be first
UNKNOWN(null, false),
EE_1_0("urn:jboss:domain:ee:1.0", true),
EE_1_1("urn:jboss:domain:ee:1.1", true),
EE_1_2("urn:jboss:domain:ee:1.2", true),
EE_2_0("urn:jboss:domain:ee:2.0", true),
EE_3_0("urn:jboss:domain:ee:3.0", false),
EE_4_0("urn:jboss:domain:ee:4.0", false),
EE_5_0("urn:jboss:domain:ee:5.0", false),
EE_6_0("urn:jboss:domain:ee:6.0", false)
;
/**
* The current namespace version.
*/
public static final Namespace CURRENT = EE_6_0;
private final String name;
private final boolean beanValidationIncluded;
Namespace(final String name, final boolean beanValidationIncluded) {
this.name = name;
this.beanValidationIncluded = beanValidationIncluded;
}
/**
* Get the URI of this namespace.
*
* @return the URI
*/
public String getUriString() {
return name;
}
public boolean isBeanValidationIncluded() {
return beanValidationIncluded;
}
private static final Map<String, Namespace> MAP;
static {
final Map<String, Namespace> map = new HashMap<String, Namespace>();
for (Namespace namespace : values()) {
final String name = namespace.getUriString();
if (name != null) map.put(name, namespace);
}
MAP = map;
}
public static Namespace forUri(String uri) {
final Namespace element = MAP.get(uri);
return element == null ? UNKNOWN : element;
}
}
| 2,665 | 30.364706 | 76 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ManagedExecutorTerminateHungTasksOperation.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2020 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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.jboss.as.ee.subsystem;
import org.jboss.as.controller.AbstractRuntimeOnlyHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.SimpleOperationDefinition;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.ee.concurrent.ManagedExecutorWithHungThreads;
import org.jboss.as.ee.logging.EeLogger;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
/**
* Operation that manually terminates a managed executor's hung tasks, through its capability service.
*
* @author emmartins
*/
public class ManagedExecutorTerminateHungTasksOperation<T> {
public static final String NAME = "terminate-hung-tasks";
private final RuntimeCapability capability;
private final SimpleOperationDefinition operationDefinition;
private final ExecutorProvider<T> executorProvider;
/**
*
* @param capability
* @param resolver
* @param executorProvider
*/
ManagedExecutorTerminateHungTasksOperation(final RuntimeCapability capability, ResourceDescriptionResolver resolver, ExecutorProvider<T> executorProvider) {
this.capability = capability;
this.operationDefinition = new SimpleOperationDefinitionBuilder(NAME, resolver)
.setRuntimeOnly()
.build();
this.executorProvider = executorProvider;
}
/**
* Registers this operation with the specified resource.
* @param resourceRegistration
*/
void registerOperation(ManagementResourceRegistration resourceRegistration) {
if (resourceRegistration.getProcessType().isServer()) {
resourceRegistration.registerOperationHandler(operationDefinition, new AbstractRuntimeOnlyHandler() {
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
if (context.getRunningMode() == RunningMode.NORMAL) {
ServiceName serviceName = capability.getCapabilityServiceName(context.getCurrentAddress());
ServiceController<?> controller = context.getServiceRegistry(false).getService(serviceName);
if (controller == null) {
throw EeLogger.ROOT_LOGGER.executorServiceNotFound(serviceName);
}
final T service = (T) controller.getService();
ManagedExecutorWithHungThreads executor = executorProvider.getExecutor(service);
executor.terminateHungTasks();
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
});
}
}
/**
* Component which retrieves executors with hung threads, from services.
* @param <T>
*/
interface ExecutorProvider<T> {
/**
*
* @param service
* @return the executor with the specified service
*/
ManagedExecutorWithHungThreads getExecutor(T service);
}
}
| 4,192 | 40.93 | 160 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/BeanValidationProfileParsingCompletionHandler.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2014, 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.ee.subsystem;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.parsing.ProfileParsingCompletionHandler;
import org.jboss.dmr.ModelNode;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXTENSION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.MODULE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
/**
* {@link org.jboss.as.controller.parsing.ProfileParsingCompletionHandler} that installs a default Jakarta Bean Validation extension and subsystem if the
* profile included a legacy EE subsystem version but not Jakarta Bean Validation subsystem.
*
* @author Eduardo Martins
*/
public class BeanValidationProfileParsingCompletionHandler implements ProfileParsingCompletionHandler {
private static final String BEAN_VALIDATION_NAMESPACE_PREFIX = "urn:jboss:domain:bean-validation:";
private static final String BEAN_VALIDATION_SUBSYSTEM = "bean-validation";
private static final String BEAN_VALIDATION_MODULE = "org.wildfly.extension.bean-validation";
@Override
public void handleProfileParsingCompletion(Map<String, List<ModelNode>> profileBootOperations, List<ModelNode> otherBootOperations) {
List<ModelNode> legacyEEOps = null;
// Check all namespace versions which include bean validation
for (Namespace namespace : EnumSet.allOf(Namespace.class)) {
if (namespace.isBeanValidationIncluded()) {
legacyEEOps = profileBootOperations.get(namespace.getUriString());
if (legacyEEOps != null) {
break;
}
}
}
if (legacyEEOps != null) {
boolean hasBeanValidationOp = false;
for (String namespace : profileBootOperations.keySet()) {
if (namespace.startsWith(BEAN_VALIDATION_NAMESPACE_PREFIX)) {
hasBeanValidationOp = true;
break;
}
}
if (!hasBeanValidationOp) {
// See if we need to add the extension as well
boolean hasBeanValidationExtension = false;
for (ModelNode op : otherBootOperations) {
PathAddress pa = PathAddress.pathAddress(op.get(OP_ADDR));
if (pa.size() == 1 && EXTENSION.equals(pa.getElement(0).getKey())
&& BEAN_VALIDATION_MODULE.equals(pa.getElement(0).getValue())) {
hasBeanValidationExtension = true;
break;
}
}
if (!hasBeanValidationExtension) {
final ModelNode addBeanValidationExtensionOp = new ModelNode();
addBeanValidationExtensionOp.get(OP).set(ADD);
PathAddress beanValidationExtensionAddress = PathAddress.pathAddress(PathElement.pathElement(EXTENSION, BEAN_VALIDATION_MODULE));
addBeanValidationExtensionOp.get(OP_ADDR).set(beanValidationExtensionAddress.toModelNode());
addBeanValidationExtensionOp.get(MODULE).set(BEAN_VALIDATION_MODULE);
otherBootOperations.add(addBeanValidationExtensionOp);
}
// legacy EE subsystem and no bean validation subsystem, add it
final ModelNode addBeanValidationSubsystemOp = new ModelNode();
addBeanValidationSubsystemOp.get(OP).set(ADD);
PathAddress beanValidationSubsystemAddress = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, BEAN_VALIDATION_SUBSYSTEM));
addBeanValidationSubsystemOp.get(OP_ADDR).set(beanValidationSubsystemAddress.toModelNode());
legacyEEOps.add(addBeanValidationSubsystemOp);
}
}
}
}
| 5,272 | 48.280374 | 153 | java |
null | wildfly-main/ee/src/main/java/org/jboss/as/ee/subsystem/ContextServiceResourceDefinition.java | /*
* JBoss, Home of Professional Open Source.
* Copyright 2013, 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.ee.subsystem;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
import org.jboss.as.controller.ServiceRemoveStepHandler;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.ee.concurrent.ContextServiceImpl;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* @author Eduardo Martins
*/
public class ContextServiceResourceDefinition extends SimpleResourceDefinition {
/**
* the resource definition's dynamic runtime capability
*/
public static final RuntimeCapability<Void> CAPABILITY = RuntimeCapability.Builder.of("org.wildfly.ee.concurrent.context.service", true, ContextServiceImpl.class)
.build();
public static final String JNDI_NAME = "jndi-name";
public static final String USE_TRANSACTION_SETUP_PROVIDER = "use-transaction-setup-provider";
public static final SimpleAttributeDefinition JNDI_NAME_AD =
new SimpleAttributeDefinitionBuilder(JNDI_NAME, ModelType.STRING, false)
.setAllowExpression(true)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
public static final SimpleAttributeDefinition USE_TRANSACTION_SETUP_PROVIDER_AD =
new SimpleAttributeDefinitionBuilder(USE_TRANSACTION_SETUP_PROVIDER, ModelType.BOOLEAN, true)
.setAllowExpression(true)
.setDefaultValue(ModelNode.FALSE)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.setDeprecated(EESubsystemModel.Version.v6_0_0)
.build();
static final SimpleAttributeDefinition[] ATTRIBUTES = {JNDI_NAME_AD, USE_TRANSACTION_SETUP_PROVIDER_AD};
ContextServiceResourceDefinition() {
super(new SimpleResourceDefinition.Parameters(PathElement.pathElement(EESubsystemModel.CONTEXT_SERVICE), EeExtension.getResourceDescriptionResolver(EESubsystemModel.CONTEXT_SERVICE))
.setAddHandler(ContextServiceAdd.INSTANCE)
.setRemoveHandler(new ServiceRemoveStepHandler(ContextServiceAdd.INSTANCE))
.addCapabilities(CAPABILITY));
}
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(ATTRIBUTES);
for (AttributeDefinition attr : ATTRIBUTES) {
resourceRegistration.registerReadWriteAttribute(attr, null, writeHandler);
}
}
}
| 4,041 | 47.119048 | 190 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.