Skip to content

Commit

Permalink
Merge pull request #82 from scotte/fix-up-timestamp
Browse files Browse the repository at this point in the history
Fix service UP timestamp from getting reset
  • Loading branch information
NiteshKant committed Feb 7, 2014
2 parents ac5975c + f7ec3db commit 14dd108
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ public void register(InstanceInfo r, int leaseDuration,
}
Lease<InstanceInfo> lease = new Lease<InstanceInfo>(r,
leaseDuration);
if (existingLease != null) {
lease.setServiceUpTimestamp(existingLease.getServiceUpTimestamp());
}
gMap.put(r.getId(), lease);
synchronized (recentRegisteredQueue) {
recentRegisteredQueue.add(new Pair<Long, String>(Long
Expand Down
7 changes: 7 additions & 0 deletions eureka-core/src/main/java/com/netflix/eureka/lease/Lease.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public void serviceUp() {
}
}

/**
* Set the leases service UP timestamp
*/
public void setServiceUpTimestamp(long serviceUpTimestamp) {
this.serviceUpTimestamp = serviceUpTimestamp;
}

/**
* Checks if the lease of a given {@link InstanceInfo} has expired or not.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,32 @@ public class SampleEurekaService {
.getLogger(SampleEurekaService.class);

public void registerWithEureka() {
int sleepSeconds = 60; // Application initialization and running simulation time

// Register with Eureka
DiscoveryManager.getInstance().initComponent(
new MyDataCenterInstanceConfig(),
new DefaultEurekaClientConfig());

// A good practice is to register as STARTING and only change status to UP
// after the service is ready to receive traffic
System.out.println("Registering service to eureka with STARTING status");
ApplicationInfoManager.getInstance().setInstanceStatus(
InstanceStatus.STARTING);

System.out.println("Simulating service initialization by sleeping for " +
sleepSeconds + " seconds...");
try {
Thread.sleep(sleepSeconds * 1000);
} catch (InterruptedException e) {
// Nothing
}

// Now we change our status to UP
System.out.println("Done sleeping, now changing status to UP");
ApplicationInfoManager.getInstance().setInstanceStatus(
InstanceStatus.UP);

String vipAddress = configInstance.getStringProperty(
"eureka.vipAddress", "sampleservice.mydomain.net").get();
InstanceInfo nextServerInfo = null;
Expand Down Expand Up @@ -95,7 +115,18 @@ public void registerWithEureka() {
} catch (IOException e) {
e.printStackTrace();
}

System.out.println("Simulating service doing work by sleeping for " +
sleepSeconds + " seconds...");
try {
Thread.sleep(sleepSeconds * 1000);
} catch (InterruptedException e) {
// Nothing
}

System.out.println("Removing registration from eureka");
this.unRegisterWithEureka();

System.out.println("Shutting down server.Demo over.");

}
Expand All @@ -116,7 +147,7 @@ private void processRequest(final Socket s) {
PrintStream out = new PrintStream(s.getOutputStream());
System.out.println("Sending the response to the client...");

out.println("Reponse at " + new Date());
out.println("Response at " + new Date());

} catch (Throwable e) {
System.err.println("Error processing requests");
Expand Down

1 comment on commit 14dd108

@NiteshKant
Copy link
Contributor Author

@NiteshKant NiteshKant commented on 14dd108 Feb 11, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.