Skip to content

Commit

Permalink
linger on shutdown fix
Browse files Browse the repository at this point in the history
--HG--
branch : v301
  • Loading branch information
rogierc committed Dec 29, 2024
1 parent e7efde4 commit 3595f4f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import nl.teslanet.mule.connectors.coap.internal.endpoint.OperationalEndpoint;
import nl.teslanet.mule.connectors.coap.internal.exceptions.InternalResourceRegistryException;
import nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUriPatternException;
import nl.teslanet.mule.connectors.coap.internal.utils.TimeUtils;


/**
Expand Down Expand Up @@ -127,7 +128,7 @@ public class Server implements Initialisable, Disposable, Startable, Stoppable
@ParameterDsl( allowReferences= false )
@Summary( value= "Main endpoint the server uses." )
@Placement( order= 1, tab= "Endpoint" )
Endpoint endpoint;
private Endpoint endpoint;

/**
* The additional endpoints the server uses.
Expand Down Expand Up @@ -166,22 +167,22 @@ public class Server implements Initialisable, Disposable, Startable, Stoppable
@ParameterDsl( allowReferences= false )
@DisplayName( value= "Notify observing clients on shutdown" )
@Placement( order= 1, tab= "Advanced" )
public boolean notifyOnShutdown= true;
private boolean notifyOnShutdown= true;

/**
* The linger time (in milliseconds [ms]) on shutdown of the server,
* giving notifications time to complete.
* Default value is 250 ms.
*/
@Parameter
@Optional( defaultValue= "250" )
@Optional( defaultValue= "250ms" )
@Summary(
value= "The linger time (in milliseconds [ms]) on shutdown of the server, \ngiving notifications time to complete. \nDefault value is 250 ms."
value= "The linger duration on shutdown of the server, \ngiving notifications time to complete. \nDefault value is 250 ms."
)
@Expression( ExpressionSupport.NOT_SUPPORTED )
@ParameterDsl( allowReferences= false )
@Placement( order= 2, tab= "Advanced" )
public long lingerOnShutdown= 250L;
private String lingerOnShutdown= "250ms";

/**
* The Californium CoAP server instance.
Expand All @@ -193,8 +194,13 @@ public class Server implements Initialisable, Disposable, Startable, Stoppable
*/
private ResourceRegistry registry= null;

/* (non-Javadoc)
* @see org.mule.runtime.api.lifecycle.Initialisable#initialise()
/**
* Calculated linger milliseconds.
*/
private long lingerOnShutdownMillis= 250L;

/**
* Initialize the server and connect to CoAP endpoints.
*/
@Override
public void initialise() throws InitialisationException
Expand Down Expand Up @@ -278,6 +284,7 @@ public void start() throws MuleException
{
try
{
lingerOnShutdownMillis= TimeUtils.toNanos( lingerOnShutdown ) / 1000000L;
if ( resources != null )
{
for ( ResourceConfig resourceConfig : resources )
Expand Down Expand Up @@ -317,7 +324,7 @@ public void stop() throws MuleException
//linger to get notifications sent.
try
{
Thread.sleep( lingerOnShutdown );
Thread.sleep( lingerOnShutdownMillis );
}
catch ( InterruptedException e )
{
Expand All @@ -332,9 +339,9 @@ public void stop() throws MuleException
//cleanup still needed
registry.removeAll();
}
ioScheduler.stop();
//TODO ioScheduler.stop();
ioScheduler= null;
cpuLightScheduler.stop();
//TODO cpuLightScheduler.stop();
cpuLightScheduler= null;
LOGGER.info( "{} stopped", this );
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/schemata/mule-coap.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@
<xs:documentation>Notify observing clients of server shutdown. When true observing clients are notified by Not-Found notifications. Default value is true.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute type="mule:substitutableLong" use="optional" default="250" name="lingerOnShutdown">
<xs:attribute type="xs:string" use="optional" default="250ms" name="lingerOnShutdown">
<xs:annotation>
<xs:documentation>The linger time (in milliseconds [ms]) on shutdown of the server, giving notifications time to complete. Default value is 250 ms.</xs:documentation>
</xs:annotation>
Expand Down Expand Up @@ -3129,4 +3129,4 @@
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:schema>
</xs:schema>

0 comments on commit 3595f4f

Please sign in to comment.