Skip to content

Commit 8f4c2d5

Browse files
committed
HHH-10006 - Document configuration of JndiService;
HHH-10007 - Audit Services chapter in Integrations Guide
1 parent 2036280 commit 8f4c2d5

14 files changed

+438
-25
lines changed

documentation/src/main/docbook/integration/en-US/chapters/services/Services.xml

Lines changed: 185 additions & 25 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class DisabledEventPublishingServiceImpl implements EventPublishingService {
2+
public static DisabledEventPublishingServiceImpl INSTANCE = new DisabledEventPublishingServiceImpl();
3+
4+
private DisabledEventPublishingServiceImpl() {
5+
}
6+
7+
@Override
8+
public void publish(Event theEvent) {
9+
// nothing to do...
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public interface EventPublishingService extends Service {
2+
public void publish(Event theEvent);
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class EventPublishingServiceContributor
2+
implements ServiceContributor {
3+
@Override
4+
public void contribute(StandardServiceRegistryBuilder builder) {
5+
builder.addInitiator( EventPublishingServiceInitiator.INSTANCE );
6+
7+
// if we wanted to allow other strategies (e.g. a JMS
8+
// Queue publisher) we might also register short names
9+
// here with the StrategySelector. The initiator would
10+
// then need to accept the strategy as a config setting
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
public class EventPublishingServiceImpl
2+
implements EventPublishingService,
3+
Configurable,
4+
Startable,
5+
Stoppable,
6+
ServiceRegistryAwareService {
7+
8+
private ServiceRegistryImplementor serviceRegistry;
9+
private String jmsConnectionFactoryName;
10+
private String destinationName;
11+
12+
private Connection jmsConnection;
13+
private Session jmsSession;
14+
private MessageProducer publisher;
15+
16+
@Override
17+
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
18+
this.serviceRegistry = serviceRegistry;
19+
}
20+
21+
public void configure(Map configurationValues) {
22+
this.jmsConnectionFactoryName = configurationValues.get( JMS_CONNECTION_FACTORY_NAME_SETTING );
23+
this.destinationName = configurationValues.get( JMS_DESTINATION_NAME_SETTING );
24+
}
25+
26+
@Override
27+
public void start() {
28+
final JndiService jndiService = serviceRegistry.getService( JndiService.class );
29+
final ConnectionFactory jmsConnectionFactory = jndiService.locate( jmsConnectionFactoryName );
30+
31+
this.jmsConnection = jmsConnectionFactory.createConnection();
32+
this.jmsSession = jmsConnection.createSession( true, Session.AUTO_ACKNOWLEDGE );
33+
34+
final Destination destination = jndiService.locate( destinationName );
35+
36+
this.publisher = jmsSession.createProducer( destination );
37+
}
38+
39+
@Override
40+
public void publish(Event theEvent) {
41+
publisher.send( theEvent );
42+
}
43+
44+
@Override
45+
public void stop() {
46+
publisher.close();
47+
jmsSession.close();
48+
jmsConnection.close();
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class EventPublishingServiceInitiator implements StandardServiceInitiator<EventPublishingService> {
2+
public static EventPublishingServiceInitiator INSTANCE = new EventPublishingServiceInitiator();
3+
public static final String ENABLE_PUBLISHING_SETTING = "com.acme.EventPublishingService.enabled";
4+
5+
@Override
6+
public Class<R> getServiceInitiated() {
7+
return EventPublishingService.class;
8+
}
9+
10+
@Override
11+
public R initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
12+
final boolean enabled = extractBoolean( configurationValues, ENABLE_PUBLISHING_SETTING );
13+
if ( enabled ) {
14+
return new EventPublishingServiceImpl();
15+
}
16+
else {
17+
return DisabledEventPublishingServiceImpl.INSTANCE;
18+
}
19+
}
20+
21+
...
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import java.lang.Override;
2+
3+
public class LatestAndGreatestConnectionProviderImpl
4+
implements ConnectionProvider, Startable, Stoppable, Configurable {
5+
6+
private LatestAndGreatestPoolBuilder lagPoolBuilder;
7+
private LatestAndGreatestPool lagPool;
8+
private boolean available = false;
9+
10+
@Override
11+
public void configure(Map configurationValues) {
12+
// extract our config from the settings map
13+
lagPoolBuilder = buildBuilder( configurationValues );
14+
}
15+
16+
@Override
17+
public void start() {
18+
// start the underlying pool
19+
lagPool = lagPoolBuilder.buildPool();
20+
21+
available = true;
22+
}
23+
24+
@Override
25+
public void stop() {
26+
available = true;
27+
28+
// stop the underlying pool
29+
lagPool.shutdown();
30+
}
31+
32+
@Override
33+
public Connection getConnection() throws SQLException {
34+
if ( !available ) {
35+
throwException( "LatestAndGreatest ConnectionProvider not available for use" )
36+
}
37+
38+
return lagPool.borrowConnection();
39+
}
40+
41+
@Override
42+
public void closeConnection(Connection conn) throws SQLException {
43+
if ( !available ) {
44+
warn( "LatestAndGreatest ConnectionProvider not available for use" )
45+
}
46+
47+
if ( conn == null ) {
48+
return;
49+
}
50+
51+
lagPool.releaseConnection( conn );
52+
}
53+
54+
...
55+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
StandardServiceRegistryBuilder builder = ...;
2+
...
3+
builder.addService(
4+
ConnectionProvider.class,
5+
new LatestAndGreatestConnectionProviderImpl()
6+
);
7+
...
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class LatestAndGreatestConnectionProviderImplContributor1
2+
implements ServiceContributor {
3+
@Override
4+
public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) {
5+
serviceRegistryBuilder.addService(
6+
ConnectionProvider.class,
7+
new LatestAndGreatestConnectionProviderImpl()
8+
);
9+
}
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fully.qualified.package.LatestAndGreatestConnectionProviderImplContributor1

0 commit comments

Comments
 (0)