Skip to content

Commit

Permalink
Bypassed AnnounceTask
Browse files Browse the repository at this point in the history
Fixed retry issue, bypassed announcement task.
All handled in TaskFetcher
  • Loading branch information
JRAndreassen committed Sep 29, 2015
1 parent 83784b5 commit 95a687b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ target/JMXProbe/
target/maven-archiver/
probe_installer.py
PRTG_SSL_Negotiation.txt
JMXMBeans.xml
target/JMXMiniProbe.jar
JMXMBeans.xml
4 changes: 3 additions & 1 deletion src/com/paessler/prtg/jmx/DaemonMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
package com.paessler.prtg.jmx;

import com.paessler.prtg.jmx.tasks.AnnouncementTask;
import com.paessler.prtg.jmx.tasks.TaskFetcherTask;
import com.paessler.prtg.util.SystemUtility;

import org.apache.commons.cli.*;
Expand Down Expand Up @@ -85,7 +86,8 @@ public static void main(String[] args) {
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
}
// ScheduledExecutorService
scheduledExecutorService.schedule(new AnnouncementTask(probeContext, scheduledExecutorService), 1, TimeUnit.SECONDS);
// scheduledExecutorService.schedule(new AnnouncementTask(probeContext, scheduledExecutorService), 1, TimeUnit.SECONDS);
scheduledExecutorService.scheduleWithFixedDelay(new TaskFetcherTask(null, probeContext, scheduledExecutorService), 10, probeContext.getBaseInterval(), TimeUnit.SECONDS);
} else {
System.out.println(probeContext.getErrorMessage()+" Failiure to launch->"+probeContext.getErrorMessage());
Logger.log(probeContext.getErrorMessage());
Expand Down
4 changes: 3 additions & 1 deletion src/com/paessler/prtg/jmx/ServletMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package com.paessler.prtg.jmx;

import com.paessler.prtg.jmx.tasks.AnnouncementTask;
import com.paessler.prtg.jmx.tasks.TaskFetcherTask;

import javax.servlet.*;

Expand Down Expand Up @@ -71,7 +72,8 @@ public void contextInitialized(ServletContextEvent servletContextEvent) {
} else {
mScheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
}
mScheduledExecutorService.schedule(new AnnouncementTask(probeContext, context, mScheduledExecutorService), 1, TimeUnit.SECONDS);
// mScheduledExecutorService.schedule(new AnnouncementTask(probeContext, context, mScheduledExecutorService), 1, TimeUnit.SECONDS);
mScheduledExecutorService.scheduleWithFixedDelay(new TaskFetcherTask(context, probeContext, mScheduledExecutorService), 10, probeContext.getBaseInterval(), TimeUnit.SECONDS);
} else {
System.out.println(probeContext.getErrorMessage()+" Failiure to launch-> [Default Config path="+defCondpath+"]");
Logger.log(probeContext.getErrorMessage()+" [Default Config path="+defCondpath+"]");
Expand Down
35 changes: 24 additions & 11 deletions src/com/paessler/prtg/jmx/tasks/TaskFetcherTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

import javax.servlet.ServletContext;

import org.apache.http.client.HttpResponseException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -88,18 +90,29 @@ public boolean sendAnnouncement(ProbeContext context){

Announcement announcement = new Announcement(context.getProbeName(), context.getVersionString(), context.getBaseInterval(), definitions);
String url = announcement.buildUrl(context);
try {
String postBody = announcement.toString();
if(context.getDebugLevel() > 0){
Logger.log("Sending: "+url+" " + postBody);
}
NetworkWrapper.post(url, postBody);
retVal = true;
reRunAnnouncement = false;
} catch (Exception e) {
Logger.log(e.getLocalizedMessage());
int maxtries = 5;
for(int retryAttempts = 0;!retVal && retryAttempts < maxtries; ++retryAttempts){
try {
String postBody = announcement.toString();
if(context.getDebugLevel() > 0){
Logger.log("Sending: "+url+" " + postBody);
}
NetworkWrapper.post(url, postBody);
retVal = true;
reRunAnnouncement = false;
} catch (HttpResponseException he) {
if(he.getStatusCode() < 500){
Logger.log(he.getLocalizedMessage());
Thread.sleep(10000*retryAttempts);
} else{
retryAttempts = maxtries;
}
} catch (Exception e) {
Logger.log(e.getLocalizedMessage());
retryAttempts = maxtries;
}

}

} catch (Throwable e) {
Logger.log("Cought Throwable in TaskFetcherTask.run(). "+e.getMessage());
e.printStackTrace();
Expand Down

0 comments on commit 95a687b

Please sign in to comment.