use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class JndiViewOperation method addEntries.
private void addEntries(final ModelNode current, final Context context) throws NamingException {
final NamingEnumeration<NameClassPair> entries = context.list("");
while (entries.hasMore()) {
final NameClassPair pair = entries.next();
final ModelNode node = current.get(pair.getName());
node.get("class-name").set(pair.getClassName());
try {
final Object value;
if (context instanceof NamingContext) {
value = ((NamingContext) context).lookup(pair.getName(), false);
} else {
value = context.lookup(pair.getName());
}
if (value instanceof Context) {
addEntries(node.get("children"), Context.class.cast(value));
} else if (value instanceof Reference) {
//node.get("value").set(value.toString());
} else {
String jndiViewValue = JndiViewManagedReferenceFactory.DEFAULT_JNDI_VIEW_INSTANCE_VALUE;
if (value instanceof JndiViewManagedReferenceFactory) {
try {
jndiViewValue = JndiViewManagedReferenceFactory.class.cast(value).getJndiViewInstanceValue();
} catch (Throwable e) {
// just log, don't stop the operation
NamingLogger.ROOT_LOGGER.failedToLookupJndiViewValue(pair.getName(), e);
}
} else if (!(value instanceof ManagedReferenceFactory)) {
jndiViewValue = String.valueOf(value);
}
node.get("value").set(jndiViewValue);
}
} catch (NamingException e) {
// just log, don't stop the operation
NamingLogger.ROOT_LOGGER.failedToLookupJndiViewValue(pair.getName(), e);
}
}
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class AbstractResourceInjectionServices method handleServiceLookup.
protected ResourceReferenceFactory<Object> handleServiceLookup(final String result, InjectionPoint injectionPoint) {
final ContextNames.BindInfo ejbBindInfo = getBindInfo(result);
/*
* Try to obtain ManagedReferenceFactory and validate the resource type
*/
final ManagedReferenceFactory factory = getManagedReferenceFactory(ejbBindInfo);
validateResourceInjectionPointType(factory, injectionPoint);
if (factory != null) {
return new ManagedReferenceFactoryToResourceReferenceFactoryAdapter<Object>(factory);
} else {
return createLazyResourceReferenceFactory(ejbBindInfo);
}
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class UndertowDeploymentInfoService method addListener.
private static void addListener(final ClassLoader classLoader, final ComponentRegistry components, final DeploymentInfo d, final ListenerMetaData listener) throws ClassNotFoundException {
ListenerInfo l;
final Class<? extends EventListener> listenerClass = (Class<? extends EventListener>) classLoader.loadClass(listener.getListenerClass());
ManagedReferenceFactory creator = components.createInstanceFactory(listenerClass);
if (creator != null) {
InstanceFactory<EventListener> factory = createInstanceFactory(creator);
l = new ListenerInfo(listenerClass, factory);
} else {
l = new ListenerInfo(listenerClass);
}
d.addListener(l);
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class BinderServiceBuilder method build.
@Override
public ServiceBuilder<ManagedReferenceFactory> build(ServiceTarget target) {
if (!this.enabled) {
// If naming is not enabled, just install a dummy service that never starts
Value<ManagedReferenceFactory> value = new ImmediateValue<>(null);
return target.addService(this.getServiceName(), new ValueService<>(value)).setInitialMode(ServiceController.Mode.NEVER);
}
String name = this.binding.getBindName();
BinderService binder = new BinderService(name);
ServiceBuilder<ManagedReferenceFactory> builder = target.addService(this.getServiceName(), binder).addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(name)).addDependency(this.targetServiceName, this.targetClass, new ManagedReferenceInjector<T>(binder.getManagedObjectInjector())).addDependency(this.binding.getParentContextServiceName(), ServiceBasedNamingStore.class, binder.getNamingStoreInjector());
for (ContextNames.BindInfo alias : this.aliases) {
builder.addAliases(alias.getBinderServiceName(), ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(alias.getBindName()));
}
return builder.setInitialMode(ServiceController.Mode.PASSIVE);
}
use of org.jboss.as.naming.ManagedReferenceFactory in project wildfly by wildfly.
the class EjbJndiBindingsDeploymentUnitProcessor method registerControlPointBinding.
private void registerControlPointBinding(final EJBComponentDescription componentDescription, final ViewDescription viewDescription, final String jndiName, final DeploymentUnit deploymentUnit) {
final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
final InjectedValue<ClassLoader> viewClassLoader = new InjectedValue<ClassLoader>();
final InjectedValue<ControlPoint> controlPointInjectedValue = new InjectedValue<>();
final RemoteViewInjectionSource delegate = new RemoteViewInjectionSource(null, moduleDescription.getEarApplicationName(), moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), viewDescription.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
final ServiceName depName = ControlPointService.serviceName(deploymentUnit.getParent() == null ? deploymentUnit.getName() : deploymentUnit.getParent().getName(), EJBComponentSuspendDeploymentUnitProcessor.ENTRY_POINT_NAME + deploymentUnit.getName() + "." + componentDescription.getComponentName());
componentDescription.getConfigurators().add((context, description, configuration) -> {
viewClassLoader.setValue(Values.immediateValue(configuration.getModuleClassLoader()));
configuration.getCreateDependencies().add((serviceBuilder, service) -> serviceBuilder.addDependency(depName, ControlPoint.class, controlPointInjectedValue));
});
//we need to wrap the injection source to allow graceful shutdown to function, although this is not ideal
//as it will also reject local lookups as well, although in general local code should never be looking up the
//exported bindings
//the other option would be to reject it at the remote naming service level, however then we loose the per-deployment granularity
final InjectionSource is = new InjectionSource() {
@Override
public void getResourceValue(ResolutionContext resolutionContext, ServiceBuilder<?> serviceBuilder, DeploymentPhaseContext phaseContext, Injector<ManagedReferenceFactory> injector) throws DeploymentUnitProcessingException {
final InjectedValue<ManagedReferenceFactory> delegateInjection = new InjectedValue<>();
delegate.getResourceValue(resolutionContext, serviceBuilder, phaseContext, delegateInjection);
injector.inject(new ManagedReferenceFactory() {
@Override
public ManagedReference getReference() {
ControlPoint cp = controlPointInjectedValue.getValue();
try {
RunResult res = cp.beginRequest();
if (res != RunResult.RUN) {
throw EjbLogger.ROOT_LOGGER.containerSuspended();
}
try {
return delegateInjection.getValue().getReference();
} finally {
cp.requestComplete();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
};
moduleDescription.getBindingConfigurations().add(new BindingConfiguration(jndiName, is));
}
Aggregations