Skip to content

Instantly share code, notes, and snippets.

Created Feb 12, 2010
Embed
What would you like to do?
package localdomain.localhost;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import java.lang.Object;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import localdomain.localhost.resource.api.Connection;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* Created by IntelliJ IDEA.
*
* @author Stephen Connolly
* @since 28-Jan-2010 17:26:51
*/
public class FooTest
{
@Test
public void test() throws Exception {
Properties p = new Properties();
// make sure we can shut down the context when we need to
p.setProperty("openejb.embedded.initialcontext.close", "destroy");
p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
p.setProperty("java:/ConfMgmtConnectionFactory", "new://Resource?type=MyConnectionFactory&provider=myNamespace%23classesRA");
InitialContext initialContext = new InitialContext(p);
try {
final SimpleLocal o = (SimpleLocal) initialContext.lookup("SimpleEJBLocal");
System.out.println("ejb = " + o);
for (int n = 0; n < 20; n++) {
Connection con = null;
try {
con = o.getConnection(n);
assertThat(con.getInt(), is(n));
} finally {
if (con != null) {
con.close();
}
}
}
} finally {
initialContext.close();
}
}
}
----
package localdomain.localhost;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
import java.lang.Object;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import localdomain.localhost.resource.api.Connection;
import localdomain.localhost.resource.api.ConnectionFactory;
import localdomain.localhost.resource.api.ResourceException;
/**
* Created by IntelliJ IDEA.
*
* @author Stephen Connolly
* @since 12-Feb-2010 07:40:37
*/
@Stateless
public class SimpleEJB implements SimpleLocal {
@Resource(mappedName="java:/ConfMgmtConnectionFactory", authenticationType = Resource.AuthenticationType.CONTAINER, shareable = true)
ConnectionFactory conn;
public Connection getConnection(int number) throws ResourceException
{
return conn.getConnection(number);
}
}
---
<?xml version="1.0" encoding="UTF-8"?>
<ServiceJar>
<ServiceProvider
id="classes"
service="Resource"
types="localdomain.localhost.resource.api.ConnectionFactory, MyConnectionFactory"
class-name="localdomain.localhost.resource.impl.ManagedConnectionFactoryImpl">
ResourceAdapter classesRA
PartitionStrategy by-connector-properties
# Specifies if the connection is enrolled in global transaction
# allowed values: xa, local or none
TransactionSupport none
# Maximum number of physical connection to the ActiveMQ broker
PoolMaxSize 10
# Minimum number of physical connection to the ActiveMQ broker
PoolMinSize 0
# Maximum amount of time to wait for a connection
ConnectionMaxWaitMilliseconds 5000
# Maximum amount of time a connection can be idle before being reclaimed
ConnectionMaxIdleMinutes 15
</ServiceProvider>
</ServiceJar>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment