-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from mendix/features/idle-connection-monitor
Added a idle connection monitor that regularly closes idle connections
- Loading branch information
Showing
7 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
51 changes: 51 additions & 0 deletions
51
javasource/restservices/actions/startIdleConnectionMonitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// This file was generated by Mendix Modeler. | ||
// | ||
// WARNING: Only the following code will be retained when actions are regenerated: | ||
// - the import list | ||
// - the code between BEGIN USER CODE and END USER CODE | ||
// - the code between BEGIN EXTRA CODE and END EXTRA CODE | ||
// Other code you write will be lost the next time you deploy the project. | ||
// Special characters, e.g., é, ö, à, etc. are supported in comments. | ||
|
||
package restservices.actions; | ||
|
||
import com.mendix.systemwideinterfaces.core.IContext; | ||
import com.mendix.webui.CustomJavaAction; | ||
|
||
import restservices.consume.RestConsumer; | ||
|
||
/** | ||
* Regularly checks for connections connections that have been idle for at least the given amount of time, and closes them. | ||
*/ | ||
public class startIdleConnectionMonitor extends CustomJavaAction<java.lang.Boolean> | ||
{ | ||
private java.lang.Long interval; | ||
private java.lang.Long maxIdleTime; | ||
|
||
public startIdleConnectionMonitor(IContext context, java.lang.Long interval, java.lang.Long maxIdleTime) | ||
{ | ||
super(context); | ||
this.interval = interval; | ||
this.maxIdleTime = maxIdleTime; | ||
} | ||
|
||
@Override | ||
public java.lang.Boolean executeAction() throws Exception | ||
{ | ||
// BEGIN USER CODE | ||
return RestConsumer.startIdleConnectionMonitor(interval, maxIdleTime); | ||
// END USER CODE | ||
} | ||
|
||
/** | ||
* Returns a string representation of this action | ||
*/ | ||
@Override | ||
public java.lang.String toString() | ||
{ | ||
return "startIdleConnectionMonitor"; | ||
} | ||
|
||
// BEGIN EXTRA CODE | ||
// END EXTRA CODE | ||
} |
39 changes: 39 additions & 0 deletions
39
javasource/restservices/consume/IdleConnectionMonitorThread.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package restservices.consume; | ||
|
||
import org.apache.commons.httpclient.HttpConnectionManager; | ||
|
||
public class IdleConnectionMonitorThread extends Thread { | ||
|
||
private final HttpConnectionManager connMgr; | ||
private long intervalMillis; | ||
private long maxIdleTimeMillis; | ||
private volatile boolean shutdown; | ||
|
||
public IdleConnectionMonitorThread(HttpConnectionManager connMgr, long intervalMillis, long maxIdleTimeMillis) { | ||
super(); | ||
this.connMgr = connMgr; | ||
this.intervalMillis = intervalMillis; | ||
this.maxIdleTimeMillis = maxIdleTimeMillis; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
while (!shutdown) { | ||
synchronized (this) { | ||
wait(intervalMillis); | ||
connMgr.closeIdleConnections(maxIdleTimeMillis); | ||
} | ||
} | ||
} catch (InterruptedException ex) { | ||
// terminate | ||
} | ||
} | ||
|
||
public void shutdown() { | ||
shutdown = true; | ||
synchronized (this) { | ||
notifyAll(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Empty file.