Skip to content

Commit 6a2943b

Browse files
Cleaned up the code and applied coding standards
1 parent cc1fb76 commit 6a2943b

21 files changed

+184
-214
lines changed

ojdbc-provider-observability/pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@
5050
<artifactId>junit-jupiter-params</artifactId>
5151
<scope>test</scope>
5252
</dependency>
53-
<dependency>
54-
<groupId>junit</groupId>
55-
<artifactId>junit</artifactId>
56-
<version>4.13.2</version>
57-
<scope>test</scope>
58-
</dependency>
5953
<dependency>
6054
<groupId>io.opentelemetry</groupId>
6155
<artifactId>opentelemetry-sdk</artifactId>
@@ -65,7 +59,7 @@
6559
<dependency>
6660
<groupId>io.opentelemetry</groupId>
6761
<artifactId>opentelemetry-sdk-testing</artifactId>
68-
<version>1.32.0</version>
62+
<version>${opentelemetry.version}</version>
6963
<scope>test</scope>
7064
</dependency>
7165
<dependency>

ojdbc-provider-observability/src/main/java/oracle/ucp/provider/observability/jfr/core/JFRUCPEventListenerProvider.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,21 @@
1010
* Provider that supplies a UCP event listener for recording JFR events.
1111
* Integrates UCP events with Java Flight Recorder for low-overhead monitoring.
1212
*/
13-
public final class JFRUCPEventListenerProvider implements UCPEventListenerProvider {
14-
15-
private final UCPEventListener listener;
13+
public final class JFRUCPEventListenerProvider
14+
implements UCPEventListenerProvider {
1615

1716
/**
1817
* Singleton listener that records UCP events as JFR events.
1918
* Thread-safe and optimized for minimal overhead.
2019
*/
21-
public static final UCPEventListener TRACE_EVENT_LISTENER = new UCPEventListener() {
20+
public static final UCPEventListener TRACE_EVENT_LISTENER =
21+
new UCPEventListener() {
2222
@Override
2323
public void onUCPEvent(EventType eventType, UCPEventContext context) {
2424
UCPEventFactory.recordEvent(eventType, context);
2525
}
2626
};
2727

28-
/**
29-
* Creates a new provider instance.
30-
*/
31-
public JFRUCPEventListenerProvider() {
32-
this.listener = TRACE_EVENT_LISTENER;
33-
}
34-
3528
/**
3629
* Returns the provider's unique identifier.
3730
*
@@ -50,6 +43,6 @@ public String getName() {
5043
*/
5144
@Override
5245
public UCPEventListener getListener(Map<String, String> config) {
53-
return listener;
46+
return TRACE_EVENT_LISTENER;
5447
}
5548
}

ojdbc-provider-observability/src/main/java/oracle/ucp/provider/observability/jfr/core/UCPBaseEvent.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import java.util.Objects;
77

88
/**
9-
* Abstract base class for UCP JFR events providing common fields and initialization.
10-
* All UCP events extend this class to inherit standard pool metrics and metadata.
9+
* Abstract base class for UCP JFR events providing common fields
10+
* and initialization. All UCP events extend this class to inherit
11+
* standard pool metrics and metadata.
1112
*/
1213
@Category("UCP Events")
1314
@Description("Base UCP Event")
@@ -19,6 +20,7 @@ public abstract class UCPBaseEvent extends Event {
1920

2021
/** Event timestamp in milliseconds since epoch */
2122
@Label("Timestamp")
23+
@Timestamp(Timestamp.MILLISECONDS_SINCE_EPOCH)
2224
protected long timestamp;
2325

2426
/** Maximum configured pool size */
Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package oracle.ucp.provider.observability.jfr.core;
22

3+
import java.util.Objects;
4+
35
import jdk.jfr.Event;
46
import oracle.ucp.events.core.UCPEventContext;
57
import oracle.ucp.events.core.UCPEventListener;
@@ -9,7 +11,8 @@
911

1012
/**
1113
* Factory for creating and recording JFR events from UCP operations.
12-
* Maps UCP event types to specific JFR event classes and handles recording.
14+
* Maps UCP event types to specific JFR event classes and handles
15+
* recording.
1316
*/
1417
public class UCPEventFactory {
1518

@@ -22,56 +25,62 @@ public class UCPEventFactory {
2225
* @throws IllegalStateException if event type is unrecognized
2326
* @throws NullPointerException if parameters are null
2427
*/
25-
public static Event createEvent(UCPEventListener.EventType type, UCPEventContext ctx) {
28+
public static Event createEvent(
29+
UCPEventListener.EventType type, UCPEventContext ctx) {
30+
Objects.requireNonNull(type, "EventType cannot be null");
2631
switch (type) {
27-
// Pool Lifecycle Events
28-
case POOL_CREATED:
29-
return new PoolCreatedEvent(ctx);
30-
case POOL_STARTING:
31-
return new PoolStartingEvent(ctx);
32-
case POOL_STARTED:
33-
return new PoolStartedEvent(ctx);
34-
case POOL_STOPPED:
35-
return new PoolStoppedEvent(ctx);
36-
case POOL_RESTARTING:
37-
return new PoolRestartingEvent(ctx);
38-
case POOL_RESTARTED:
39-
return new PoolRestartedEvent(ctx);
40-
case POOL_DESTROYED:
41-
return new PoolDestroyedEvent(ctx);
32+
// Pool Lifecycle Events
33+
case POOL_CREATED:
34+
return new PoolCreatedEvent(ctx);
35+
case POOL_STARTING:
36+
return new PoolStartingEvent(ctx);
37+
case POOL_STARTED:
38+
return new PoolStartedEvent(ctx);
39+
case POOL_STOPPED:
40+
return new PoolStoppedEvent(ctx);
41+
case POOL_DESTROYED:
42+
return new PoolDestroyedEvent(ctx);
4243

43-
// Connection Lifecycle Events
44-
case CONNECTION_CREATED:
45-
return new ConnectionCreatedEvent(ctx);
46-
case CONNECTION_BORROWED:
47-
return new ConnectionBorrowedEvent(ctx);
48-
case CONNECTION_RETURNED:
49-
return new ConnectionReturnedEvent(ctx);
50-
case CONNECTION_CLOSED:
51-
return new ConnectionClosedEvent(ctx);
44+
// Connection Lifecycle Events
45+
case CONNECTION_CREATED:
46+
return new ConnectionCreatedEvent(ctx);
47+
case CONNECTION_BORROWED:
48+
return new ConnectionBorrowedEvent(ctx);
49+
case CONNECTION_RETURNED:
50+
return new ConnectionReturnedEvent(ctx);
51+
case CONNECTION_CLOSED:
52+
return new ConnectionClosedEvent(ctx);
5253

53-
// Maintenance Operations
54-
case POOL_REFRESHED:
55-
return new PoolRefreshedEvent(ctx);
56-
case POOL_RECYCLED:
57-
return new PoolRecycledEvent(ctx);
58-
case POOL_PURGED:
59-
return new PoolPurgedEvent(ctx);
54+
// Maintenance Operations
55+
case POOL_REFRESHED:
56+
return new PoolRefreshedEvent(ctx);
57+
case POOL_RECYCLED:
58+
return new PoolRecycledEvent(ctx);
59+
case POOL_PURGED:
60+
return new PoolPurgedEvent(ctx);
6061

61-
default:
62-
throw new IllegalStateException("Unexpected event type: " + type);
62+
default:
63+
throw new IllegalStateException(
64+
"Unexpected event type: " + type);
6365
}
6466
}
6567

6668
/**
67-
* Creates and immediately records a JFR event for the UCP operation.
69+
* Creates and immediately records a JFR event for the UCP
70+
* operation. POOL_RESTARTING and POOL_RESTARTED events are
71+
* silently ignored.
6872
*
6973
* @param type UCP event type to record
7074
* @param ctx event context with pool metrics
7175
* @throws NullPointerException if parameters are null
7276
*/
73-
public static void recordEvent(UCPEventListener.EventType type, UCPEventContext ctx) {
77+
public static void recordEvent(
78+
UCPEventListener.EventType type, UCPEventContext ctx) {
79+
if (type == UCPEventListener.EventType.POOL_RESTARTING
80+
|| type == UCPEventListener.EventType.POOL_RESTARTED) {
81+
return;
82+
}
7483
Event event = createEvent(type, ctx);
7584
event.commit();
7685
}
77-
}
86+
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package oracle.ucp.provider.observability.jfr.events.connection;
22

3-
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
43
import jdk.jfr.Category;
54
import jdk.jfr.Label;
65
import jdk.jfr.Name;
76
import oracle.ucp.events.core.UCPEventContext;
7+
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
88

99
@Name("ucp.ConnectionBorrowed")
1010
@Label("Connection Borrowed")
11-
@Category({"UCP Events","Connection Lifecycle Events"})
11+
@Category({"UCP Events", "Connection Lifecycle Events"})
1212
public class ConnectionBorrowedEvent extends UCPBaseEvent {
13+
1314
public ConnectionBorrowedEvent(UCPEventContext ctx) {
14-
initCommonFields(ctx);
15-
}
16-
}
15+
initCommonFields(ctx);
16+
}
17+
}

ojdbc-provider-observability/src/main/java/oracle/ucp/provider/observability/jfr/events/connection/ConnectionClosedEvent.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import jdk.jfr.Category;
44
import jdk.jfr.Label;
55
import jdk.jfr.Name;
6-
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
76
import oracle.ucp.events.core.UCPEventContext;
7+
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
88

99
@Name("ucp.ConnectionClosed")
1010
@Label("Connection Closed")
11-
@Category({"UCP Events","Connection Lifecycle Events"})
11+
@Category({"UCP Events", "Connection Lifecycle Events"})
1212
public class ConnectionClosedEvent extends UCPBaseEvent {
13+
1314
public ConnectionClosedEvent(UCPEventContext ctx) {
1415
initCommonFields(ctx);
1516
}
16-
}
17+
}

ojdbc-provider-observability/src/main/java/oracle/ucp/provider/observability/jfr/events/connection/ConnectionCreatedEvent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package oracle.ucp.provider.observability.jfr.events.connection;
22

3-
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
43
import jdk.jfr.Category;
54
import jdk.jfr.Label;
65
import jdk.jfr.Name;
76
import oracle.ucp.events.core.UCPEventContext;
7+
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
88

99
@Name("ucp.ConnectionCreated")
1010
@Label("Connection Created")
11-
@Category({"UCP Events","Connection Lifecycle Events"})
11+
@Category({"UCP Events", "Connection Lifecycle Events"})
1212
public class ConnectionCreatedEvent extends UCPBaseEvent {
13+
1314
public ConnectionCreatedEvent(UCPEventContext ctx) {
1415
initCommonFields(ctx);
1516
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package oracle.ucp.provider.observability.jfr.events.connection;
22

3-
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
43
import jdk.jfr.Category;
54
import jdk.jfr.Label;
65
import jdk.jfr.Name;
76
import oracle.ucp.events.core.UCPEventContext;
7+
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
88

99
@Name("ucp.ConnectionReturned")
1010
@Label("Connection Returned")
11-
@Category({"UCP Events","Connection Lifecycle Events"})
11+
@Category({"UCP Events", "Connection Lifecycle Events"})
1212
public class ConnectionReturnedEvent extends UCPBaseEvent {
13+
1314
public ConnectionReturnedEvent(UCPEventContext ctx) {
14-
initCommonFields(ctx);
15-
}
16-
}
15+
initCommonFields(ctx);
16+
}
17+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package oracle.ucp.provider.observability.jfr.events.lifecycle;
22

3-
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
43
import jdk.jfr.Category;
5-
import jdk.jfr.Description;
64
import jdk.jfr.Label;
75
import jdk.jfr.Name;
86
import oracle.ucp.events.core.UCPEventContext;
7+
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
98

109
@Name("ucp.PoolCreated")
1110
@Label("Pool Created")
12-
@Category({"UCP Events","Pool Lifecycle Events"})
11+
@Category({"UCP Events", "Pool Lifecycle Events"})
1312
public class PoolCreatedEvent extends UCPBaseEvent {
13+
1414
public PoolCreatedEvent(UCPEventContext ctx) {
15-
initCommonFields(ctx);
16-
}
17-
}
15+
initCommonFields(ctx);
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package oracle.ucp.provider.observability.jfr.events.lifecycle;
22

3-
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
43
import jdk.jfr.Category;
54
import jdk.jfr.Label;
65
import jdk.jfr.Name;
76
import oracle.ucp.events.core.UCPEventContext;
7+
import oracle.ucp.provider.observability.jfr.core.UCPBaseEvent;
88

99
@Name("ucp.PoolDestroyed")
1010
@Label("Pool Destroyed")
11-
@Category({"UCP Events","Pool Lifecycle Events"})
11+
@Category({"UCP Events", "Pool Lifecycle Events"})
1212
public class PoolDestroyedEvent extends UCPBaseEvent {
13-
public PoolDestroyedEvent(UCPEventContext ctx) { initCommonFields(ctx); }
13+
14+
public PoolDestroyedEvent(UCPEventContext ctx) {
15+
initCommonFields(ctx);
16+
}
1417
}

0 commit comments

Comments
 (0)