Package io.objectbox.sync.server
Class SyncServerImpl
- java.lang.Object
-
- io.objectbox.sync.server.SyncServerImpl
-
- All Implemented Interfaces:
SyncServer,java.io.Closeable,java.lang.AutoCloseable
@Internal public final class SyncServerImpl extends java.lang.Object implements SyncServer
Internal sync server implementation. UseSyncServerto access functionality, this class may change without notice.
-
-
Field Summary
Fields Modifier and Type Field Description private longhandleprivate SyncChangeListenersyncChangeListenerProtects listener instance from garbage collection.private java.net.URIurl
-
Constructor Summary
Constructors Constructor Description SyncServerImpl(SyncServerBuilder builder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes and cleans up all resources used by this sync server.protected voidfinalize()Users of this class should explicitly callclose()instead to avoid expensive finalization.private longgetHandle()intgetPort()Returns the port this server listens on, or 0 if the server was not yet started.java.lang.StringgetStatsString()Gets some statistics from the sync server.java.lang.StringgetUrl()Returns the URL this server is listening on, including the bound port (seeSyncServer.getPort()).booleanisRunning()Returns if the server is up and running.private static longnativeCreateFromFlatOptions(long storeHandle, byte[] flatOptionsByteArray)Creates a native Sync server instance with FlatBufferSyncServerOptionsflatOptionsByteArray.private voidnativeDelete(long handle)private intnativeGetPort(long handle)private java.lang.StringnativeGetStatsString(long handle)private booleannativeIsRunning(long handle)private voidnativeSetSyncChangesListener(long handle, SyncChangeListener changesListener)private voidnativeStart(long handle)private voidnativeStop(long handle)voidsetSyncChangeListener(SyncChangeListener changesListener)Sets aSyncChangeListener.voidstart()Starts the server (e.g.voidstop()Stops the server.
-
-
-
Field Detail
-
url
private final java.net.URI url
-
handle
private volatile long handle
-
syncChangeListener
@Nullable private volatile SyncChangeListener syncChangeListener
Protects listener instance from garbage collection.
-
-
Constructor Detail
-
SyncServerImpl
SyncServerImpl(SyncServerBuilder builder)
-
-
Method Detail
-
getHandle
private long getHandle()
-
getUrl
public java.lang.String getUrl()
Description copied from interface:SyncServerReturns the URL this server is listening on, including the bound port (seeSyncServer.getPort()).- Specified by:
getUrlin interfaceSyncServer
-
getPort
public int getPort()
Description copied from interface:SyncServerReturns the port this server listens on, or 0 if the server was not yet started.This is especially useful if the port was assigned arbitrarily (a "0" port was used in the URL when building the server).
- Specified by:
getPortin interfaceSyncServer
-
isRunning
public boolean isRunning()
Description copied from interface:SyncServerReturns if the server is up and running.- Specified by:
isRunningin interfaceSyncServer
-
getStatsString
public java.lang.String getStatsString()
Description copied from interface:SyncServerGets some statistics from the sync server.- Specified by:
getStatsStringin interfaceSyncServer
-
setSyncChangeListener
public void setSyncChangeListener(@Nullable SyncChangeListener changesListener)Description copied from interface:SyncServerSets aSyncChangeListener. Replaces a previously set listener. Set tonullto remove the listener.- Specified by:
setSyncChangeListenerin interfaceSyncServer
-
start
public void start()
Description copied from interface:SyncServerStarts the server (e.g. bind to port) and gets everything operational.- Specified by:
startin interfaceSyncServer
-
stop
public void stop()
Description copied from interface:SyncServerStops the server.- Specified by:
stopin interfaceSyncServer
-
close
public void close()
Description copied from interface:SyncServerCloses and cleans up all resources used by this sync server. It can no longer be used afterwards, build a new sync server instead. Does nothing if this sync server has already been closed.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceSyncServer
-
finalize
protected void finalize() throws java.lang.ThrowableUsers of this class should explicitly callclose()instead to avoid expensive finalization.- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
nativeCreateFromFlatOptions
private static long nativeCreateFromFlatOptions(long storeHandle, byte[] flatOptionsByteArray)Creates a native Sync server instance with FlatBufferSyncServerOptionsflatOptionsByteArray.- Returns:
- The handle of the native server instance.
-
nativeDelete
private void nativeDelete(long handle)
-
nativeStart
private void nativeStart(long handle)
-
nativeStop
private void nativeStop(long handle)
-
nativeIsRunning
private boolean nativeIsRunning(long handle)
-
nativeGetPort
private int nativeGetPort(long handle)
-
nativeGetStatsString
private java.lang.String nativeGetStatsString(long handle)
-
nativeSetSyncChangesListener
private void nativeSetSyncChangesListener(long handle, @Nullable SyncChangeListener changesListener)
-
-