Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Java Reference implementation #2379

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions csharp/src/Ice/Internal/Reference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public Ice.Communicator getCommunicator()
public abstract string getConnectionId();
public abstract ThreadPool getThreadPool();

public abstract Connection getConnection();

//
// The change* methods (here and in derived classes) create
// a new reference based on the existing one, with the
Expand Down Expand Up @@ -536,6 +538,11 @@ public override ThreadPool getThreadPool()
return _fixedConnection.getThreadPool();
}

public override Connection getConnection()
{
return _fixedConnection;
}

public override Reference changeEndpoints(EndpointI[] newEndpoints)
{
throw new Ice.FixedProxyException();
Expand Down Expand Up @@ -760,6 +767,11 @@ public override ThreadPool getThreadPool()
return getInstance().clientThreadPool();
}

public override Connection getConnection()
{
return null;
}

public override Reference changeEncoding(Ice.EncodingVersion newEncoding)
{
RoutableReference r = (RoutableReference)base.changeEncoding(newEncoding);
Expand Down
6 changes: 3 additions & 3 deletions csharp/src/Ice/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,14 +1441,14 @@ public ObjectPrx ice_fixed(Ice.Connection connection)
{
throw new ArgumentException("invalid connection passed to ice_fixed");
}
var reference = _reference.changeConnection((Ice.ConnectionI)connection);
if (reference == _reference)

if (connection == _reference.getConnection())
{
return this;
}
else
{
return iceNewInstance(reference);
return iceNewInstance(_reference.changeConnection((Ice.ConnectionI)connection));
}
}

Expand Down
68 changes: 35 additions & 33 deletions java/src/Ice/src/main/java/com/zeroc/Ice/_ObjectPrxI.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public ObjectPrx _newInstance(com.zeroc.IceInternal.Reference ref) {

@Override
public ObjectPrx ice_context(java.util.Map<String, String> newContext) {
return _newInstance(_getReference().changeContext(newContext));
return _newInstance(_reference.changeContext(newContext));
}

@Override
Expand All @@ -395,22 +395,22 @@ public ObjectPrx ice_adapterId(String newAdapterId) {
newAdapterId = "";
}

if (newAdapterId.equals(_getReference().getAdapterId())) {
if (newAdapterId.equals(_reference.getAdapterId())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understandand why you replaced calls to _getReference() by _reference only in some method of this file. Should it be a global replace instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and replaced all occurrences.

return this;
} else {
return _newInstance(_getReference().changeAdapterId(newAdapterId));
return _newInstance(_reference.changeAdapterId(newAdapterId));
}
}

@Override
public ObjectPrx ice_endpoints(Endpoint[] newEndpoints) {
if (java.util.Arrays.equals(newEndpoints, _getReference().getEndpoints())) {
if (java.util.Arrays.equals(newEndpoints, _reference.getEndpoints())) {
return this;
} else {
com.zeroc.IceInternal.EndpointI[] edpts =
new com.zeroc.IceInternal.EndpointI[newEndpoints.length];
edpts = java.util.Arrays.asList(newEndpoints).toArray(edpts);
return _newInstance(_getReference().changeEndpoints(edpts));
return _newInstance(_reference.changeEndpoints(edpts));
}
}

Expand All @@ -422,10 +422,10 @@ public ObjectPrx ice_fixed(com.zeroc.Ice.Connection connection) {
if (!(connection instanceof com.zeroc.Ice.ConnectionI)) {
throw new IllegalArgumentException("invalid connection passed to ice_fixed");
}
if (connection == _getReference().getConnection()) {
if (connection == _reference.getConnection()) {
return this;
} else {
return _newInstance(_getReference().changeConnection((com.zeroc.Ice.ConnectionI) connection));
return _newInstance(_reference.changeConnection((com.zeroc.Ice.ConnectionI) connection));
}
}

Expand All @@ -435,10 +435,10 @@ public ObjectPrx ice_locatorCacheTimeout(int newTimeout) {
throw new IllegalArgumentException(
"invalid value passed to ice_locatorCacheTimeout: " + newTimeout);
}
if (newTimeout == _getReference().getLocatorCacheTimeout()) {
if (newTimeout == _reference.getLocatorCacheTimeout()) {
return this;
} else {
return _newInstance(_getReference().changeLocatorCacheTimeout(newTimeout));
return _newInstance(_reference.changeLocatorCacheTimeout(newTimeout));
}
}

Expand All @@ -448,46 +448,46 @@ public ObjectPrx ice_invocationTimeout(int newTimeout) {
throw new IllegalArgumentException(
"invalid value passed to ice_invocationTimeout: " + newTimeout);
}
if (newTimeout == _getReference().getInvocationTimeout()) {
if (newTimeout == _reference.getInvocationTimeout()) {
return this;
} else {
return _newInstance(_getReference().changeInvocationTimeout(newTimeout));
return _newInstance(_reference.changeInvocationTimeout(newTimeout));
}
}

@Override
public ObjectPrx ice_connectionCached(boolean newCache) {
if (newCache == _getReference().getCacheConnection()) {
if (newCache == _reference.getCacheConnection()) {
return this;
} else {
return _newInstance(_getReference().changeCacheConnection(newCache));
return _newInstance(_reference.changeCacheConnection(newCache));
}
}

@Override
public ObjectPrx ice_endpointSelection(EndpointSelectionType newType) {
if (newType == _getReference().getEndpointSelection()) {
if (newType == _reference.getEndpointSelection()) {
return this;
} else {
return _newInstance(_getReference().changeEndpointSelection(newType));
return _newInstance(_reference.changeEndpointSelection(newType));
}
}

@Override
public ObjectPrx ice_secure(boolean b) {
if (b == _getReference().getSecure()) {
if (b == _reference.getSecure()) {
return this;
} else {
return _newInstance(_getReference().changeSecure(b));
return _newInstance(_reference.changeSecure(b));
}
}

@Override
public ObjectPrx ice_encodingVersion(EncodingVersion e) {
if (e.equals(_getReference().getEncoding())) {
if (e.equals(_reference.getEncoding())) {
return this;
} else {
return _newInstance(_getReference().changeEncoding(e));
return _newInstance(_reference.changeEncoding(e));
}
}

Expand All @@ -501,22 +501,25 @@ public ObjectPrx ice_preferSecure(boolean b) {
}

@Override
public ObjectPrx ice_router(RouterPrx router) {
com.zeroc.IceInternal.Reference ref = _getReference().changeRouter(router);
if (ref.equals(_getReference())) {
public ObjectPrx ice_router(RouterPrx newRouter) {
com.zeroc.IceInternal.RouterInfo routerInfo = _reference.getRouterInfo();
RouterPrx router = routerInfo != null ? routerInfo.getRouter() : null;
if (router == newRouter || (router != null && router.equals(newRouter))) {
return this;
} else {
return _newInstance(ref);
return _newInstance(_reference.changeRouter(newRouter));
}
}

@Override
public ObjectPrx ice_locator(LocatorPrx locator) {
public ObjectPrx ice_locator(LocatorPrx newLocator) {
com.zeroc.IceInternal.LocatorInfo locatorInfo = _reference.getLocatorInfo();
LocatorPrx locator = locatorInfo != null ? locatorInfo.getLocator() : null;
com.zeroc.IceInternal.Reference ref = _getReference().changeLocator(locator);
if (ref.equals(_getReference())) {
if (locator == newLocator || (locator != null && locator.equals(newLocator))) {
return this;
} else {
return _newInstance(ref);
return _newInstance(_reference.changeLocator(newLocator));
}
}

Expand Down Expand Up @@ -577,22 +580,21 @@ public ObjectPrx ice_batchDatagram() {
}

@Override
public ObjectPrx ice_compress(boolean co) {
com.zeroc.IceInternal.Reference ref = _getReference().changeCompress(co);
if (ref.equals(_getReference())) {
public ObjectPrx ice_compress(boolean compress) {
var value = _getReference().getCompress();
if (value.isPresent() && value.get() == compress) {
return this;
} else {
return _newInstance(ref);
return _newInstance(_getReference().changeCompress(compress));
}
}

@Override
public ObjectPrx ice_connectionId(String connectionId) {
com.zeroc.IceInternal.Reference ref = _getReference().changeConnectionId(connectionId);
if (ref.equals(_getReference())) {
if (connectionId.equals(_reference.getConnectionId())) {
return this;
} else {
return _newInstance(ref);
return _newInstance(_getReference().changeConnectionId(connectionId));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ public Reference changeConnectionId(String connectionId) {

@Override
public Reference changeConnection(com.zeroc.Ice.ConnectionI connection) {
if (_fixedConnection == connection) {
return this;
}
FixedReference r = (FixedReference) getInstance().referenceFactory().copy(this);
r._fixedConnection = connection;
return r;
Expand Down
21 changes: 0 additions & 21 deletions java/src/Ice/src/main/java/com/zeroc/IceInternal/Reference.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,63 +105,42 @@ public final Reference changeContext(java.util.Map<String, String> newContext) {
}

public final Reference changeMode(int newMode) {
if (newMode == _mode) {
return this;
}
Reference r = _instance.referenceFactory().copy(this);
r._mode = newMode;
return r;
}

public Reference changeSecure(boolean newSecure) {
if (newSecure == _secure) {
return this;
}
Reference r = _instance.referenceFactory().copy(this);
r._secure = newSecure;
return r;
}

public final Reference changeIdentity(com.zeroc.Ice.Identity newIdentity) {
if (newIdentity.equals(_identity)) {
return this;
}
Reference r = _instance.referenceFactory().copy(this);
r._identity = newIdentity.clone();
return r;
}

public final Reference changeFacet(String newFacet) {
if (newFacet.equals(_facet)) {
return this;
}
Reference r = _instance.referenceFactory().copy(this);
r._facet = newFacet;
return r;
}

public final Reference changeInvocationTimeout(int newTimeout) {
if (newTimeout == _invocationTimeout) {
return this;
}
Reference r = _instance.referenceFactory().copy(this);
r._invocationTimeout = newTimeout;
return r;
}

public Reference changeEncoding(com.zeroc.Ice.EncodingVersion newEncoding) {
if (newEncoding.equals(_encoding)) {
return this;
}
Reference r = _instance.referenceFactory().copy(this);
r._encoding = newEncoding;
return r;
}

public Reference changeCompress(boolean newCompress) {
if (_overrideCompress && _compress == newCompress) {
return this;
}
Reference r = _instance.referenceFactory().copy(this);
r._compress = newCompress;
r._overrideCompress = true;
Expand Down
Loading
Loading