Package io.objectbox.sync.server
Class SyncServerImpl
java.lang.Object
io.objectbox.sync.server.SyncServerImpl
- All Implemented Interfaces:
SyncServer,Closeable,AutoCloseable
Internal sync server implementation. Use
SyncServer to access functionality,
this class may change without notice.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longprivate SyncChangeListenerProtects listener instance from garbage collection.private final URI -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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 longintgetPort()Returns the port this server listens on, or 0 if the server was not yet started.Gets some statistics from the sync server.getUrl()Returns the URL this server is listening on, including the bound port (seeSyncServer.getPort()).booleanReturns 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 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 Details
-
url
-
handle
private volatile long handle -
syncChangeListener
Protects listener instance from garbage collection.
-
-
Constructor Details
-
SyncServerImpl
SyncServerImpl(SyncServerBuilder builder)
-
-
Method Details
-
getHandle
private long getHandle() -
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
Description copied from interface:SyncServerGets some statistics from the sync server.- Specified by:
getStatsStringin interfaceSyncServer
-
setSyncChangeListener
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 interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceSyncServer
-
finalize
Users of this class should explicitly callclose()instead to avoid expensive finalization. -
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
-
nativeSetSyncChangesListener
private void nativeSetSyncChangesListener(long handle, @Nullable SyncChangeListener changesListener)
-