Search in sources :

Example 1 with Logger

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");
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) EjbModule(org.apache.openejb.config.EjbModule) Logger(org.apache.openejb.util.Logger) Properties(java.util.Properties) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) ResourceException(javax.resource.ResourceException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) SecurityException(java.lang.SecurityException) NotSupportedException(javax.resource.NotSupportedException) InvalidPropertyException(javax.resource.spi.InvalidPropertyException) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ContainerInfo(org.apache.openejb.assembler.classic.ContainerInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) Ignore(org.junit.Ignore)

Example 2 with Logger

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;
}
Also used : ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) Logger(org.apache.openejb.util.Logger) SuperProperties(org.apache.openejb.util.SuperProperties) Properties(java.util.Properties) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 3 with Logger

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);
}
Also used : Logger(org.apache.openejb.util.Logger)

Example 4 with Logger

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);
    }
}
Also used : Logger(org.apache.openejb.util.Logger)

Example 5 with Logger

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);
    }
}
Also used : ArrayList(java.util.ArrayList) MethodContext(org.apache.openejb.MethodContext) Duration(org.apache.openejb.util.Duration) Method(java.lang.reflect.Method) Logger(org.apache.openejb.util.Logger) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Logger (org.apache.openejb.util.Logger)10 HashMap (java.util.HashMap)4 Map (java.util.Map)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)2 LoggerCreator (org.apache.openejb.log.LoggerCreator)2 JuliLogStream (org.apache.openejb.util.JuliLogStream)2 SecurityException (java.lang.SecurityException)1 MalformedURLException (java.net.MalformedURLException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 TreeMap (java.util.TreeMap)1 Handler (java.util.logging.Handler)1 LogRecord (java.util.logging.LogRecord)1 NotSupportedException (javax.resource.NotSupportedException)1 ResourceException (javax.resource.ResourceException)1