Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package de.hshannover.f4.trust.ifmapj21;
  
  /*
   * #%L
   * =====================================================
   *   _____                _     ____  _   _       _   _
   *  |_   _|_ __ _   _ ___| |_  / __ \| | | | ___ | | | |
   *    | | | '__| | | / __| __|/ / _` | |_| |/ __|| |_| |
   *    | | | |  | |_| \__ \ |_| | (_| |  _  |\__ \|  _  |
  *    |_| |_|   \__,_|___/\__|\ \__,_|_| |_||___/|_| |_|
  *                             \____/
  * 
  * =====================================================
  * 
  * Hochschule Hannover
  * (University of Applied Sciences and Arts, Hannover)
  * Faculty IV, Dept. of Computer Science
  * Ricklinger Stadtweg 118, 30459 Hannover, Germany
  * 
  * Email: trust@f4-i.fh-hannover.de
  * Website: http://trust.f4.hs-hannover.de
  * 
  * This file is part of IfmapJ, version 1.0.0, implemented by the Trust@HsH
  * research group at the Hochschule Hannover.
  * 
  * IfmapJ is a lightweight, platform-independent, easy-to-use IF-MAP client
  * library for Java. IF-MAP is an XML based protocol for sharing data across
  * arbitrary components, specified by the Trusted Computing Group. IfmapJ is
  * maintained by the Trust@HsH group at the Hochschule Hannover. IfmapJ
  * was developed within the ESUKOM research project.
  * %%
  * Copyright (C) 2010 - 2013 Trust@HsH
  * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * #L%
  */
 
 import java.util.List;
 
 
 
Helper class to synchronize time between MAPC and MAPS. This class implements the behaviour described in sec. 4.6.1 of published TNC IF-MAP Binding for SOAP specification 2.1 Rev 15.

Author(s):
jk
Since:
0.1.5
 
 public class ClockSkewDetector {

The SSRC to be used for time synchronization.
 
 	private final SSRC mSsrc;

Clock skew after the last call to publishTime(java.util.Calendar)
 
 	private Long mClockSkew;

Last successful clock skew adjustment
Device identifier used for time synchronization.
	private final Device mDev;

Private Metadata factory.
Factory method to get a ClockSkewDetector instance.

Parameters:
ssrc
dev
Returns:
	public static ClockSkewDetector newInstance(SSRC ssrcDevice dev) {
		return new ClockSkewDetector(ssrcdev);
	}

Private constructor.

Parameters:
ssrc
dev
	private ClockSkewDetector(SSRC ssrcDevice dev) {
		if (ssrc == null)
			throw new NullPointerException();
		if (dev == null)
			throw new NullPointerException();
		 = ssrc;
		 = dev;
	}

Send a client-time publish request with the current time followed by a search request in order to synchronize time to MAPS.
  This function implements the behaviour described in sec. 4.6.1
  of published TNC IF-MAP Binding for SOAP specification 2.1 Rev 15.
 

	}

Send a client-time publish request with the current time followed by a search request in order to synchronize time to MAPS.
  This function implements the behaviour described in sec. 4.6.1
  of published TNC IF-MAP Binding for SOAP specification 2.1 Rev 15.
 

	public long performClockSkewDetection(Calendar clientTime)
		publishTime(clientTime);
		Element time = searchTime();
		 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
		return ;
	}
Just wrap those crazy transformations into a helper...

Parameters:
time
Returns:
	private long calculateTimeDiff(Element time) {
		try {
			String ifmapTs = time.getAttribute("ifmap-timestamp");
			String curTs = time.getAttribute("current-timestamp");
			Calendar ifmapTime = DateHelpers.getTimeFromIso8601String(ifmapTs);
			Calendar curTime = DateHelpers.getTimeFromIso8601String(curTs);
			return ifmapTime.getTimeInMillis() - curTime.getTimeInMillis();
			IfmapJLog.warn("time sync: could not convert times: " + e.getMessage());
		}
		// Error case:
		return 0;
	}

Has time successfully been synchronized?
  Defaults to false until performClockSkewDetection
  without any parameter has been called. Gets set to true if
  a call to performClockSkewDetection was successful.
 

Returns:
true if clock has been detected
Since:
0.1.5
	public boolean getClockSynchronized() {
		return  != null;
	}

Detected clock skew between the client and MAPS

Returns:
the difference between both systems in milliseconds.
Since:
0.1.5
	public long getClockSkewMilliseconds() {
	}

Detected clock skew between the client and MAPS

Returns:
the difference between both systems in rounded seconds.
Since:
0.1.5
		return (int) Math.round(.doubleValue() / 1000);
	}

The corrected server time

Returns:
current UTC server time
Since:
0.1.5
		Calendar retCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
		return retCal;
	}

Last successful publish of client time

Returns:
date and time of last successful call to publishClientTime.
Since:
0.1.5
		return null;
	}

Attach the current client time to the {{@link mDev} identifier. if clientTime is null, the current time is used.

Parameters:
clientTime the supplied client time, use null for current time
Throws:
de.hshannover.f4.trust.ifmapj.exception.IfmapErrorResult
de.hshannover.f4.trust.ifmapj.exception.IfmapException
	private void publishTime(Calendar clientTime)
		String date = DateHelpers.getUtcTimeAsIso8601(clientTime);
		pu = Requests.createPublishUpdate(timeMd.);
		pr = Requests.createPublishReq(pu);
	}

Search for the self-published client time on mDev.

		List<Documentmlist;
		Node node;
			":client-time[@" + .
" = \"" + .getPublisherId() + "\"]";
		sr = Requests.createSearchReq(null, 0, nullnullresultFilter);
		res = .search(sr);
		items = res.getResultItems();
		if (items.size() > 1)
			IfmapJLog.warn("time sync: weird result item count: " + items.size());
		if (items.size() == 0)
			throw new IfmapException("time sync""No ResultItems for search!");
		ri = items.get(0);
		mlist = ri.getMetadata();
		if (mlist.size() > 1)
			IfmapJLog.warn("time sync: multiple client-time elements: " + mlist.size());
		if (mlist.size() == 0)
			throw new IfmapException("time sync""No client-time metadata!");
		// Take the last one in the list, hoping that it is the most current
		// one.
		Document clientTime = mlist.get(mlist.size() - 1);
		node = clientTime.getFirstChild();
		if (node.getNodeType() != .)
			throw new IfmapException("time sync""Metadata is not element");
		return (Element)node;
	}

Delete all current-time metadata objects attached to the {{@link mDev} identifier provided they have "our" publisher-id.

Parameters:
clientTime the supplied client time, use null for current time
Throws:
de.hshannover.f4.trust.ifmapj.exception.IfmapErrorResult
de.hshannover.f4.trust.ifmapj.exception.IfmapException
	private void deleteTimes()
			":client-time[@" + .
" = \"" + .getPublisherId() + "\"]";
		PublishDelete pd = Requests.createPublishDelete(filter);
		PublishRequest pr = Requests.createPublishReq(pd);
	}
New to GrepCode? Check out our FAQ X