Skip to content

Commit 003ce46

Browse files
author
Myron Scott
committed
PR comment changes
1 parent 25b440e commit 003ce46

File tree

4 files changed

+43
-67
lines changed

4 files changed

+43
-67
lines changed

tc-client/src/main/java/com/tc/object/ClientEntityManagerImpl.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979

8080
import static com.tc.object.EntityDescriptor.createDescriptorForLifecycle;
8181
import static com.tc.object.SafeInvocationCallback.safe;
82+
import java.util.concurrent.Callable;
8283
import static java.util.stream.Collectors.toCollection;
8384
import static org.terracotta.entity.Invocation.uninterruptiblyGet;
8485

@@ -408,23 +409,20 @@ private <M extends EntityMessage, R extends EntityResponse> EntityClientEndpoint
408409
Assert.assertNotNull("Can't lookup null entity descriptor", instance);
409410
final EntityDescriptor fetchDescriptor = EntityDescriptor.createDescriptorForFetch(entity, version, instance);
410411
EntityClientEndpointImpl<M, R> resolvedEndpoint = null;
411-
// make sure this close hook is only ever called once
412-
CloseHookCallable closeCall = new CloseHookCallable() {
412+
// make sure release is only ever called once
413+
Callable<Void> closeCall = new Callable<Void>() {
413414
boolean released = false;
415+
414416
@Override
415-
public EntityException call() {
417+
public synchronized Void call() throws Exception {
416418
if (!released) {
417419
released = true;
418-
try {
419-
internalRelease(entity, fetchDescriptor);
420-
} catch (EntityException e) {
421-
// We aren't expecting there to be any problems releasing an entity in the close hook but return the exception if there is an issue.
422-
return e;
423-
}
420+
internalRelease(entity, fetchDescriptor);
424421
}
425422
return null;
426423
}
427424
};
425+
428426
try {
429427
byte[] raw = internalRetrieve(fetchDescriptor);
430428
ByteBuffer br = ByteBuffer.wrap(raw);
@@ -445,13 +443,21 @@ public EntityException call() {
445443
throw notfound;
446444
} catch (EntityException e) {
447445
// Release the entity and re-throw to the higher level.
448-
e.addSuppressed(closeCall.call());
446+
try {
447+
closeCall.call();
448+
} catch (Exception subE) {
449+
e.addSuppressed(subE);
450+
}
449451

450452
throw e;
451453
} catch (Throwable t) {
452454
// This is the unexpected case so clean up and re-throw as a RuntimeException
453455
// Clean up any client-side or server-side state regarding this failed connection.
454-
t.addSuppressed(closeCall.call());
456+
try {
457+
closeCall.call();
458+
} catch (Exception subE) {
459+
t.addSuppressed(subE);
460+
}
455461

456462
throw Throwables.propagate(t);
457463
}

tc-client/src/main/java/com/tc/object/CloseHookCallable.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

tc-client/src/main/java/com/tc/object/EntityClientEndpointImpl.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class EntityClientEndpointImpl<M extends EntityMessage, R extends EntityR
5353
private final EntityID entityID;
5454
private final long version;
5555
private final MessageCodec<M, R> codec;
56-
private final CloseHookCallable closeHook;
56+
private final Callable<Void> closeHook;
5757
private final ExecutorService closer;
5858
private EndpointDelegate<R> delegate;
5959
private boolean isOpen;
@@ -67,7 +67,7 @@ public class EntityClientEndpointImpl<M extends EntityMessage, R extends EntityR
6767
* @param entityConfiguration Opaque byte[] describing how to configure the entity to be built on top of this end-point.
6868
* @param closeHook A Runnable which will be run last when the end-point is closed.
6969
*/
70-
public EntityClientEndpointImpl(EntityID eid, long version, EntityDescriptor instance, InvocationHandler invocationHandler, byte[] entityConfiguration, MessageCodec<M, R> codec, CloseHookCallable closeHook, ExecutorService closer) {
70+
public EntityClientEndpointImpl(EntityID eid, long version, EntityDescriptor instance, InvocationHandler invocationHandler, byte[] entityConfiguration, MessageCodec<M, R> codec, Callable<Void> closeHook, ExecutorService closer) {
7171
this.entityID = eid;
7272
this.version = version;
7373
this.invokeDescriptor = instance;
@@ -97,14 +97,14 @@ EntityDescriptor getEntityDescriptor() {
9797
@Override
9898
public byte[] getEntityConfiguration() {
9999
// This is harmless while closed but shouldn't be called so check open.
100-
checkEndpointOpen(false);
100+
checkEndpointOpen();
101101
return configuration;
102102
}
103103

104104
@Override
105105
public void setDelegate(EndpointDelegate<R> delegate) {
106106
// This is harmless while closed but shouldn't be called so check open.
107-
checkEndpointOpen(false);
107+
checkEndpointOpen();
108108
Assert.assertNull(this.delegate);
109109
this.delegate = delegate;
110110
}
@@ -125,7 +125,7 @@ public InFlightStats getStatistics() {
125125
@Override
126126
public Invocation<R> message(M message) {
127127
// We can't create new invocations when the endpoint is closed.
128-
checkEndpointOpen(false);
128+
checkEndpointOpen();
129129
return new InvocationImpl(message);
130130
}
131131

@@ -177,16 +177,15 @@ public byte[] getExtendedReconnectData() {
177177
@Override
178178
public void close() {
179179
// We can't close twice.
180-
try {
181-
checkEndpointOpen(true);
182-
} catch (IllegalStateException alreadyClosed) {
183-
LOGGER.info("Trying to close an endpoint which has already been closed", alreadyClosed);
184-
return;
185-
}
186-
if (this.closeHook != null) {
187-
EntityException e = this.closeHook.call();
188-
LOGGER.info("Exception occured during close", e);
189-
// log and swallow this exception closing
180+
if (closeIfOpen()) {
181+
if (this.closeHook != null) {
182+
try {
183+
this.closeHook.call();
184+
} catch (Exception e) {
185+
LOGGER.warn("Exception occured during close", e);
186+
}
187+
// log and swallow this exception closing
188+
}
190189
}
191190
}
192191

@@ -226,12 +225,15 @@ public void didCloseUnexpectedly() {
226225
}
227226
}
228227

229-
private synchronized void checkEndpointOpen(boolean close) {
228+
private synchronized void checkEndpointOpen() {
230229
if (!this.isOpen) {
231230
throw new IllegalStateException("Endpoint closed");
232231
}
233-
if (close) {
234-
this.isOpen = false;
235-
}
232+
}
233+
234+
private synchronized boolean closeIfOpen() {
235+
boolean wasOpen = this.isOpen;
236+
this.isOpen = false;
237+
return wasOpen;
236238
}
237239
}

tc-server/src/main/java/com/tc/objectserver/entity/ManagedEntityImpl.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -987,14 +987,13 @@ private void getEntity(ServerEntityRequest getEntityRequest, ResultCapture respo
987987
Assert.assertTrue(clientReferenceCount > 0);
988988
} else {
989989
// this should never happen. Ther server is expecting sane things from the client.
990-
logger.info("the client has attempted to fetch the same entity instance twice {}", descriptor);
990+
logger.warn("the client has attempted to fetch the same entity instance twice {}", descriptor);
991991
}
992992
}
993993

994994
if (this.isInActiveState) {
995995
if (!added) {
996-
// this should never happen if the client is sane but if it does, exception the client
997-
// don't crash the server
996+
// Exception the client. Don't crash the server
998997
response.failure(ServerException.createReferencedException(id));
999998
return;
1000999
}
@@ -1060,15 +1059,14 @@ private void releaseEntity(ServerEntityRequest request, ResultCapture response)
10601059
clientReferenceCount -= 1;
10611060
Assert.assertTrue(clientReferenceCount >= 0);
10621061
} else {
1063-
// this should never happen. the expectation is that the client will send sane things to the server. Will assert if active
1064-
logger.info("client has tried to release and entity that is not fetched {}", clientInstance);
1062+
// this should never happen. the expectation is that the client will send sane things to the server.
1063+
logger.warn("client has tried to release an entity that is not fetched {}", clientInstance);
10651064
}
10661065
}
10671066

10681067
if (this.isInActiveState) {
10691068
if (!removed) {
1070-
// this should never happen if the client is sane but if it does, exception the client
1071-
// don't crash the server
1069+
// Exception the client. don't crash the server
10721070
response.failure(ServerException.createNotFoundException(id));
10731071
return;
10741072
}

0 commit comments

Comments
 (0)