|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.unikassel.android.sdcframework.util.ObservableEventSourceImpl<TimeProviderEvent>
de.unikassel.android.sdcframework.util.TimeProvider
public final class TimeProvider
The internal time provider.
This class does encapsulate the frameworks time service. It does request an
actual time from an ntp server and stores the offset to correct the local
system time.
Nested Class Summary | |
---|---|
(package private) class |
TimeProvider.UpdateThread
Thread for asynchronous time updates |
Field Summary | |
---|---|
private static int |
CNT_MAX_SYNC_ATTEMPTS
The maximum count for asynchronous synchronization retires |
private static long |
CONNECTION_WAIT_TIME
Time to wait for network available |
private String[] |
INITIAL_PROVIDERS
The list with the providers to use |
private static TimeProvider |
instance
The singleton instance of the time provider |
private AtomicLong |
lastUpdateTs
The time stamp of the last sync update |
private AtomicLong |
offset
The internal time offset |
private List<String> |
providers
The list with time providers |
private AtomicBoolean |
synced
Flag if time is initialized |
private AtomicBoolean |
updateInProgress
Flag for update in progress |
private TimeProvider.UpdateThread |
updateThread
The instance of a running update thread |
Constructor Summary | |
---|---|
private |
TimeProvider()
Constructor |
Method Summary | |
---|---|
void |
asynchronousUpdateTime(Context context)
Method to update the internal time offset asynchronously |
TimeInformation |
getAccurateTimeInformation()
Getter for the accurate time stamp |
static Calendar |
getDayBegin(Calendar calValue)
Getter for the day day start time stamp of a given calendar date |
static TimeProvider |
getInstance()
Access to the global time provider instance |
long |
getOffset()
Getter for the offset |
List<String> |
getProviders()
Getter for the providers |
long |
getTimeStamp()
Getter for the time ( maybe out of sync ) |
static long |
getUTCDayTimeMillis()
Getter for the currents day time milliseconds |
static long |
getUTCDayTimeMillis(long ts)
Getter for the day time milliseconds for a given time stamp |
boolean |
isSynced()
Test method for time provider synchronization state |
static boolean |
isUTCDayChange(Long curUTCTime)
Test method for day changes |
protected void |
notifyOutOfSync(long ts)
Method to send an sync notification |
protected void |
notifySyncError(long ts)
Method to send an sync notification |
protected void |
notifyUpdated()
Method to send an sync notification |
protected void |
onObserverRegistration(EventObserver<? extends TimeProviderEvent> observer)
Handler for registered observers ( to be overloaded by extending classes if necessary ) |
private void |
setOffset(long offset)
Setter for the offset |
void |
stopAsynchronousUpdate(Context context)
Method to stop an update asynchronous update of the internal time offset |
private boolean |
syncTime(Context context)
Method to synchronize time with a NTP server |
static String |
toUTCDate(long timeStamp)
Does create a date string representation of the given time stamp |
static String |
toUTCString(long timeStamp)
Does create a long string representation of the given time stamp |
static String |
toUTCTime(long timeStamp)
Does create a time string representation of the given time stamp |
void |
updateProviders(List<String> newProviders)
Method to update the NTP provider list |
boolean |
updateTime(Context context)
Method to update the internal time offset |
Methods inherited from class de.unikassel.android.sdcframework.util.ObservableEventSourceImpl |
---|
getObservers, hasObservers, notify, onObserverUnregistration, registerEventObserver, removeAllObservers, unregisterEventObserver |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final String[] INITIAL_PROVIDERS
private static final int CNT_MAX_SYNC_ATTEMPTS
private static final long CONNECTION_WAIT_TIME
private AtomicLong offset
private AtomicLong lastUpdateTs
private final AtomicBoolean synced
private final AtomicBoolean updateInProgress
private static TimeProvider instance
private final List<String> providers
private TimeProvider.UpdateThread updateThread
Constructor Detail |
---|
private TimeProvider()
Method Detail |
---|
public static final TimeProvider getInstance()
public long getOffset()
private void setOffset(long offset)
offset
- the offset to setpublic final void updateProviders(List<String> newProviders)
newProviders
- the new provider listpublic List<String> getProviders()
public final long getTimeStamp()
public final TimeInformation getAccurateTimeInformation()
public final boolean updateTime(Context context)
context
- the context
public final void asynchronousUpdateTime(Context context)
context
- the contextpublic final void stopAsynchronousUpdate(Context context)
context
- the contextprivate final boolean syncTime(Context context)
public static final String toUTCString(long timeStamp)
timeStamp
- the milliseconds since 01.01.1970
public static final String toUTCTime(long timeStamp)
timeStamp
- the milliseconds since 01.01.1970
public static final String toUTCDate(long timeStamp)
timeStamp
- the milliseconds since 01.01.1970
protected final void onObserverRegistration(EventObserver<? extends TimeProviderEvent> observer)
ObservableEventSourceImpl
onObserverRegistration
in class ObservableEventSourceImpl<TimeProviderEvent>
observer
- the registered observerprotected void notifyUpdated()
protected void notifyOutOfSync(long ts)
ts
- the time stampprotected void notifySyncError(long ts)
ts
- the time stamppublic static final long getUTCDayTimeMillis()
public static final long getUTCDayTimeMillis(long ts)
ts
- the time stamp to get day time milliseconds for ( at 00:00:00.0
Midnight )
public static final Calendar getDayBegin(Calendar calValue)
calValue
- the calendar date time to get day start for ( same day at 00:00:00.0
Midnight )
public static final boolean isUTCDayChange(Long curUTCTime)
curUTCTime
- current time provider time
public boolean isSynced()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |