Skip to content

Commit

Permalink
implementing issue JPPF-438 - refactored org.jppf.client.Operator:
Browse files Browse the repository at this point in the history
extracted interface ComparisonOperator, depracated the and made new
class in org.jppf.utils that implements the same interface, refactored
the code using the old Operator class
  • Loading branch information
lolocohen committed May 2, 2018
1 parent 8054b31 commit f326a0e
Show file tree
Hide file tree
Showing 54 changed files with 5,467 additions and 5,339 deletions.
3 changes: 2 additions & 1 deletion application-template/.gitignore
@@ -1 +1,2 @@
/classes/
/classes/
/.settings/

Large diffs are not rendered by default.

Expand Up @@ -264,8 +264,8 @@ boolean connectionHasStatus(final JPPFClientConnection connection, final boolean
* @return a list of {@link JPPFClientConnection} instances, possibly less than the requested number if the timeout expired first.
* @since 5.0
*/
public List<JPPFClientConnection> awaitConnections(final Operator operator, final int nbConnections, final long timeout, final JPPFClientConnectionStatus...statuses) {
final Operator op = operator == null ? Operator.EQUAL : operator;
public List<JPPFClientConnection> awaitConnections(final ComparisonOperator operator, final int nbConnections, final long timeout, final JPPFClientConnectionStatus...statuses) {
final ComparisonOperator op = operator == null ? org.jppf.utils.Operator.EQUAL : operator;
if (debugEnabled) log.debug(String.format("awaiting %d connections with operator=%s and status in %s", nbConnections, op, Arrays.asList(statuses)));
final MutableReference<List<JPPFClientConnection>> ref = new MutableReference<>();
ConcurrentUtils.awaitCondition(new ConcurrentUtils.Condition() {
Expand Down
4 changes: 2 additions & 2 deletions client/src/java/org/jppf/client/JMXConnectionPool.java
Expand Up @@ -174,8 +174,8 @@ private void initializeConnections() {
* @return a list of {@link JMXDriverConnectionWrapper} instances, possibly less than the requested number if the timeout expired first.
* @since 5.0
*/
List<JMXDriverConnectionWrapper> awaitJMXConnections(final Operator operator, final int nbConnections, final long timeout, final boolean connected) {
final Operator op = operator == null ? Operator.EQUAL : operator;
List<JMXDriverConnectionWrapper> awaitJMXConnections(final ComparisonOperator operator, final int nbConnections, final long timeout, final boolean connected) {
final ComparisonOperator op = operator == null ? org.jppf.utils.Operator.EQUAL : operator;
//setSize(nbConnections);
final MutableReference<List<JMXDriverConnectionWrapper>> ref = new MutableReference<>();
ConcurrentUtils.awaitCondition(new ConcurrentUtils.Condition() {
Expand Down
6 changes: 3 additions & 3 deletions client/src/java/org/jppf/client/JPPFClient.java
Expand Up @@ -273,8 +273,8 @@ public List<JPPFConnectionPool> awaitConnectionPools(final long timeout, final J
* @return a list of {@link JPPFConnectionPool} instances, possibly empty but never null.
* @since 5.0
*/
public List<JPPFConnectionPool> awaitConnectionPools(final Operator operator, final int expectedConnections, final long timeout, final JPPFClientConnectionStatus...statuses) {
return awaitConnectionPools(Operator.AT_LEAST, 1, operator, expectedConnections, timeout, statuses);
public List<JPPFConnectionPool> awaitConnectionPools(final ComparisonOperator operator, final int expectedConnections, final long timeout, final JPPFClientConnectionStatus...statuses) {
return awaitConnectionPools(org.jppf.utils.Operator.AT_LEAST, 1, operator, expectedConnections, timeout, statuses);
}

/**
Expand All @@ -295,7 +295,7 @@ public List<JPPFConnectionPool> awaitConnectionPools(final Operator operator, fi
* @return a list of {@link JPPFConnectionPool} instances, possibly empty but never null.
* @since 6.0
*/
public List<JPPFConnectionPool> awaitConnectionPools(final Operator poolOperator, final int expectedPools, final Operator connectionOperator, final int expectedConnections,
public List<JPPFConnectionPool> awaitConnectionPools(final ComparisonOperator poolOperator, final int expectedPools, final ComparisonOperator connectionOperator, final int expectedConnections,
final long timeout, final JPPFClientConnectionStatus...statuses) {
final MutableReference<List<JPPFConnectionPool>> ref = new MutableReference<>();
ConcurrentUtils.awaitCondition(new ConcurrentUtils.Condition() {
Expand Down
22 changes: 11 additions & 11 deletions client/src/java/org/jppf/client/JPPFConnectionPool.java
Expand Up @@ -22,7 +22,7 @@

import org.jppf.discovery.ClientConnectionPoolInfo;
import org.jppf.management.JMXDriverConnectionWrapper;
import org.jppf.utils.LoggingUtils;
import org.jppf.utils.*;
import org.slf4j.*;

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ public int setSize(final int newSize) {
* @return a list of {@code nbConnections} {@link JPPFClientConnection} instances with the desired status.
* @since 5.0
*/
public List<JPPFClientConnection> awaitActiveConnections(final Operator operator, final int nbConnections) {
public List<JPPFClientConnection> awaitActiveConnections(final ComparisonOperator operator, final int nbConnections) {
return awaitConnections(operator, nbConnections, Long.MAX_VALUE, JPPFClientConnectionStatus.ACTIVE);
}

Expand All @@ -115,7 +115,7 @@ public List<JPPFClientConnection> awaitActiveConnections(final Operator operator
* @since 5.1
*/
public JPPFClientConnection awaitActiveConnection() {
return awaitActiveConnections(Operator.AT_LEAST, 1).get(0);
return awaitActiveConnections(org.jppf.utils.Operator.AT_LEAST, 1).get(0);
}

/**
Expand All @@ -126,7 +126,7 @@ public JPPFClientConnection awaitActiveConnection() {
* @return a list of {@code nbConnections} {@link JPPFClientConnection} instances with the desired status.
* @since 5.0
*/
public List<JPPFClientConnection> awaitWorkingConnections(final Operator operator, final int nbConnections) {
public List<JPPFClientConnection> awaitWorkingConnections(final ComparisonOperator operator, final int nbConnections) {
return awaitConnections(operator, nbConnections, Long.MAX_VALUE, JPPFClientConnectionStatus.ACTIVE, JPPFClientConnectionStatus.EXECUTING);
}

Expand All @@ -137,7 +137,7 @@ public List<JPPFClientConnection> awaitWorkingConnections(final Operator operato
* @since 5.0
*/
public JPPFClientConnection awaitWorkingConnection() {
return awaitWorkingConnections(Operator.AT_LEAST, 1).get(0);
return awaitWorkingConnections(org.jppf.utils.Operator.AT_LEAST, 1).get(0);
}

/**
Expand All @@ -149,7 +149,7 @@ public JPPFClientConnection awaitWorkingConnection() {
* @return a list of {@code nbConnections} {@link JPPFClientConnection} instances.
* @since 5.0
*/
public List<JPPFClientConnection> awaitConnections(final Operator operator, final int nbConnections, final JPPFClientConnectionStatus...statuses) {
public List<JPPFClientConnection> awaitConnections(final ComparisonOperator operator, final int nbConnections, final JPPFClientConnectionStatus...statuses) {
return awaitConnections(operator, nbConnections, Long.MAX_VALUE, statuses);
}

Expand All @@ -161,7 +161,7 @@ public List<JPPFClientConnection> awaitConnections(final Operator operator, fina
* @since 5.1
*/
public JPPFClientConnection awaitConnection(final JPPFClientConnectionStatus...statuses) {
return awaitConnections(Operator.AT_LEAST, 1, Long.MAX_VALUE, statuses).get(0);
return awaitConnections(org.jppf.utils.Operator.AT_LEAST, 1, Long.MAX_VALUE, statuses).get(0);
}

/**
Expand All @@ -173,7 +173,7 @@ public JPPFClientConnection awaitConnection(final JPPFClientConnectionStatus...s
* @return a list of at least {@code nbConnections} {@link JMXDriverConnectionWrapper} instances.
* @since 5.0
*/
public List<JMXDriverConnectionWrapper> awaitJMXConnections(final Operator operator, final int nbConnections, final boolean connectedOnly) {
public List<JMXDriverConnectionWrapper> awaitJMXConnections(final ComparisonOperator operator, final int nbConnections, final boolean connectedOnly) {
return jmxPool.awaitJMXConnections(operator, nbConnections, Long.MAX_VALUE, connectedOnly);
}

Expand All @@ -186,7 +186,7 @@ public List<JMXDriverConnectionWrapper> awaitJMXConnections(final Operator opera
* @return a list of {@link JMXDriverConnectionWrapper} instances, possibly less than the requested number if the timeout expired first.
* @since 5.0
*/
public List<JMXDriverConnectionWrapper> awaitJMXConnections(final Operator operator, final int nbConnections, final long timeout, final boolean connectedOnly) {
public List<JMXDriverConnectionWrapper> awaitJMXConnections(final ComparisonOperator operator, final int nbConnections, final long timeout, final boolean connectedOnly) {
return jmxPool.awaitJMXConnections(operator, nbConnections, timeout, connectedOnly);
}

Expand All @@ -197,7 +197,7 @@ public List<JMXDriverConnectionWrapper> awaitJMXConnections(final Operator opera
* @since 5.1
*/
public JMXDriverConnectionWrapper awaitJMXConnection(final boolean connectedOnly) {
return awaitJMXConnections(Operator.AT_LEAST, 1, connectedOnly).get(0);
return awaitJMXConnections(org.jppf.utils.Operator.AT_LEAST, 1, connectedOnly).get(0);
}

/**
Expand All @@ -206,6 +206,6 @@ public JMXDriverConnectionWrapper awaitJMXConnection(final boolean connectedOnly
* @since 5.1
*/
public JMXDriverConnectionWrapper awaitWorkingJMXConnection() {
return awaitJMXConnections(Operator.AT_LEAST, 1, true).get(0);
return awaitJMXConnections(org.jppf.utils.Operator.AT_LEAST, 1, true).get(0);
}
}
147 changes: 71 additions & 76 deletions common/src/java/org/jppf/client/Operator.java
@@ -1,76 +1,71 @@
/*
* JPPF.
* Copyright (C) 2005-2017 JPPF Team.
* http://www.jppf.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jppf.client;

/**
* Enumeration of the possible boolean operators that can be used as a comparison predicates for integer/long values.
* @author Laurent Cohen
*/
public enum Operator {
/**
* The number of connections is equal to the expected number.
*/
EQUAL {
@Override
public boolean evaluate(final long actual, final long expected) { return actual == expected; }
},
/**
* The number of connections is different from the expected number.
*/
NOT_EQUAL {
@Override
public boolean evaluate(final long actual, final long expected) { return actual != expected; }
},
/**
* The number of connections is at least the expected number.
*/
AT_LEAST {
@Override
public boolean evaluate(final long actual, final long expected) { return actual >= expected; }
},
/**
* The number of connections is at most the expected number.
*/
AT_MOST {
@Override
public boolean evaluate(final long actual, final long expected) { return actual <= expected; }
},
/**
* The number of connections is strictly greater than the expected number.
*/
MORE_THAN {
@Override
public boolean evaluate(final long actual, final long expected) { return actual > expected; }
},
/**
* The number of connections is strictly less than the expected number.
*/
LESS_THAN {
@Override
public boolean evaluate(final long actual, final long expected) { return actual < expected; }
};

/**
* Evaluate the condition based on the actual and expected number of connections.
* @param actual the actual number of connections.
* @param expected the expected number of connections
* @return true if the condition is matched, false otherwise.
*/
public abstract boolean evaluate(long actual, long expected);
}
/*
* JPPF.
* Copyright (C) 2005-2017 JPPF Team.
* http://www.jppf.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jppf.client;

import org.jppf.utils.ComparisonOperator;

/**
* Enumeration of the possible boolean operators that can be used as a comparison predicates for integer/long values.
* @author Laurent Cohen
* @deprecated use {@link org.jppf.utils.Operator} instead.
*/
public enum Operator implements ComparisonOperator {
/**
* The number of connections is equal to the expected number.
*/
EQUAL {
@Override
public boolean evaluate(final long actual, final long expected) { return actual == expected; }
},
/**
* The number of connections is different from the expected number.
*/
NOT_EQUAL {
@Override
public boolean evaluate(final long actual, final long expected) { return actual != expected; }
},
/**
* The number of connections is at least the expected number.
*/
AT_LEAST {
@Override
public boolean evaluate(final long actual, final long expected) { return actual >= expected; }
},
/**
* The number of connections is at most the expected number.
*/
AT_MOST {
@Override
public boolean evaluate(final long actual, final long expected) { return actual <= expected; }
},
/**
* The number of connections is strictly greater than the expected number.
*/
MORE_THAN {
@Override
public boolean evaluate(final long actual, final long expected) { return actual > expected; }
},
/**
* The number of connections is strictly less than the expected number.
*/
LESS_THAN {
@Override
public boolean evaluate(final long actual, final long expected) { return actual < expected; }
};
}

0 comments on commit f326a0e

Please sign in to comment.