Skip to content

Commit

Permalink
Added some debugging and changed the registration to a GET (because i…
Browse files Browse the repository at this point in the history
… couldn't explain why it wasn't returning at times when the server wasn't available).
  • Loading branch information
chenson42 committed Sep 30, 2007
1 parent 1187d33 commit 7fe36c4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
@@ -1,6 +1,5 @@
package org.jumpmind.symmetric.service.impl;

import java.io.IOException;
import java.net.ConnectException;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -44,10 +43,13 @@ public class BootstrapService extends AbstractService implements
private ITransportManager transportManager;

private IDataLoaderService dataLoaderService;

private RandomTimeSlot randomSleepTimeSlot;

private boolean autoConfigureDatabase = true;

public void init() {
this.randomSleepTimeSlot = new RandomTimeSlot(this.runtimeConfiguration, 60);
if (autoConfigureDatabase) {
logger.info("Initializing symmetric database.");
dbDialect.initConfigDb(tablePrefix);
Expand Down Expand Up @@ -168,12 +170,13 @@ public void register() {
// If we cannot contact the server to register, we simply must wait and try again.
while (!registered) {
try {
logger.info("Attempting to register.");
registered = dataLoaderService.loadData(transportManager
.getRegisterTransport(new Node(
this.runtimeConfiguration, dbDialect)));
} catch (ConnectException e) {
logger.warn("Connection failed while registering.");
} catch (IOException e) {
} catch (Exception e) {
logger.error(e, e);
}

Expand Down Expand Up @@ -205,10 +208,10 @@ public void heartbeat() {
}

private void sleepBeforeRegistrationRetry() {
RandomTimeSlot ts = new RandomTimeSlot(this.runtimeConfiguration, 60);

try {
long sleepTimeInMs = DateUtils.MILLIS_PER_SECOND
* ts.getRandomValueSeededByDomainId();
* randomSleepTimeSlot.getRandomValueSeededByDomainId();
logger.warn("Could not register. Sleeping for " + sleepTimeInMs
+ "ms before attempting again.");
Thread.sleep(sleepTimeInMs);
Expand Down
Expand Up @@ -21,6 +21,7 @@ public class PullService implements IPullService {
private IDataLoaderService dataLoaderService;

public void pullData() {
logger.info("Pull requested");
List<Node> nodes = nodeService.findNodesToPull();
for (Node node : nodes) {
try {
Expand All @@ -31,6 +32,7 @@ public void pullData() {
logger.error(e, e);
}
}
logger.info("Pull completed.");
}

public void setNodeService(INodeService clientService) {
Expand Down
Expand Up @@ -34,7 +34,7 @@ public void setExtractor(IDataExtractorService extractor) {
}

public void pushData() {
debug("Push requested.");
info("Push requested.");

List<Node> clients = nodeService.findNodesToPushTo();
if (clients != null) {
Expand All @@ -43,7 +43,7 @@ public void pushData() {
}
}

debug("Push request completed.");
info("Push request completed.");
}

class ParameterParser {
Expand Down Expand Up @@ -134,11 +134,11 @@ private void pushToClient(Node remote)
}
}

private void debug(String s)
private void info(String s)
{
if (logger.isDebugEnabled())
if (logger.isInfoEnabled())
{
logger.debug(s);
logger.info(s);
}
}

Expand Down
Expand Up @@ -69,6 +69,7 @@ protected HttpURLConnection sendMessage(URL url, String data)
conn.setRequestMethod("POST");
conn.setAllowUserInteraction(false);
conn.setDoOutput(true);
conn.setConnectTimeout(10000);
conn.setRequestProperty("Content-Length", Integer.toString(data
.length()));
writeMessage(conn.getOutputStream(), data);
Expand Down Expand Up @@ -110,8 +111,8 @@ public IIncomingTransport getRegisterTransport(Node node)
.getDatabaseVersion());
append(builder, WebConstants.SYMMETRIC_VERSION, node
.getSymmetricVersion());

HttpURLConnection conn = sendMessage(new URL(builder.toString()), "");
HttpURLConnection conn = (HttpURLConnection) new URL(builder.toString()).openConnection();
conn.setRequestMethod("GET");
return new HttpIncomingTransport(conn);
}

Expand Down
Expand Up @@ -14,24 +14,28 @@ public class RandomTimeSlot {

int maxValue = 1000;

public RandomTimeSlot() {
Random random;

public RandomTimeSlot() {
random = new Random();
}

public RandomTimeSlot(IRuntimeConfig config, int maxValue) {
this.runtimeConfiguration = config;
this.maxValue = maxValue;
random = new Random(runtimeConfiguration.getExternalId().hashCode());
}

public void setMaxValue(int maxValue) {
this.maxValue = maxValue;
}

public void setRuntimeConfiguration(IRuntimeConfig runtimeConfiguration) {
this.runtimeConfiguration = runtimeConfiguration;
random = new Random(runtimeConfiguration.getExternalId().hashCode());
}

public int getRandomValueSeededByDomainId() {
return new Random(runtimeConfiguration.getExternalId().hashCode())
.nextInt(maxValue);
return random.nextInt(maxValue);
}
}
Expand Up @@ -22,7 +22,7 @@ public class RegistrationServlet extends HttpServlet {
protected static final Log logger = LogFactory.getLog(RegistrationServlet.class);

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
IRegistrationService service = (IRegistrationService) ctx.getBean(Constants.REGISTRATION_SERVICE);
Expand Down

0 comments on commit 7fe36c4

Please sign in to comment.