-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
901 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/io/neonbee/internal/SharedDataAccessorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.neonbee.internal; | ||
|
||
import io.neonbee.NeonBee; | ||
import io.neonbee.config.NeonBeeConfig; | ||
import io.neonbee.internal.cluster.ClusterHelper; | ||
import io.neonbee.internal.hazelcast.ReplicatedDataAccessor; | ||
import io.vertx.core.Vertx; | ||
|
||
/** | ||
* Factory to create a {@link SharedDataAccessor} based on the configuration. | ||
*/ | ||
public class SharedDataAccessorFactory { | ||
private final NeonBee neonBee; | ||
|
||
/** | ||
* Create a new instance of {@link SharedDataAccessorFactory}. | ||
*/ | ||
public SharedDataAccessorFactory() { | ||
this.neonBee = NeonBee.get(); | ||
} | ||
|
||
/** | ||
* Create a new instance of {@link SharedDataAccessorFactory}. | ||
* | ||
* @param vertx the Vert.x instance | ||
*/ | ||
public SharedDataAccessorFactory(Vertx vertx) { | ||
this.neonBee = NeonBee.get(vertx); | ||
} | ||
|
||
/** | ||
* Create a new instance of {@link SharedDataAccessorFactory}. | ||
* | ||
* @param neonBee the NeonBee instance | ||
*/ | ||
public SharedDataAccessorFactory(NeonBee neonBee) { | ||
this.neonBee = neonBee; | ||
} | ||
|
||
private boolean useHazelcastReplicatedMaps() { | ||
NeonBeeConfig config = neonBee.getConfig(); | ||
return config.isUseReplicatedMaps() && ClusterHelper.getHazelcastClusterManager(neonBee.getVertx()).isPresent(); | ||
} | ||
|
||
/** | ||
* Get a {@link SharedDataAccessor} based on the configuration. | ||
* | ||
* @param accessClass the class to access the shared data | ||
* @return the shared data accessor | ||
*/ | ||
public SharedDataAccessor getSharedDataAccessor(Class<?> accessClass) { | ||
if (useHazelcastReplicatedMaps()) { | ||
return new ReplicatedDataAccessor(neonBee.getVertx(), accessClass); | ||
} else { | ||
return new SharedDataAccessor(neonBee.getVertx(), accessClass); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.