Issue #353 add logic to syncronize times for thin client data updates..
Change-Id: Id1f8e31bc95f0b0262821050be6660bfe66df9d1 Former-commit-id:5c303ed189
[formerly5c303ed189
[formerly f94248823eed52b2d9f8c56af3dc7607b323fc1e]] Former-commit-id:c61e40c426
Former-commit-id:84e6c9beb8
This commit is contained in:
parent
7d4367ee7a
commit
588432f980
6 changed files with 199 additions and 2 deletions
|
@ -35,11 +35,14 @@ import com.raytheon.uf.common.dataquery.requests.RequestConstraint.ConstraintTyp
|
|||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.common.time.msgs.GetServerTimeRequest;
|
||||
import com.raytheon.uf.common.time.msgs.GetServerTimeResponse;
|
||||
import com.raytheon.uf.viz.core.RecordFactory;
|
||||
import com.raytheon.uf.viz.core.alerts.AlertMessage;
|
||||
import com.raytheon.uf.viz.core.catalog.LayerProperty;
|
||||
import com.raytheon.uf.viz.core.datastructure.DataCubeContainer;
|
||||
import com.raytheon.uf.viz.core.exception.VizException;
|
||||
import com.raytheon.uf.viz.core.requests.ThriftClient;
|
||||
import com.raytheon.uf.viz.core.rsc.AbstractRequestableResourceData;
|
||||
import com.raytheon.uf.viz.core.rsc.AbstractResourceData;
|
||||
import com.raytheon.uf.viz.core.rsc.updater.DataUpdateTree;
|
||||
|
@ -70,6 +73,8 @@ public class ThinClientDataUpdateTree extends DataUpdateTree {
|
|||
|
||||
private long lastQuery = 0l;
|
||||
|
||||
private long serverTimeLag = Long.MIN_VALUE;
|
||||
|
||||
public static synchronized ThinClientDataUpdateTree getInstance() {
|
||||
DataUpdateTree instance = DataUpdateTree.getInstance();
|
||||
if (!(instance instanceof ThinClientDataUpdateTree)) {
|
||||
|
@ -86,8 +91,7 @@ public class ThinClientDataUpdateTree extends DataUpdateTree {
|
|||
|
||||
public Collection<AlertMessage> updateAllData() {
|
||||
String time = DATE_FORMAT.format(new Date(lastQuery));
|
||||
// put in a 1 second overlap in case insert time is a bit off.
|
||||
lastQuery = System.currentTimeMillis() - 1000;
|
||||
lastQuery = getServerTime();
|
||||
Set<AlertMessage> messages = new HashSet<AlertMessage>();
|
||||
for (DataPair pair : getDataPairs()) {
|
||||
AbstractResourceData resourceData = pair.data.getResourceData();
|
||||
|
@ -123,4 +127,30 @@ public class ThinClientDataUpdateTree extends DataUpdateTree {
|
|||
return messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the estimated current time on the server. This is useful if the
|
||||
* client and server have differences in their clocks. The time returned
|
||||
* from this method will always be slightly earlier than the actual server
|
||||
* time because of network latency. The earlier time guarantees that all
|
||||
* updates are retrieved but may result in updates being retrieved twice if
|
||||
* the data is inserted during this one second window
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private long getServerTime() {
|
||||
if (serverTimeLag == Long.MIN_VALUE) {
|
||||
try {
|
||||
GetServerTimeResponse response = (GetServerTimeResponse) ThriftClient
|
||||
.sendRequest(new GetServerTimeRequest());
|
||||
serverTimeLag = System.currentTimeMillis() - response.getTime();
|
||||
} catch (VizException e) {
|
||||
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
|
||||
e);
|
||||
return System.currentTimeMillis() - 1000l;
|
||||
}
|
||||
}
|
||||
// put in a 1 second overlap in case insert time is a bit off.
|
||||
return System.currentTimeMillis() - serverTimeLag - 1000l;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<bean id="utilitySrv" class="com.raytheon.edex.services.UtilitySrv"/>
|
||||
<bean id="privilegedUtilityHandler" class="com.raytheon.edex.services.PrivilegedUtilityHandler"/>
|
||||
<bean id="getServers" class="com.raytheon.edex.services.GetServersHandler"/>
|
||||
<bean id="getServerTime" class="com.raytheon.edex.services.GetServerTimeHandler"/>
|
||||
<bean id="streamSrv" class="com.raytheon.edex.services.LocalizationStreamHandler"/>
|
||||
|
||||
<bean factory-bean="handlerRegistry" factory-method="register">
|
||||
|
@ -23,6 +24,10 @@
|
|||
<constructor-arg value="com.raytheon.uf.common.localization.msgs.GetServersRequest"/>
|
||||
<constructor-arg ref="getServers"/>
|
||||
</bean>
|
||||
<bean factory-bean="handlerRegistry" factory-method="register">
|
||||
<constructor-arg value="com.raytheon.uf.common.time.msgs.GetServerTimeRequest"/>
|
||||
<constructor-arg ref="getServerTime"/>
|
||||
</bean>
|
||||
<bean factory-bean="handlerRegistry" factory-method="register">
|
||||
<constructor-arg value="com.raytheon.uf.common.localization.stream.LocalizationStreamPutRequest"/>
|
||||
<constructor-arg ref="streamSrv"/>
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.edex.services;
|
||||
|
||||
import com.raytheon.uf.common.serialization.comm.IRequestHandler;
|
||||
import com.raytheon.uf.common.time.msgs.GetServerTimeRequest;
|
||||
import com.raytheon.uf.common.time.msgs.GetServerTimeResponse;
|
||||
|
||||
/**
|
||||
* Return the current time on the server, beware network latency.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 29, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
public class GetServerTimeHandler implements
|
||||
IRequestHandler<GetServerTimeRequest> {
|
||||
|
||||
@Override
|
||||
public Object handleRequest(GetServerTimeRequest request) throws Exception {
|
||||
GetServerTimeResponse response = new GetServerTimeResponse();
|
||||
response.setTime(System.currentTimeMillis());
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
|
@ -9,6 +9,7 @@ Require-Bundle: net.sf.cglib
|
|||
Import-Package: com.raytheon.uf.common.serialization,
|
||||
com.raytheon.uf.common.serialization.adapters,
|
||||
com.raytheon.uf.common.serialization.annotations,
|
||||
com.raytheon.uf.common.serialization.comm,
|
||||
javax.persistence,
|
||||
org.apache.commons.beanutils,
|
||||
org.apache.commons.lang,
|
||||
|
@ -17,4 +18,5 @@ Import-Package: com.raytheon.uf.common.serialization,
|
|||
Eclipse-RegisterBuddy: com.raytheon.uf.common.serialization
|
||||
Export-Package: com.raytheon.uf.common.time,
|
||||
com.raytheon.uf.common.time.adapter,
|
||||
com.raytheon.uf.common.time.msgs,
|
||||
com.raytheon.uf.common.time.util
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.time.msgs;
|
||||
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.comm.IServerRequest;
|
||||
|
||||
/**
|
||||
* Request time from the server. This is not very reliable, since it does not
|
||||
* take into account the network delay for sending request/response. Use this
|
||||
* value with caution.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 29, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
@DynamicSerialize
|
||||
public class GetServerTimeRequest implements IServerRequest {
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.time.msgs;
|
||||
|
||||
import com.raytheon.uf.common.serialization.ISerializableObject;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
|
||||
import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
|
||||
|
||||
/**
|
||||
* This contains the time when the request was processed. This does not
|
||||
* represent the time the request was sent, or the time the response is received
|
||||
* by the client. Network latency may cause a significant difference between the
|
||||
* time in the response and the time the response is actually received.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Feb 29, 2012 bsteffen Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
@DynamicSerialize
|
||||
public class GetServerTimeResponse implements ISerializableObject {
|
||||
|
||||
/**
|
||||
* The time in milliseconds when this request was processed.
|
||||
*/
|
||||
@DynamicSerializeElement
|
||||
private Long time;
|
||||
|
||||
public Long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(Long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue