Skip to content

Commit

Permalink
more refactoring for a simple problem...
Browse files Browse the repository at this point in the history
  • Loading branch information
hg-ms committed Oct 1, 2024
1 parent 1470bcc commit 05e89bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public final class Default implements StorageLockFileManager

private final StorageLockFileSetup setup ;
private final StorageOperationController operationController;
private final StorageLockFileManagerThreadProvider threadProvider ;

// cached values
private transient StorageLockFile lockFile ;
Expand Down Expand Up @@ -134,8 +133,6 @@ public final class Default implements StorageLockFileManager
this.fileSystem = setup.lockFileProvider().fileSystem();
this.operationController = operationController;
this.vs = VarString.New() ;
this.threadProvider = threadProvider ;

// 2 timestamps with separators and an identifier. Should suffice.
this.wrappedByteBuffer = new ByteBuffer[1];
this.wrappedWrappedByteBuffer = X.ArrayView(this.wrappedByteBuffer);
Expand All @@ -144,7 +141,7 @@ public final class Default implements StorageLockFileManager
this.stringWriteBuffer = this.stringReadBuffer.clone();
this.allocateBuffer(this.stringReadBuffer.length);

this.executor = Executors.newSingleThreadScheduledExecutor();
this.executor = Executors.newSingleThreadScheduledExecutor(threadProvider);
}


Expand All @@ -171,8 +168,7 @@ private synchronized boolean isReady()
public StorageLockFileManager.Default start()
{
logger.info("Starting log file manager thread ");
Thread lockFileManagerThread = this.threadProvider.provideLockFileManagerThread(this);
this.executor.scheduleWithFixedDelay(lockFileManagerThread, 0, this.setup.updateInterval(), TimeUnit.MICROSECONDS);
this.executor.scheduleWithFixedDelay(this, 0, this.setup.updateInterval(), TimeUnit.MICROSECONDS);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.eclipse.store.storage.types;

import java.util.concurrent.ThreadFactory;

/*-
* #%L
* EclipseStore Storage
Expand All @@ -15,25 +17,20 @@
*/

@FunctionalInterface
public interface StorageLockFileManagerThreadProvider extends StorageThreadProviding
public interface StorageLockFileManagerThreadProvider extends StorageThreadProviding, ThreadFactory
{
/**
* Provides a newly created, yet un-started {@link Thread} instance wrapping the passed
* {@link StorageLockFileManager} instance.
* The thread will be used as an exclusive, permanent lock file validator and updater worker thread
* until the storage is shut down.
* Interfering with the thread from outside the storage compound has undefined and potentially
* unpredictable and erroneous behavior.
* @param lockFileManager the lock file manager to wrap
* @return a {@link Thread} instance to be used as a storage lock file managing worker thread.
* Provide a ThreadFactory for the StorageLockFileManager that uses the configured StorageThreadNameProvider
* to name threads.
*/
public default Thread provideLockFileManagerThread(final StorageLockFileManager lockFileManager)
@Override
public default Thread newThread(final Runnable runnable)
{
return this.provideLockFileManagerThread(lockFileManager, StorageThreadNameProvider.NoOp());
return this.provideLockFileManagerThread(runnable, StorageThreadNameProvider.NoOp());
}

public Thread provideLockFileManagerThread(
StorageLockFileManager lockFileManager ,
Runnable runnable ,
StorageThreadNameProvider threadNameProvider
);

Expand All @@ -53,14 +50,14 @@ public final class Default implements StorageLockFileManagerThreadProvider

@Override
public Thread provideLockFileManagerThread(
final StorageLockFileManager lockFileManager ,
final Runnable runnable ,
final StorageThreadNameProvider threadNameProvider
)
{
final String threadName = StorageLockFileManager.class.getSimpleName();

return new Thread(
lockFileManager,
runnable,
threadNameProvider.provideThreadName(this, threadName)
);
}
Expand Down

0 comments on commit 05e89bf

Please sign in to comment.