Skip to content

Commit ad8f70c

Browse files
Move plugins around
1 parent 9bf8501 commit ad8f70c

File tree

11 files changed

+92
-94
lines changed

11 files changed

+92
-94
lines changed

temporal-sdk/src/main/java/io/temporal/common/plugin/ClientPlugin.java renamed to temporal-sdk/src/main/java/io/temporal/client/Plugin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
* limitations under the License.
1919
*/
2020

21-
package io.temporal.common.plugin;
21+
package io.temporal.client;
2222

23-
import io.temporal.client.WorkflowClientOptions;
2423
import io.temporal.common.Experimental;
24+
import io.temporal.common.PluginBase;
2525
import io.temporal.serviceclient.WorkflowServiceStubs;
2626
import io.temporal.serviceclient.WorkflowServiceStubs.ClientPluginCallback;
2727
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
@@ -65,11 +65,11 @@
6565
* }
6666
* }</pre>
6767
*
68-
* @see WorkerPlugin
68+
* @see io.temporal.worker.Plugin
6969
* @see PluginBase
7070
*/
7171
@Experimental
72-
public interface ClientPlugin extends ClientPluginCallback {
72+
public interface Plugin extends ClientPluginCallback {
7373

7474
/**
7575
* Returns a unique name for this plugin. Used for logging and duplicate detection. Recommended

temporal-sdk/src/main/java/io/temporal/client/WorkflowClientInternalImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.temporal.common.WorkflowExecutionHistory;
1616
import io.temporal.common.interceptors.WorkflowClientCallsInterceptor;
1717
import io.temporal.common.interceptors.WorkflowClientInterceptor;
18-
import io.temporal.common.plugin.ClientPlugin;
1918
import io.temporal.internal.WorkflowThreadMarker;
2019
import io.temporal.internal.client.*;
2120
import io.temporal.internal.client.NexusStartWorkflowResponse;
@@ -788,8 +787,8 @@ private static WorkflowClientOptions applyClientPluginConfiguration(
788787

789788
WorkflowClientOptions.Builder builder = WorkflowClientOptions.newBuilder(options);
790789
for (Object plugin : plugins) {
791-
if (plugin instanceof ClientPlugin) {
792-
builder = ((ClientPlugin) plugin).configureClient(builder);
790+
if (plugin instanceof Plugin) {
791+
builder = ((Plugin) plugin).configureClient(builder);
793792
}
794793
}
795794
return builder.build();

temporal-sdk/src/main/java/io/temporal/client/WorkflowClientOptions.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,14 @@ public Builder setQueryRejectCondition(QueryRejectCondition queryRejectCondition
140140
* Sets the plugins to use with this client. Plugins can modify client and worker configuration,
141141
* intercept connection, and wrap execution lifecycle.
142142
*
143-
* <p>Each plugin should implement {@link io.temporal.common.plugin.ClientPlugin} and/or {@link
144-
* io.temporal.common.plugin.WorkerPlugin}. Plugins that implement both interfaces are
145-
* automatically propagated to workers created from this client.
143+
* <p>Each plugin should implement {@link io.temporal.client.Plugin} and/or {@link
144+
* io.temporal.worker.Plugin}. Plugins that implement both interfaces are automatically
145+
* propagated to workers created from this client.
146146
*
147-
* @param plugins the list of plugins to use (each should implement ClientPlugin and/or
148-
* WorkerPlugin)
147+
* @param plugins the list of plugins to use (each should implement Plugin)
149148
* @return this builder for chaining
150-
* @see io.temporal.common.plugin.ClientPlugin
151-
* @see io.temporal.common.plugin.WorkerPlugin
149+
* @see io.temporal.client.Plugin
150+
* @see io.temporal.worker.Plugin
152151
*/
153152
@Experimental
154153
public Builder setPlugins(List<?> plugins) {
@@ -160,14 +159,14 @@ public Builder setPlugins(List<?> plugins) {
160159
* Adds a plugin to use with this client. Plugins can modify client and worker configuration,
161160
* intercept connection, and wrap execution lifecycle.
162161
*
163-
* <p>The plugin should implement {@link io.temporal.common.plugin.ClientPlugin} and/or {@link
164-
* io.temporal.common.plugin.WorkerPlugin}. Plugins that implement both interfaces are
165-
* automatically propagated to workers created from this client.
162+
* <p>The plugin should implement {@link io.temporal.client.Plugin} and/or {@link
163+
* io.temporal.worker.Plugin}. Plugins that implement both interfaces are automatically
164+
* propagated to workers created from this client.
166165
*
167-
* @param plugin the plugin to add (should implement ClientPlugin and/or WorkerPlugin)
166+
* @param plugin the plugin to add (should implement Plugin)
168167
* @return this builder for chaining
169-
* @see io.temporal.common.plugin.ClientPlugin
170-
* @see io.temporal.common.plugin.WorkerPlugin
168+
* @see io.temporal.client.Plugin
169+
* @see io.temporal.worker.Plugin
171170
*/
172171
@Experimental
173172
public Builder addPlugin(Object plugin) {
@@ -293,9 +292,9 @@ public QueryRejectCondition getQueryRejectCondition() {
293292
/**
294293
* Returns the list of plugins configured for this client.
295294
*
296-
* <p>Each plugin implements {@link io.temporal.common.plugin.ClientPlugin} and/or {@link
297-
* io.temporal.common.plugin.WorkerPlugin}. Plugins that implement both interfaces are
298-
* automatically propagated to workers created from this client.
295+
* <p>Each plugin implements {@link io.temporal.client.Plugin} and/or {@link
296+
* io.temporal.worker.Plugin}. Plugins that implement both interfaces are automatically propagated
297+
* to workers created from this client.
299298
*
300299
* @return an unmodifiable list of plugins, never null
301300
*/

temporal-sdk/src/main/java/io/temporal/common/plugin/PluginBase.java renamed to temporal-sdk/src/main/java/io/temporal/common/PluginBase.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
* limitations under the License.
1919
*/
2020

21-
package io.temporal.common.plugin;
21+
package io.temporal.common;
2222

23-
import io.temporal.common.Experimental;
23+
import io.temporal.client.Plugin;
2424
import java.util.Objects;
2525
import javax.annotation.Nonnull;
2626

2727
/**
28-
* Convenience base class for plugins that implement both {@link ClientPlugin} and {@link
29-
* WorkerPlugin}. All methods have default no-op implementations.
28+
* Convenience base class for plugins that implement both {@link io.temporal.client.Plugin} and
29+
* {@link io.temporal.worker.Plugin}. All methods have default no-op implementations.
3030
*
3131
* <p>This is the recommended way to create plugins that need to customize both client and worker
3232
* behavior. Plugins that extend this class will automatically be propagated from the client to
@@ -59,11 +59,11 @@
5959
* }
6060
* }</pre>
6161
*
62-
* @see ClientPlugin
63-
* @see WorkerPlugin
62+
* @see io.temporal.client.Plugin
63+
* @see io.temporal.worker.Plugin
6464
*/
6565
@Experimental
66-
public abstract class PluginBase implements ClientPlugin, WorkerPlugin {
66+
public abstract class PluginBase implements Plugin, io.temporal.worker.Plugin {
6767

6868
private final String name;
6969

temporal-sdk/src/main/java/io/temporal/common/plugin/SimplePluginBuilder.java renamed to temporal-sdk/src/main/java/io/temporal/common/SimplePluginBuilder.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
* limitations under the License.
1919
*/
2020

21-
package io.temporal.common.plugin;
21+
package io.temporal.common;
2222

2323
import io.temporal.client.WorkflowClientOptions;
24-
import io.temporal.common.Experimental;
2524
import io.temporal.common.context.ContextPropagator;
2625
import io.temporal.common.interceptors.WorkerInterceptor;
2726
import io.temporal.common.interceptors.WorkflowClientInterceptor;
@@ -41,8 +40,8 @@
4140
* Builder for creating simple plugins that only need to modify configuration.
4241
*
4342
* <p>This builder provides a declarative way to create plugins for common use cases without
44-
* subclassing {@link PluginBase}. The resulting plugin implements both {@link ClientPlugin} and
45-
* {@link WorkerPlugin}.
43+
* subclassing {@link PluginBase}. The resulting plugin implements both {@link
44+
* io.temporal.client.Plugin} and {@link io.temporal.worker.Plugin}.
4645
*
4746
* <p>Example:
4847
*
@@ -59,8 +58,8 @@
5958
* }</pre>
6059
*
6160
* @see PluginBase
62-
* @see ClientPlugin
63-
* @see WorkerPlugin
61+
* @see io.temporal.client.Plugin
62+
* @see io.temporal.worker.Plugin
6463
*/
6564
@Experimental
6665
public final class SimplePluginBuilder {
@@ -204,8 +203,8 @@ public SimplePluginBuilder addContextPropagators(ContextPropagator... propagator
204203
/**
205204
* Builds the plugin with the configured settings.
206205
*
207-
* @return a new plugin instance that implements both {@link ClientPlugin} and {@link
208-
* WorkerPlugin}
206+
* @return a new plugin instance that implements both {@link io.temporal.client.Plugin} and {@link
207+
* io.temporal.worker.Plugin}
209208
*/
210209
public PluginBase build() {
211210
return new SimplePlugin(

temporal-sdk/src/main/java/io/temporal/common/plugin/WorkerPlugin.java renamed to temporal-sdk/src/main/java/io/temporal/worker/Plugin.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,17 @@
1818
* limitations under the License.
1919
*/
2020

21-
package io.temporal.common.plugin;
21+
package io.temporal.worker;
2222

2323
import io.temporal.common.Experimental;
24-
import io.temporal.worker.Worker;
25-
import io.temporal.worker.WorkerFactory;
26-
import io.temporal.worker.WorkerFactoryOptions;
27-
import io.temporal.worker.WorkerOptions;
24+
import io.temporal.common.PluginBase;
2825
import javax.annotation.Nonnull;
2926

3027
/**
3128
* Plugin interface for customizing Temporal worker configuration and lifecycle.
3229
*
33-
* <p>WorkerPlugins that also implement {@link ClientPlugin} are automatically propagated from the
34-
* client to workers created from that client.
30+
* <p>Plugins that also implement {@link io.temporal.client.Plugin} are automatically propagated
31+
* from the client to workers created from that client.
3532
*
3633
* <p>Example implementation:
3734
*
@@ -62,11 +59,11 @@
6259
* }
6360
* }</pre>
6461
*
65-
* @see ClientPlugin
62+
* @see io.temporal.client.Plugin
6663
* @see PluginBase
6764
*/
6865
@Experimental
69-
public interface WorkerPlugin {
66+
public interface Plugin {
7067

7168
/**
7269
* Returns a unique name for this plugin. Used for logging and duplicate detection. Recommended

temporal-sdk/src/main/java/io/temporal/worker/WorkerFactory.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import io.temporal.client.WorkflowClient;
99
import io.temporal.client.WorkflowClientOptions;
1010
import io.temporal.common.converter.DataConverter;
11-
import io.temporal.common.plugin.WorkerPlugin;
1211
import io.temporal.internal.client.WorkflowClientInternal;
1312
import io.temporal.internal.sync.WorkflowThreadExecutor;
1413
import io.temporal.internal.task.VirtualThreadDelegate;
@@ -173,8 +172,8 @@ public synchronized Worker newWorker(String taskQueue, WorkerOptions options) {
173172
// Go through the plugins to call plugin initializeWorker hooks (e.g. register workflows,
174173
// activities, etc.)
175174
for (Object plugin : plugins) {
176-
if (plugin instanceof WorkerPlugin) {
177-
((WorkerPlugin) plugin).initializeWorker(taskQueue, worker);
175+
if (plugin instanceof Plugin) {
176+
((Plugin) plugin).initializeWorker(taskQueue, worker);
178177
}
179178
}
180179

@@ -241,9 +240,9 @@ public synchronized void start() {
241240
List<Object> reversed = new ArrayList<>(plugins);
242241
Collections.reverse(reversed);
243242
for (Object plugin : reversed) {
244-
if (plugin instanceof WorkerPlugin) {
243+
if (plugin instanceof Plugin) {
245244
final Runnable next = startChain;
246-
final WorkerPlugin workerPlugin = (WorkerPlugin) plugin;
245+
final Plugin workerPlugin = (Plugin) plugin;
247246
startChain =
248247
() -> {
249248
try {
@@ -345,9 +344,9 @@ private void shutdownInternal(boolean interruptUserTasks) {
345344
List<Object> reversed = new ArrayList<>(plugins);
346345
Collections.reverse(reversed);
347346
for (Object plugin : reversed) {
348-
if (plugin instanceof WorkerPlugin) {
347+
if (plugin instanceof Plugin) {
349348
final Runnable next = shutdownChain;
350-
final WorkerPlugin workerPlugin = (WorkerPlugin) plugin;
349+
final Plugin workerPlugin = (Plugin) plugin;
351350
shutdownChain =
352351
() -> {
353352
try {
@@ -442,7 +441,7 @@ public String toString() {
442441

443442
/**
444443
* Extracts worker plugins from the client plugins list. Only plugins that implement {@link
445-
* WorkerPlugin} are included.
444+
* Plugin} are included.
446445
*/
447446
private static List<Object> extractWorkerPlugins(List<?> clientPlugins) {
448447
if (clientPlugins == null || clientPlugins.isEmpty()) {
@@ -451,7 +450,7 @@ private static List<Object> extractWorkerPlugins(List<?> clientPlugins) {
451450

452451
List<Object> workerPlugins = new ArrayList<>();
453452
for (Object plugin : clientPlugins) {
454-
if (plugin instanceof WorkerPlugin) {
453+
if (plugin instanceof Plugin) {
455454
workerPlugins.add(plugin);
456455
}
457456
}
@@ -474,8 +473,8 @@ private static WorkerFactoryOptions applyPluginConfiguration(
474473
: WorkerFactoryOptions.newBuilder(options);
475474

476475
for (Object plugin : plugins) {
477-
if (plugin instanceof WorkerPlugin) {
478-
builder = ((WorkerPlugin) plugin).configureWorkerFactory(builder);
476+
if (plugin instanceof Plugin) {
477+
builder = ((Plugin) plugin).configureWorkerFactory(builder);
479478
}
480479
}
481480
return builder.build();
@@ -495,8 +494,8 @@ private static WorkerOptions applyWorkerPluginConfiguration(
495494
options == null ? WorkerOptions.newBuilder() : WorkerOptions.newBuilder(options);
496495

497496
for (Object plugin : plugins) {
498-
if (plugin instanceof WorkerPlugin) {
499-
builder = ((WorkerPlugin) plugin).configureWorker(taskQueue, builder);
497+
if (plugin instanceof Plugin) {
498+
builder = ((Plugin) plugin).configureWorker(taskQueue, builder);
500499
}
501500
}
502501
return builder.build();

temporal-sdk/src/test/java/io/temporal/common/plugin/WorkflowClientOptionsPluginTest.java renamed to temporal-sdk/src/test/java/io/temporal/client/WorkflowClientOptionsPluginTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
* limitations under the License.
1919
*/
2020

21-
package io.temporal.common.plugin;
21+
package io.temporal.client;
2222

2323
import static org.junit.Assert.*;
2424

25-
import io.temporal.client.WorkflowClientOptions;
25+
import io.temporal.common.PluginBase;
2626
import java.util.Arrays;
2727
import java.util.List;
2828
import org.junit.Test;
@@ -45,8 +45,8 @@ public void testSetPlugins() {
4545

4646
List<?> plugins = options.getPlugins();
4747
assertEquals(2, plugins.size());
48-
assertEquals("plugin1", ((ClientPlugin) plugins.get(0)).getName());
49-
assertEquals("plugin2", ((ClientPlugin) plugins.get(1)).getName());
48+
assertEquals("plugin1", ((Plugin) plugins.get(0)).getName());
49+
assertEquals("plugin2", ((Plugin) plugins.get(1)).getName());
5050
}
5151

5252
@Test
@@ -59,8 +59,8 @@ public void testAddPlugin() {
5959

6060
List<?> plugins = options.getPlugins();
6161
assertEquals(2, plugins.size());
62-
assertEquals("plugin1", ((ClientPlugin) plugins.get(0)).getName());
63-
assertEquals("plugin2", ((ClientPlugin) plugins.get(1)).getName());
62+
assertEquals("plugin1", ((Plugin) plugins.get(0)).getName());
63+
assertEquals("plugin2", ((Plugin) plugins.get(1)).getName());
6464
}
6565

6666
@Test
@@ -99,7 +99,7 @@ public void testToBuilder() {
9999
WorkflowClientOptions copy = original.toBuilder().build();
100100

101101
assertEquals(1, copy.getPlugins().size());
102-
assertEquals("plugin", ((ClientPlugin) copy.getPlugins().get(0)).getName());
102+
assertEquals("plugin", ((Plugin) copy.getPlugins().get(0)).getName());
103103
}
104104

105105
@Test
@@ -110,7 +110,7 @@ public void testValidateAndBuildWithDefaults() {
110110
WorkflowClientOptions.newBuilder().addPlugin(plugin).validateAndBuildWithDefaults();
111111

112112
assertEquals(1, options.getPlugins().size());
113-
assertEquals("plugin", ((ClientPlugin) options.getPlugins().get(0)).getName());
113+
assertEquals("plugin", ((Plugin) options.getPlugins().get(0)).getName());
114114
}
115115

116116
@Test

0 commit comments

Comments
 (0)