Skip to content

Commit 486228b

Browse files
authored
Merge pull request #6438 from bstansberry/WFCORE-7273
[WFCORE-7273] Remove JBoss Threads classes from the ModelControllerClient API; use SE's CompletableFuture
2 parents d9f2cbf + af8fda4 commit 486228b

File tree

35 files changed

+560
-672
lines changed

35 files changed

+560
-672
lines changed

cli/src/main/java/org/jboss/as/cli/embedded/ThreadContextsModelControllerClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
package org.jboss.as.cli.embedded;
77

88
import java.io.IOException;
9+
import java.util.concurrent.CompletableFuture;
910

1011
import org.jboss.as.controller.client.ModelControllerClient;
1112
import org.jboss.as.controller.client.Operation;
1213
import org.jboss.as.controller.client.OperationMessageHandler;
1314
import org.jboss.as.controller.client.OperationResponse;
1415
import org.jboss.dmr.ModelNode;
15-
import org.jboss.threads.AsyncFuture;
1616

1717
/**
1818
* {@link org.jboss.as.controller.client.ModelControllerClient} that uses a
@@ -86,7 +86,7 @@ public OperationResponse executeOperation(Operation operation, OperationMessageH
8686
}
8787

8888
@Override
89-
public AsyncFuture<ModelNode> executeAsync(ModelNode operation, OperationMessageHandler messageHandler) {
89+
public CompletableFuture<ModelNode> executeAsync(ModelNode operation, OperationMessageHandler messageHandler) {
9090
Contexts existing = contextSelector.pushLocal();
9191
try {
9292
return delegate.executeAsync(operation, messageHandler);
@@ -96,7 +96,7 @@ public AsyncFuture<ModelNode> executeAsync(ModelNode operation, OperationMessage
9696
}
9797

9898
@Override
99-
public AsyncFuture<ModelNode> executeAsync(Operation operation, OperationMessageHandler messageHandler) {
99+
public CompletableFuture<ModelNode> executeAsync(Operation operation, OperationMessageHandler messageHandler) {
100100
Contexts existing = contextSelector.pushLocal();
101101
try {
102102
return delegate.executeAsync(operation, messageHandler);
@@ -106,7 +106,7 @@ public AsyncFuture<ModelNode> executeAsync(Operation operation, OperationMessage
106106
}
107107

108108
@Override
109-
public AsyncFuture<OperationResponse> executeOperationAsync(Operation operation, OperationMessageHandler messageHandler) {
109+
public CompletableFuture<OperationResponse> executeOperationAsync(Operation operation, OperationMessageHandler messageHandler) {
110110
Contexts existing = contextSelector.pushLocal();
111111
try {
112112
return delegate.executeOperationAsync(operation, messageHandler);

cli/src/main/java/org/jboss/as/cli/impl/CLIModelControllerClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void close() throws IOException {
151151
}
152152

153153
@Override
154-
protected ManagementChannelAssociation getChannelAssociation() throws IOException {
154+
protected ManagementChannelAssociation getChannelAssociation() {
155155
return channelAssociation;
156156
}
157157

cli/src/main/java/org/jboss/as/cli/impl/CommandExecutor.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.io.PrintStream;
1111
import java.util.Collection;
1212
import java.util.concurrent.CancellationException;
13+
import java.util.concurrent.CompletableFuture;
1314
import java.util.concurrent.ExecutionException;
1415
import java.util.concurrent.ExecutorService;
1516
import java.util.concurrent.Executors;
@@ -41,7 +42,6 @@
4142
import org.jboss.as.controller.client.OperationMessageHandler;
4243
import org.jboss.as.controller.client.OperationResponse;
4344
import org.jboss.dmr.ModelNode;
44-
import org.jboss.threads.AsyncFuture;
4545

4646
/**
4747
* Implement the timeout logic when executing commands. Public for testing
@@ -101,12 +101,12 @@ public ModelNode execute(Operation operation) throws IOException {
101101
}
102102

103103
@Override
104-
public AsyncFuture<ModelNode> executeAsync(ModelNode operation, OperationMessageHandler messageHandler) {
104+
public CompletableFuture<ModelNode> executeAsync(ModelNode operation, OperationMessageHandler messageHandler) {
105105
return doExecuteAsync(operation, messageHandler);
106106
}
107107

108108
@Override
109-
public AsyncFuture<ModelNode> executeAsync(Operation operation, OperationMessageHandler messageHandler) {
109+
public CompletableFuture<ModelNode> executeAsync(Operation operation, OperationMessageHandler messageHandler) {
110110
return doExecuteAsync(operation, messageHandler);
111111
}
112112

@@ -116,7 +116,7 @@ public OperationResponse executeOperation(Operation operation, OperationMessageH
116116
}
117117

118118
@Override
119-
public AsyncFuture<OperationResponse> executeOperationAsync(Operation operation, OperationMessageHandler messageHandler) {
119+
public CompletableFuture<OperationResponse> executeOperationAsync(Operation operation, OperationMessageHandler messageHandler) {
120120
return doExecuteOperationAsync(operation, messageHandler);
121121
}
122122

@@ -157,15 +157,15 @@ public void ensureConnected(long timeoutMillis) throws CommandLineException, IOE
157157
((AwaiterModelControllerClient) wrapped).ensureConnected(timeoutMillis);
158158
}
159159

160-
private AsyncFuture<OperationResponse> doExecuteOperationAsync(Operation operation, OperationMessageHandler messageHandler) {
161-
AsyncFuture<OperationResponse> task
160+
private CompletableFuture<OperationResponse> doExecuteOperationAsync(Operation operation, OperationMessageHandler messageHandler) {
161+
CompletableFuture<OperationResponse> task
162162
= wrapped.executeOperationAsync(operation, messageHandler);
163163
setLastHandlerTask(task);
164164
return task;
165165
}
166166

167167
private OperationResponse doExecuteOperation(Operation operation, OperationMessageHandler messageHandler) throws IOException {
168-
AsyncFuture<OperationResponse> task;
168+
CompletableFuture<OperationResponse> task;
169169
task = wrapped.executeOperationAsync(operation, messageHandler);
170170
boolean canceled = setLastHandlerTask(task);
171171
if (canceled) {
@@ -181,15 +181,15 @@ private OperationResponse doExecuteOperation(Operation operation, OperationMessa
181181
}
182182
}
183183

184-
private AsyncFuture<ModelNode> doExecuteAsync(Operation operation, OperationMessageHandler messageHandler) {
185-
AsyncFuture<ModelNode> task
184+
private CompletableFuture<ModelNode> doExecuteAsync(Operation operation, OperationMessageHandler messageHandler) {
185+
CompletableFuture<ModelNode> task
186186
= wrapped.executeAsync(operation, messageHandler);
187187
setLastHandlerTask(task);
188188
return task;
189189
}
190190

191-
private AsyncFuture<ModelNode> doExecuteAsync(ModelNode operation, OperationMessageHandler messageHandler) {
192-
AsyncFuture<ModelNode> task
191+
private CompletableFuture<ModelNode> doExecuteAsync(ModelNode operation, OperationMessageHandler messageHandler) {
192+
CompletableFuture<ModelNode> task
193193
= wrapped.executeAsync(operation, messageHandler);
194194
setLastHandlerTask(task);
195195
return task;

cli/src/test/java/org/jboss/as/cli/impl/BootScriptInvokerTestCase.java

Lines changed: 11 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,25 @@
44
*/
55
package org.jboss.as.cli.impl;
66

7+
import static org.junit.Assert.assertEquals;
8+
import static org.junit.Assert.assertNull;
9+
import static org.junit.Assert.assertTrue;
10+
711
import java.io.IOException;
812
import java.nio.file.Files;
913
import java.nio.file.Path;
1014
import java.util.HashSet;
1115
import java.util.LinkedHashSet;
1216
import java.util.List;
1317
import java.util.Set;
14-
import java.util.concurrent.CancellationException;
15-
import java.util.concurrent.ExecutionException;
16-
import java.util.concurrent.TimeUnit;
17-
import java.util.concurrent.TimeoutException;
18+
import java.util.concurrent.CompletableFuture;
1819

1920
import org.jboss.as.cli.Util;
2021
import org.jboss.as.controller.client.ModelControllerClient;
2122
import org.jboss.as.controller.client.Operation;
2223
import org.jboss.as.controller.client.OperationMessageHandler;
2324
import org.jboss.as.controller.client.OperationResponse;
2425
import org.jboss.dmr.ModelNode;
25-
import org.jboss.threads.AsyncFuture;
26-
import static org.junit.Assert.assertEquals;
27-
import static org.junit.Assert.assertNull;
28-
import static org.junit.Assert.assertTrue;
2926
import org.junit.BeforeClass;
3027
import org.junit.Test;
3128
import org.wildfly.security.manager.WildFlySecurityManager;
@@ -36,7 +33,7 @@
3633
*/
3734
public class BootScriptInvokerTestCase {
3835

39-
private class TestClient implements ModelControllerClient {
36+
private static class TestClient implements ModelControllerClient {
4037

4138
private class TestOperationResponse implements OperationResponse {
4239

@@ -61,80 +58,8 @@ public void close() throws IOException {
6158

6259
}
6360

64-
private class TestAsync implements AsyncFuture<ModelNode> {
65-
66-
@Override
67-
public AsyncFuture.Status await() throws InterruptedException {
68-
return AsyncFuture.Status.COMPLETE;
69-
}
70-
71-
@Override
72-
public AsyncFuture.Status await(long arg0, TimeUnit arg1) throws InterruptedException {
73-
return AsyncFuture.Status.COMPLETE;
74-
}
75-
76-
@Override
77-
public ModelNode getUninterruptibly() throws CancellationException, ExecutionException {
78-
return mn;
79-
}
80-
81-
@Override
82-
public ModelNode getUninterruptibly(long arg0, TimeUnit arg1) throws CancellationException, ExecutionException, TimeoutException {
83-
return mn;
84-
}
85-
86-
@Override
87-
public AsyncFuture.Status awaitUninterruptibly() {
88-
return AsyncFuture.Status.COMPLETE;
89-
}
90-
91-
@Override
92-
public AsyncFuture.Status awaitUninterruptibly(long arg0, TimeUnit arg1) {
93-
return AsyncFuture.Status.COMPLETE;
94-
}
95-
96-
@Override
97-
public AsyncFuture.Status getStatus() {
98-
return AsyncFuture.Status.COMPLETE;
99-
}
100-
101-
@Override
102-
public <A> void addListener(AsyncFuture.Listener<? super ModelNode, A> arg0, A arg1) {
103-
104-
}
105-
106-
@Override
107-
public boolean cancel(boolean arg0) {
108-
return true;
109-
}
110-
111-
@Override
112-
public void asyncCancel(boolean arg0) {
113-
}
114-
115-
@Override
116-
public boolean isCancelled() {
117-
return false;
118-
}
119-
120-
@Override
121-
public boolean isDone() {
122-
return true;
123-
}
124-
125-
@Override
126-
public ModelNode get() throws InterruptedException, ExecutionException {
127-
return mn;
128-
}
129-
130-
@Override
131-
public ModelNode get(long arg0, TimeUnit arg1) throws InterruptedException, ExecutionException, TimeoutException {
132-
return mn;
133-
}
134-
}
135-
136-
private Set<String> seen = new HashSet<>();
137-
private ModelNode mn;
61+
private final Set<String> seen = new HashSet<>();
62+
private final ModelNode mn;
13863

13964
private TestClient() {
14065
mn = new ModelNode();
@@ -149,13 +74,13 @@ public OperationResponse executeOperation(Operation op, OperationMessageHandler
14974
}
15075

15176
@Override
152-
public AsyncFuture<ModelNode> executeAsync(Operation op, OperationMessageHandler arg1) {
77+
public CompletableFuture<ModelNode> executeAsync(Operation op, OperationMessageHandler arg1) {
15378
seen.add(op.getOperation().get("operation").asString());
154-
return new TestAsync();
79+
return CompletableFuture.completedFuture(mn);
15580
}
15681

15782
@Override
158-
public AsyncFuture<OperationResponse> executeOperationAsync(Operation arg0, OperationMessageHandler arg1) {
83+
public CompletableFuture<OperationResponse> executeOperationAsync(Operation arg0, OperationMessageHandler arg1) {
15984
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
16085
}
16186

controller-client/src/main/java/org/jboss/as/controller/client/ModelControllerClient.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import java.net.URI;
1212
import java.net.UnknownHostException;
1313
import java.security.GeneralSecurityException;
14+
import java.util.concurrent.CompletableFuture;
1415

1516
import javax.security.auth.callback.CallbackHandler;
1617

1718
import org.jboss.as.controller.client.helpers.ContextualModelControllerClient;
1819
import org.jboss.as.controller.client.impl.RemotingModelControllerClient;
1920
import org.jboss.as.controller.client.logging.ControllerClientLogger;
2021
import org.jboss.dmr.ModelNode;
21-
import org.jboss.threads.AsyncFuture;
2222
import org.wildfly.client.config.ConfigXMLParseException;
2323
import org.wildfly.common.context.Contextual;
2424
import org.wildfly.security.auth.client.ElytronXmlParser;
@@ -45,7 +45,7 @@ default ModelNode execute(ModelNode operation) throws IOException{
4545

4646
/**
4747
* Execute an operation synchronously.
48-
*
48+
* <p/>
4949
* Note that associated input-streams have to be closed by the caller, after the
5050
* operation completed {@link OperationAttachments#isAutoCloseStreams()}.
5151
*
@@ -106,7 +106,7 @@ default ModelNode execute(Operation operation, OperationMessageHandler messageHa
106106
* @param operation the operation to execute
107107
* @return the future result of the operation
108108
*/
109-
default AsyncFuture<ModelNode> executeAsync(ModelNode operation) {
109+
default CompletableFuture<ModelNode> executeAsync(ModelNode operation) {
110110
return executeAsync(Operation.Factory.create(operation), OperationMessageHandler.DISCARD);
111111
}
112112

@@ -117,7 +117,7 @@ default AsyncFuture<ModelNode> executeAsync(ModelNode operation) {
117117
* @param messageHandler the message handler to use for operation progress reporting, or {@code null} for none
118118
* @return the future result of the operation
119119
*/
120-
default AsyncFuture<ModelNode> executeAsync(ModelNode operation, OperationMessageHandler messageHandler) {
120+
default CompletableFuture<ModelNode> executeAsync(ModelNode operation, OperationMessageHandler messageHandler) {
121121
return executeAsync(Operation.Factory.create(operation), messageHandler);
122122
}
123123

@@ -130,7 +130,7 @@ default AsyncFuture<ModelNode> executeAsync(ModelNode operation, OperationMessag
130130
* @param operation the operation to execute
131131
* @return the future result of the operation
132132
*/
133-
default AsyncFuture<ModelNode> executeAsync(Operation operation) {
133+
default CompletableFuture<ModelNode> executeAsync(Operation operation) {
134134
return executeAsync(operation, OperationMessageHandler.DISCARD);
135135
}
136136

@@ -144,7 +144,7 @@ default AsyncFuture<ModelNode> executeAsync(Operation operation) {
144144
* @param messageHandler the message handler to use for operation progress reporting, or {@code null} for none
145145
* @return the future result of the operation
146146
*/
147-
AsyncFuture<ModelNode> executeAsync(Operation operation, OperationMessageHandler messageHandler);
147+
CompletableFuture<ModelNode> executeAsync(Operation operation, OperationMessageHandler messageHandler);
148148

149149
/**
150150
* Execute an operation in another thread, optionally receiving progress reports, with the response
@@ -157,7 +157,7 @@ default AsyncFuture<ModelNode> executeAsync(Operation operation) {
157157
* @param messageHandler the message handler to use for operation progress reporting, or {@code null} for none
158158
* @return the future result of the operation
159159
*/
160-
AsyncFuture<OperationResponse> executeOperationAsync(Operation operation, OperationMessageHandler messageHandler);
160+
CompletableFuture<OperationResponse> executeOperationAsync(Operation operation, OperationMessageHandler messageHandler);
161161

162162
/** Factory methods for creating a {@code ModelControllerClient}. */
163163
class Factory {

controller-client/src/main/java/org/jboss/as/controller/client/helpers/ContextualModelControllerClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
package org.jboss.as.controller.client.helpers;
77

88
import java.io.IOException;
9+
import java.util.concurrent.CompletableFuture;
910

1011
import org.jboss.as.controller.client.ModelControllerClient;
1112
import org.jboss.as.controller.client.Operation;
1213
import org.jboss.as.controller.client.OperationMessageHandler;
1314
import org.jboss.as.controller.client.OperationResponse;
1415
import org.jboss.dmr.ModelNode;
15-
import org.jboss.threads.AsyncFuture;
1616
import org.wildfly.common.Assert;
1717
import org.wildfly.common.context.Contextual;
1818

@@ -43,12 +43,12 @@ public OperationResponse executeOperation(final Operation operation, final Opera
4343
}
4444

4545
@Override
46-
public AsyncFuture<ModelNode> executeAsync(final Operation operation, final OperationMessageHandler messageHandler) {
46+
public CompletableFuture<ModelNode> executeAsync(final Operation operation, final OperationMessageHandler messageHandler) {
4747
return context.runExFunction(o -> delegate.executeAsync(operation, messageHandler), null);
4848
}
4949

5050
@Override
51-
public AsyncFuture<OperationResponse> executeOperationAsync(final Operation operation, final OperationMessageHandler messageHandler) {
51+
public CompletableFuture<OperationResponse> executeOperationAsync(final Operation operation, final OperationMessageHandler messageHandler) {
5252
return context.runExFunction(o -> delegate.executeOperationAsync(operation, messageHandler), null);
5353
}
5454

0 commit comments

Comments
 (0)