use of org.apache.openejb.util.Logger in project tomee by apache.
the class AutoConnectionTrackerTest method test.
@Ignore
public void test() throws Exception {
System.setProperty("openejb.log.async", "false");
final Logger logger = Logger.getInstance(LogCategory.OPENEJB_CONNECTOR, AutoConnectionTrackerTest.class);
logger.info("Starting test");
final java.util.logging.Logger julLogger = LogManager.getLogManager().getLogger(LogCategory.OPENEJB_CONNECTOR.getName());
final LogCaptureHandler logCapture = new LogCaptureHandler();
julLogger.addHandler(logCapture);
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
// System services
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// JMS persistence datasource
final ResourceInfo dataSourceInfo = config.configureService("Default Unmanaged JDBC Database", ResourceInfo.class);
dataSourceInfo.properties.setProperty("JdbcUrl", "jdbc:hsqldb:mem:MdbConfigTest");
assembler.createResource(dataSourceInfo);
// FakeRA
final ResourceInfo resourceInfo = new ResourceInfo();
resourceInfo.service = "Resource";
resourceInfo.className = FakeRA.class.getName();
resourceInfo.id = "FakeRA";
resourceInfo.properties = new Properties();
assembler.createResource(resourceInfo);
// FakeRA container
final ContainerInfo containerInfo = config.configureService(MdbContainerInfo.class);
containerInfo.id = "FakeContainer";
containerInfo.displayName = "Fake Container";
containerInfo.properties.setProperty("ResourceAdapter", "FakeRA");
containerInfo.properties.setProperty("MessageListenerInterface", FakeMessageListener.class.getName());
containerInfo.properties.setProperty("ActivationSpecClass", FakeActivationSpec.class.getName());
assembler.createContainer(containerInfo);
// Fake connection factory
final ResourceInfo mcfResourceInfo = new ResourceInfo();
mcfResourceInfo.className = FakeManagedConnectionFactory.class.getName();
mcfResourceInfo.id = "FakeConnectionFactory";
mcfResourceInfo.types = Collections.singletonList(FakeConnectionFactory.class.getName());
mcfResourceInfo.properties = new Properties();
mcfResourceInfo.properties.setProperty("ResourceAdapter", "FakeRA");
mcfResourceInfo.properties.setProperty("TransactionSupport", "None");
mcfResourceInfo.properties.setProperty("allConnectionsEqual", "false");
assembler.createResource(mcfResourceInfo);
// generate ejb jar application
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean("TestBean", FakeStatelessBean.class));
final EjbModule ejbModule = new EjbModule(getClass().getClassLoader(), "FakeEjbJar", "fake.jar", ejbJar, null);
// configure and deploy it
final EjbJarInfo info = config.configureApplication(ejbModule);
assembler.createEjbJar(info);
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final FakeConnectionFactory cf = (FakeConnectionFactory) containerSystem.getJNDIContext().lookup("openejb:Resource/FakeConnectionFactory");
final FakeRemote bean = (FakeRemote) containerSystem.getJNDIContext().lookup("java:global/FakeEjbJar/FakeEjbJar/TestBean!org.apache.openejb.resource.AutoConnectionTrackerTest$FakeRemote");
{
logCapture.clear();
runTest(new Runnable() {
@Override
public void run() {
try {
bean.nonLeakyTxMethod();
System.gc();
} catch (Exception e) {
e.printStackTrace();
}
}
});
System.gc();
cf.getConnection().close();
assertLogs(logCapture, 0, "Transaction complete, but connection still has handles associated");
assertLogs(logCapture, 0, "Detected abandoned connection");
assertTrue(getConnectionCount((FakeConnectionFactoryImpl) cf) > 0);
}
{
logCapture.clear();
runTest(new Runnable() {
@Override
public void run() {
try {
bean.nonleakyNonTxMethod();
} catch (Exception e) {
e.printStackTrace();
}
}
});
System.gc();
cf.getConnection().close();
assertLogs(logCapture, 0, "Transaction complete, but connection still has handles associated");
assertLogs(logCapture, 0, "Detected abandoned connection");
assertTrue(getConnectionCount((FakeConnectionFactoryImpl) cf) > 0);
}
{
logCapture.clear();
bean.leakyTxMethod();
System.gc();
final AutoConnectionTracker tracker = getAutoConnectionTracker((FakeConnectionFactoryImpl) cf);
tracker.setEnvironment(null, null);
assertLogs(logCapture, 1, "Transaction complete, but connection still has handles associated");
assertLogs(logCapture, 1, "Detected abandoned connection");
}
{
logCapture.clear();
bean.leakyNonTxMethod();
System.gc();
final AutoConnectionTracker tracker = getAutoConnectionTracker((FakeConnectionFactoryImpl) cf);
tracker.setEnvironment(null, null);
assertLogs(logCapture, 1, "Detected abandoned connection");
}
}
use of org.apache.openejb.util.Logger in project tomee by apache.
the class Assembler method createRecipe.
private ObjectRecipe createRecipe(final Collection<ServiceInfo> services, final ServiceInfo info) {
final Logger serviceLogger = logger.getChildLogger("service");
if (info instanceof ResourceInfo) {
final List<String> aliasesList = ((ResourceInfo) info).aliases;
if (!aliasesList.isEmpty()) {
final String aliases = Join.join(", ", aliasesList);
serviceLogger.info("createServiceWithAliases", info.service, info.id, aliases);
} else {
serviceLogger.info("createService", info.service, info.id);
}
} else {
serviceLogger.info("createService", info.service, info.id);
}
final ObjectRecipe serviceRecipe = prepareRecipe(info);
// we don't want this one to go in recipe
final Object value = info.properties.remove("SkipImplicitAttributes");
final Properties allProperties = PropertyPlaceHolderHelper.simpleHolds(info.properties);
allProperties.remove("SkipPropertiesFallback");
if (services == null) {
// small optim for internal resources
serviceRecipe.setAllProperties(allProperties);
} else {
info.properties = allProperties;
ServiceInfos.setProperties(services, info, serviceRecipe);
}
if (value != null) {
info.properties.put("SkipImplicitAttributes", value);
}
if (serviceLogger.isDebugEnabled()) {
for (final Map.Entry<String, Object> entry : serviceRecipe.getProperties().entrySet()) {
serviceLogger.debug("createService.props", entry.getKey(), entry.getValue());
}
}
return serviceRecipe;
}
use of org.apache.openejb.util.Logger in project tomee by apache.
the class Assembler method unusedProperty.
private static void unusedProperty(final String id, final String property) {
final Assembler component = SystemInstance.get().getComponent(Assembler.class);
final Logger logger = component != null ? component.logger : null;
unusedProperty(id, logger, property);
}
use of org.apache.openejb.util.Logger in project tomee by apache.
the class Assembler method logUnusedProperties.
private static void logUnusedProperties(final Map<String, ?> unsetProperties, final ServiceInfo info) {
if (isPassthroughType(info)) {
return;
}
final boolean ignoreJdbcDefault = "Annotation".equalsIgnoreCase(info.properties.getProperty("Origin"));
Logger logger = null;
for (final String property : unsetProperties.keySet()) {
// TODO: DMB: Make more robust later
if (ignoreJdbcDefault && ("JdbcUrl".equals(property) || "UserName".equals(property) || "Password".equals(property) || "PasswordCipher".equals(property))) {
continue;
}
if (property.equalsIgnoreCase("Definition")) {
continue;
}
if (property.equalsIgnoreCase("SkipImplicitAttributes")) {
continue;
}
if (property.equalsIgnoreCase("JndiName")) {
continue;
}
if (property.equalsIgnoreCase("Origin")) {
continue;
}
if (property.equalsIgnoreCase("DatabaseName")) {
continue;
}
if (property.equalsIgnoreCase("connectionAttributes")) {
return;
}
if (property.equalsIgnoreCase("properties")) {
return;
}
if (property.equalsIgnoreCase("ApplicationWide")) {
continue;
}
if (property.equalsIgnoreCase("OpenEJBResourceClasspath")) {
continue;
}
if (isInternalProperty(property)) {
continue;
}
if (info.types.isEmpty() && "class".equalsIgnoreCase(property)) {
// inline service (no sp)
continue;
}
if ("destination".equalsIgnoreCase(property) && info.id.equals(unsetProperties.get("destination"))) {
continue;
}
if (logger == null) {
final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
if (assembler != null) {
logger = assembler.logger;
} else {
System.err.println("Assembler has not been initialized");
}
}
unusedProperty(info.id, logger, property);
}
}
use of org.apache.openejb.util.Logger in project tomee by apache.
the class MethodConcurrencyBuilder method applyConcurrencyAttributes.
public static void applyConcurrencyAttributes(final BeanContext beanContext, final List<MethodConcurrencyInfo> methodConcurrencyInfos) throws OpenEJBException {
if (beanContext.isBeanManagedConcurrency()) {
return;
}
final Logger log = Logger.getInstance(LogCategory.OPENEJB_STARTUP.createChild("attributes"), MethodConcurrencyBuilder.class);
final List<MethodConcurrencyInfo> lockInfos = new ArrayList<>();
final List<MethodConcurrencyInfo> accessTimeoutInfos = new ArrayList<>();
MethodConcurrencyBuilder.normalize(methodConcurrencyInfos, lockInfos, accessTimeoutInfos);
Map<Method, MethodAttributeInfo> attributes;
// handle @Lock
attributes = MethodInfoUtil.resolveAttributes(lockInfos, beanContext);
if (log.isDebugEnabled()) {
for (final Map.Entry<Method, MethodAttributeInfo> entry : attributes.entrySet()) {
final Method method = entry.getKey();
final MethodConcurrencyInfo value = (MethodConcurrencyInfo) entry.getValue();
log.debug("Lock: " + method + " -- " + MethodInfoUtil.toString(value.methods.get(0)) + " " + value.concurrencyAttribute);
}
}
for (final Map.Entry<Method, MethodAttributeInfo> entry : attributes.entrySet()) {
final MethodConcurrencyInfo value = (MethodConcurrencyInfo) entry.getValue();
final MethodContext methodContext = beanContext.getMethodContext(entry.getKey());
final String s = value.concurrencyAttribute.toUpperCase();
methodContext.setLockType(LockType.valueOf(s));
}
// handle @AccessTimeout
attributes = MethodInfoUtil.resolveAttributes(accessTimeoutInfos, beanContext);
if (log.isDebugEnabled()) {
for (final Map.Entry<Method, MethodAttributeInfo> entry : attributes.entrySet()) {
final Method method = entry.getKey();
final MethodConcurrencyInfo value = (MethodConcurrencyInfo) entry.getValue();
log.debug("AccessTimeout: " + method + " -- " + MethodInfoUtil.toString(value.methods.get(0)) + " " + " " + value.accessTimeout.time + " " + value.accessTimeout.unit);
}
}
for (final Map.Entry<Method, MethodAttributeInfo> entry : attributes.entrySet()) {
final MethodConcurrencyInfo value = (MethodConcurrencyInfo) entry.getValue();
final MethodContext methodContext = beanContext.getMethodContext(entry.getKey());
final Duration accessTimeout = new Duration(value.accessTimeout.time, TimeUnit.valueOf(value.accessTimeout.unit));
methodContext.setAccessTimeout(accessTimeout);
}
}
Aggregations