-
Notifications
You must be signed in to change notification settings - Fork 34
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 #2551 from subutai-io/issue-2547
#2547 Send peer metrics on container destruction
- Loading branch information
Showing
4 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
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
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
45 changes: 45 additions & 0 deletions
45
...b-manager-impl/src/main/java/io/subutai/core/hubmanager/impl/util/ReschedulableTimer.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,45 @@ | ||
package io.subutai.core.hubmanager.impl.util; | ||
|
||
|
||
import java.util.Timer; | ||
import java.util.TimerTask; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.google.common.base.Preconditions; | ||
|
||
|
||
public class ReschedulableTimer extends Timer | ||
{ | ||
private final Runnable task; | ||
private TimerTask timerTask; | ||
|
||
|
||
public ReschedulableTimer( final Runnable task ) | ||
{ | ||
Preconditions.checkNotNull( task ); | ||
|
||
this.task = task; | ||
} | ||
|
||
|
||
public synchronized void schedule( long delayInSec ) | ||
{ | ||
Preconditions.checkArgument( delayInSec >= 0 ); | ||
|
||
if ( timerTask != null ) | ||
{ | ||
timerTask.cancel(); | ||
} | ||
|
||
timerTask = new TimerTask() | ||
{ | ||
@Override | ||
public void run() | ||
{ | ||
task.run(); | ||
} | ||
}; | ||
|
||
this.schedule( timerTask, TimeUnit.SECONDS.toMillis( delayInSec ) ); | ||
} | ||
} |