Skip to content

Commit

Permalink
Merge pull request #26 from willrogers/search-intervals
Browse files Browse the repository at this point in the history
Make max and min search periods configurable.
  • Loading branch information
shroffk authored Apr 25, 2018
2 parents d292d0f + 8a43715 commit 6c29417
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/core/JCALibrary.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ com.cosylab.epics.caj.CAJContext.beacon_period = 15.0
com.cosylab.epics.caj.CAJContext.repeater_port = 5065
com.cosylab.epics.caj.CAJContext.server_port = 5064
com.cosylab.epics.caj.CAJContext.max_array_bytes = 16384
com.cosylab.epics.caj.CAJContext.max_search_interval = 300
com.cosylab.epics.caj.impl.reactor.lf.LeaderFollowersThreadPool.thread_pool_size = 5
92 changes: 58 additions & 34 deletions src/core/com/cosylab/epics/caj/CAJContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public class CAJContext extends Context implements CAContext, CAJConstants, Conf
*/
protected int maxArrayBytes = 16384;

/**
* Maximum interval in seconds between CA search broadcasts. Default is 5 minutes.
*/
protected float maxSearchInterval = (float) 60.0 * 5;

/**
* List of context message listeners.
*/
Expand Down Expand Up @@ -404,40 +409,43 @@ protected void loadConfiguration()

String eventDispatcherClassName = null;
final String thisClassName = this.getClass().getName();
if (Boolean.getBoolean("jca.use_env"))
{
// Context default configuration
eventDispatcherClassName = jcaLibrary.getProperty( gov.aps.jca.Context.class.getName()+".event_dispatcher", eventDispatcherClassName );

String tmp = System.getenv("EPICS_CA_ADDR_LIST");
if (tmp != null) addressList = tmp;

tmp = System.getenv("EPICS_CA_AUTO_ADDR_LIST");
if (tmp != null)
autoAddressList = !tmp.equalsIgnoreCase("NO");
else
autoAddressList = true;

tmp = System.getenv("EPICS_CA_NAME_SERVERS");
if (tmp != null) nameServersList = tmp;

tmp = System.getenv("EPICS_CA_CONN_TMO");
if (tmp != null) connectionTimeout = Float.parseFloat(tmp);

tmp = System.getenv("EPICS_CA_BEACON_PERIOD");
if (tmp != null) beaconPeriod = Float.parseFloat(tmp);

tmp = System.getenv("EPICS_CA_REPEATER_PORT");
if (tmp != null) repeaterPort = Integer.parseInt(tmp);

tmp = System.getenv("EPICS_CA_SERVER_PORT");
if (tmp != null) serverPort = Integer.parseInt(tmp);

tmp = System.getenv("EPICS_CA_MAX_ARRAY_BYTES");
if (tmp != null) maxArrayBytes = Integer.parseInt(tmp);
}
else
{
if (Boolean.getBoolean("jca.use_env"))
{
// Context default configuration
eventDispatcherClassName = jcaLibrary.getProperty( gov.aps.jca.Context.class.getName()+".event_dispatcher", eventDispatcherClassName );

String tmp = System.getenv("EPICS_CA_ADDR_LIST");
if (tmp != null) addressList = tmp;

tmp = System.getenv("EPICS_CA_AUTO_ADDR_LIST");
if (tmp != null)
autoAddressList = !tmp.equalsIgnoreCase("NO");
else
autoAddressList = true;

tmp = System.getenv("EPICS_CA_NAME_SERVERS");
if (tmp != null) nameServersList = tmp;

tmp = System.getenv("EPICS_CA_CONN_TMO");
if (tmp != null) connectionTimeout = Float.parseFloat(tmp);

tmp = System.getenv("EPICS_CA_BEACON_PERIOD");
if (tmp != null) beaconPeriod = Float.parseFloat(tmp);

tmp = System.getenv("EPICS_CA_REPEATER_PORT");
if (tmp != null) repeaterPort = Integer.parseInt(tmp);

tmp = System.getenv("EPICS_CA_SERVER_PORT");
if (tmp != null) serverPort = Integer.parseInt(tmp);

tmp = System.getenv("EPICS_CA_MAX_ARRAY_BYTES");
if (tmp != null) maxArrayBytes = Integer.parseInt(tmp);

tmp = System.getenv("EPICS_CA_MAX_SEARCH_PERIOD");
if (tmp != null) maxSearchInterval = Float.parseFloat(tmp);
}
else
{
// load default Context configuration
final String contextClassName = Context.class.getName();
addressList = jcaLibrary.getProperty(contextClassName + ".addr_list", addressList);
Expand All @@ -448,6 +456,7 @@ protected void loadConfiguration()
repeaterPort = jcaLibrary.getPropertyAsInt(contextClassName + ".repeater_port", repeaterPort);
serverPort = jcaLibrary.getPropertyAsInt(contextClassName + ".server_port", serverPort);
maxArrayBytes = jcaLibrary.getPropertyAsInt(contextClassName + ".max_array_bytes", maxArrayBytes);
maxSearchInterval = jcaLibrary.getPropertyAsFloat(contextClassName + ".max_search_interval", maxSearchInterval);
eventDispatcherClassName = jcaLibrary.getProperty(contextClassName + ".event_dispatcher");

// load CAJ specific configuration (overrides default)
Expand All @@ -459,6 +468,7 @@ protected void loadConfiguration()
repeaterPort = jcaLibrary.getPropertyAsInt(thisClassName + ".repeater_port", repeaterPort);
serverPort = jcaLibrary.getPropertyAsInt(thisClassName + ".server_port", serverPort);
maxArrayBytes = jcaLibrary.getPropertyAsInt(thisClassName + ".max_array_bytes", maxArrayBytes);
maxSearchInterval = jcaLibrary.getPropertyAsFloat(thisClassName + ".max_search_interval", maxSearchInterval);
}

eventDispatcherClassName = jcaLibrary.getProperty(thisClassName + ".event_dispatcher", eventDispatcherClassName);
Expand Down Expand Up @@ -530,6 +540,13 @@ public void configure(Configuration configuration)
maxArrayBytes = configuration.getAttributeAsInteger("max_array_bytes", maxArrayBytes);
}

// max. search interval
try {
maxSearchInterval = configuration.getChild("max_search_interval", false).getValueAsFloat();
} catch(Exception ex) {
maxSearchInterval = configuration.getAttributeAsFloat("max_search_interval", maxSearchInterval);
}

// event dispathcer
Configuration conf = configuration.getChild("event_dispatcher", false);
if (conf != null)
Expand Down Expand Up @@ -1262,6 +1279,7 @@ public void printInfo(PrintStream out) throws IllegalStateException {
out.println("REPEATER_PORT : " + repeaterPort);
out.println("SERVER_PORT : " + serverPort);
out.println("MAX_ARRAY_BYTES : " + maxArrayBytes);
out.println("MAX_SEARCH_INTERVAL : " + maxSearchInterval);
out.println("EVENT_DISPATCHER: " + eventDispatcher);
out.print("STATE : ");
switch (state)
Expand Down Expand Up @@ -1368,6 +1386,12 @@ public int getBroadcastPort() {
return getServerPort();
}

/**
* Get max. search interval
* @return max. search interval
*/
public float getMaxSearchInterval() { return maxSearchInterval; }

/**
* Get event dispatcher.
* @return event dispatcher.
Expand Down
4 changes: 2 additions & 2 deletions src/core/com/cosylab/epics/caj/impl/ChannelSearchManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class ChannelSearchManager {
private final int intervalMultiplier;

private static final int MIN_SEND_INTERVAL_MS_DEFAULT = 100;
private static final int MAX_SEND_INTERVAL_MS_DEFAULT = 30000;
private static final int INTERVAL_MULTIPLIER_DEFAULT = 2;

private static final int MESSAGE_COALESCENCE_TIME_MS = 3;
Expand Down Expand Up @@ -194,7 +193,8 @@ public ChannelSearchManager(CAJContext context)
this.context = context;

minSendInterval = MIN_SEND_INTERVAL_MS_DEFAULT;
maxSendInterval = MAX_SEND_INTERVAL_MS_DEFAULT;
// Convert from seconds to milliseconds.
maxSendInterval = (long) (context.getMaxSearchInterval() * 1000);
intervalMultiplier = INTERVAL_MULTIPLIER_DEFAULT;

// create and initialize send buffer
Expand Down
1 change: 1 addition & 0 deletions src/core/gov/aps/jca/JCALibrary.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ com.cosylab.epics.caj.CAJContext.beacon_period = 15.0
com.cosylab.epics.caj.CAJContext.repeater_port = 5065
com.cosylab.epics.caj.CAJContext.server_port = 5064
com.cosylab.epics.caj.CAJContext.max_array_bytes = 16384
com.cosylab.epics.caj.CAJContext.max_search_interval = 300
com.cosylab.epics.caj.impl.reactor.lf.LeaderFollowersThreadPool.thread_pool_size = 5
1 change: 1 addition & 0 deletions test/com/cosylab/epics/caj/cas/test/JCALibrary.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ com.cosylab.epics.caj.CAJContext.beacon_period = 15.0
com.cosylab.epics.caj.CAJContext.repeater_port = 5065
com.cosylab.epics.caj.CAJContext.server_port = 5064
com.cosylab.epics.caj.CAJContext.max_array_bytes = 16384
com.cosylab.epics.caj.CAJContext.max_search_interval = 300
com.cosylab.epics.caj.impl.reactor.lf.LeaderFollowersThreadPool.thread_pool_size = 5

0 comments on commit 6c29417

Please sign in to comment.