Skip to content

Commit

Permalink
cancelThrottleRequest(address, this)
Browse files Browse the repository at this point in the history
Use cancelThrottleRequest(address, this) instead of responseThrottleDecision(address, this, DecisionType.CANCEL );
  • Loading branch information
icklesteve committed May 14, 2019
1 parent 25d4573 commit 9bd08a3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
22 changes: 9 additions & 13 deletions java/src/jmri/ThrottleListener.java
Expand Up @@ -32,21 +32,17 @@ public interface ThrottleListener extends EventListener {
*/
enum DecisionType {
/**
* Notification for decision needed Steal OR Cancel, or wish to Steal
* Notification for decision needed, Steal OR Cancel, or wish to Steal
*/
STEAL,
/**
* Notification for decision needed Share OR Cancel, or wish to Share
* Notification for decision needed, Share OR Cancel, or wish to Share
*/
SHARE,
/**
* Notification for decision needed Steal OR Share OR Cancel
* Notification for decision needed, Steal OR Share OR Cancel
*/
STEAL_OR_SHARE,
/**
* Notification of wish to Cancel
*/
CANCEL
STEAL_OR_SHARE
}

/**
Expand Down Expand Up @@ -110,7 +106,7 @@ enum DecisionType {
* end
*
* group If the Listener chooses to cancel
* ThrottleListener --> ThrottleManager : responseThrottleDecision(LocoAddress, ThrottleListener, ThrottleListener.DecisionType.CANCEL )
* ThrottleListener --> ThrottleManager : cancelThrottleRequest(LocoAddress, ThrottleListener)
* note over ThrottleListener : Request ends here
* end
* end
Expand All @@ -119,11 +115,11 @@ enum DecisionType {
* ThrottleListener <-- ThrottleManager : notifyDecisionRequired(LocoAddress, ThrottleListener.DecisionType.SHARE)
*
* group If the Listener chooses to share
* ThrottleListener --> ThrottleManager : responseThrottleDecision(LocoAddress, ThrottleListener, ThrottleListener.DecisionType.SHARE )
* ThrottleListener --> ThrottleManager : responseThrottleDecision(LocoAddress, ThrottleListener, ThrottleListener.DecisionType.SHARE)
* end
*
* group If the Listener chooses to cancel
* ThrottleListener --> ThrottleManager : responseThrottleDecision(LocoAddress, ThrottleListener, ThrottleListener.DecisionType.CANCEL )
* ThrottleListener --> ThrottleManager : cancelThrottleRequest(LocoAddress, ThrottleListener)
* note over ThrottleListener : Request ends here
* end
end
Expand All @@ -136,11 +132,11 @@ enum DecisionType {
* end
*
* group If the Listener chooses to share
* ThrottleListener --> ThrottleManager : responseThrottleDecision(LocoAddress, ThrottleListener, ThrottleListener.DecisionType.SHARE )
* ThrottleListener --> ThrottleManager : responseThrottleDecision(LocoAddress, ThrottleListener, ThrottleListener.DecisionType.SHARE)
* end
*
* group If the Listener chooses to cancel
* ThrottleListener --> ThrottleManager : responseThrottleDecision(LocoAddress, ThrottleListener, ThrottleListener.DecisionType.CANCEL )
* ThrottleListener --> ThrottleManager : cancelThrottleRequest(LocoAddress, ThrottleListener)
* note over ThrottleListener : Request ends here
* end
end
Expand Down
Expand Up @@ -651,7 +651,7 @@ public void notifyFailedThrottleRequest(jmri.LocoAddress address, String reason)
@Override
public void notifyDecisionRequired(jmri.LocoAddress address, DecisionType question) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("ErrorNoStealing"));
InstanceManager.throttleManagerInstance().responseThrottleDecision(address, this, DecisionType.CANCEL );
InstanceManager.throttleManagerInstance().cancelThrottleRequest(address, this);
setButtonStates(true);
throttleState = -1;
}
Expand Down
6 changes: 3 additions & 3 deletions java/src/jmri/jmrit/throttle/AddressPanel.java
Expand Up @@ -255,7 +255,7 @@ public void notifyDecisionRequired(LocoAddress address, DecisionType question) {
Bundle.getMessage("StealRequestTitle"), javax.swing.JOptionPane.YES_NO_OPTION)) {
InstanceManager.throttleManagerInstance().responseThrottleDecision(address, this, DecisionType.STEAL );
} else {
InstanceManager.throttleManagerInstance().responseThrottleDecision(address, this, DecisionType.CANCEL );
InstanceManager.throttleManagerInstance().cancelThrottleRequest(address, this);
}
});
}
Expand All @@ -270,7 +270,7 @@ else if ( question == DecisionType.SHARE ){
Bundle.getMessage("ShareRequestTitle"), javax.swing.JOptionPane.YES_NO_OPTION)) {
InstanceManager.throttleManagerInstance().responseThrottleDecision(address, this, DecisionType.SHARE );
} else {
InstanceManager.throttleManagerInstance().responseThrottleDecision(address, this, DecisionType.CANCEL );
InstanceManager.throttleManagerInstance().cancelThrottleRequest(address, this);
}
});
}
Expand Down Expand Up @@ -303,7 +303,7 @@ else if ( question == DecisionType.STEAL_OR_SHARE ){
}
else {
log.debug("cancel clicked");
InstanceManager.throttleManagerInstance().responseThrottleDecision(address, this, DecisionType.CANCEL );
InstanceManager.throttleManagerInstance().cancelThrottleRequest(address, this);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrix/AbstractThrottleManager.java
Expand Up @@ -318,7 +318,7 @@ public void cancelThrottleRequest(LocoAddress la, ThrottleListener l) {
*/
@Override
public void responseThrottleDecision(LocoAddress address, ThrottleListener l, ThrottleListener.DecisionType decision) {
log.error("Received response form ThrottleListener, this method should be overridden by a hardware type");
log.debug("Received response from ThrottleListener, this method should be overridden by a hardware type");
}

/**
Expand Down
23 changes: 16 additions & 7 deletions java/src/jmri/jmrix/can/cbus/CbusThrottleManager.java
Expand Up @@ -613,13 +613,7 @@ else if ( question == DecisionType.STEAL_OR_SHARE ){
@Override
public void responseThrottleDecision(LocoAddress address, ThrottleListener l, DecisionType decision) {
log.debug("Received {} response for Loco {}, listener {}",decision,address,l);
if ( decision == DecisionType.CANCEL ){
cancelThrottleRequest(address,l);
failedThrottleRequest(address, "User cancelled request.");
}
else {
requestThrottleSetup(address,decision);
}
requestThrottleSetup(address,decision);
}

/**
Expand Down Expand Up @@ -696,5 +690,20 @@ protected void updateNumUsers( LocoAddress la, int numUsers ){
}
}


/**
* {@inheritDoc}
*/
@Override
public void cancelThrottleRequest(LocoAddress address, ThrottleListener l) {

// calling super removes the ThrottleListener from the callback list,
// The listener which has just sent the cancel doesn't need notification
// of the cancel but other listeners might
super.cancelThrottleRequest(address, l);

failedThrottleRequest(address, "Throttle Request " + address + " Cancelled.");
}

private final static Logger log = LoggerFactory.getLogger(CbusThrottleManager.class);
}
21 changes: 8 additions & 13 deletions java/src/jmri/jmrix/loconet/LnThrottleManager.java
Expand Up @@ -462,7 +462,14 @@ public void failedThrottleRequest(LocoAddress address, String reason) {
*/
@Override
public void cancelThrottleRequest(LocoAddress address, ThrottleListener l) {

// calling super removes the ThrottleListener from the callback list,
// The listener which has just sent the cancel doesn't need notification
// of the cancel but other listeners might
super.cancelThrottleRequest(address, l);

failedThrottleRequest(address, "Throttle Request " + address + " Cancelled.");

int loconumber = address.getNumber();
log.debug("cancelThrottleRequest - loconumber {}", loconumber);
if (waitingForNotification.containsKey(loconumber)) {
Expand Down Expand Up @@ -548,19 +555,7 @@ public void responseThrottleDecision(LocoAddress address, ThrottleListener l, Th

log.debug("{} decision invoked for address {}",decision,address.getNumber() );

if ( decision == ThrottleListener.DecisionType.CANCEL ) {

if (address instanceof DccLocoAddress) {
cancelThrottleRequest(address,l);
failedThrottleRequest(address, "User chose not to 'steal' the throttle.");

} else {
log.error("not a DccLocoAddress.");
requestOutstanding = false;
processQueuedThrottleSetupRequest();
}
}
else if ( decision == ThrottleListener.DecisionType.STEAL ) {
if ( decision == ThrottleListener.DecisionType.STEAL ) {
// Steal is currently implemented by using the same method
// we used to aquire the slot prior to the release of
// Digitrax command stations with expanded slots.
Expand Down
6 changes: 3 additions & 3 deletions java/test/jmri/jmrix/loconet/LnThrottleManagerTest.java
Expand Up @@ -299,7 +299,7 @@ public void notifyDecisionRequired(LocoAddress address, DecisionType question) {
// this is a never-stealing impelementation.
if ( question == DecisionType.STEAL ){
flagGotStealRequest = address.getNumber();
InstanceManager.throttleManagerInstance().responseThrottleDecision(address, this, DecisionType.CANCEL);
InstanceManager.throttleManagerInstance().cancelThrottleRequest(address, this);
log.error("1: Got a steal request");
}
}
Expand Down Expand Up @@ -345,7 +345,7 @@ public void notifyDecisionRequired(LocoAddress address, DecisionType question) {
// this is a never-stealing impelementation.
if ( question == DecisionType.STEAL ){
flagGotStealRequest = address.getNumber();
InstanceManager.throttleManagerInstance().responseThrottleDecision(address, this, DecisionType.CANCEL);
InstanceManager.throttleManagerInstance().cancelThrottleRequest(address, this);
log.error("2: Got a steal request");
}
}
Expand Down Expand Up @@ -390,7 +390,7 @@ public void notifyDecisionRequired(LocoAddress address, DecisionType question) {
// this is a never-stealing impelementation.
if ( question == DecisionType.STEAL ){
flagGotStealRequest = address.getNumber();
InstanceManager.throttleManagerInstance().responseThrottleDecision(address, this, DecisionType.CANCEL);
InstanceManager.throttleManagerInstance().cancelThrottleRequest(address, this);
log.error("3: Got a steal request");
}
}
Expand Down

0 comments on commit 9bd08a3

Please sign in to comment.