Skip to content

Commit ef6b8aa

Browse files
author
Dmitriy Setrakyan
committed
GG-9245 - added local service for proxy.
1 parent 7a2363d commit ef6b8aa

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceProcessor.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,34 @@ public GridServiceContextImpl serviceContext(String name) {
543543
* @param <T> Service interface type.
544544
* @return The proxy of a service by its name and class.
545545
*/
546+
@SuppressWarnings("unchecked")
546547
public <T> T serviceProxy(GridProjection prj, String name, Class<T> svcItf,
547548
boolean sticky) throws GridRuntimeException {
548549
A.ensure(svcItf.isInterface(), "Service class must be an interface: " + svcItf);
549550

551+
if (hasLocalNode(prj)) {
552+
GridServiceContextImpl ctx = serviceContext(name);
553+
554+
if (ctx != null)
555+
return (T)ctx.service();
556+
}
557+
550558
return new GridServiceProxy<>(prj, name, svcItf, sticky, ctx).proxy();
551559
}
552560

561+
/**
562+
* @param prj Grid nodes projection.
563+
* @return Whether given projection contains any local node.
564+
*/
565+
private boolean hasLocalNode(GridProjection prj) {
566+
for (GridNode n : prj.nodes()) {
567+
if (n.isLocal())
568+
return true;
569+
}
570+
571+
return false;
572+
}
573+
553574
/**
554575
* @param name Service name.
555576
* @param <T> Service type.

modules/core/src/main/java/org/gridgain/grid/kernal/processors/service/GridServiceProxy.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ private ProxyInvocationHandler(String name, boolean sticky) {
166166
throw new GridRuntimeException(e);
167167
}
168168
}
169-
170169
}
171170

172171
/**

0 commit comments

Comments
 (0)