Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass instances of ClientConfig and Config to Hazelcast data store factory #8600

Merged
merged 3 commits into from
Sep 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class HazelcastSessionDataStoreFactory

private String addresses;

private ClientConfig clientConfig;

private Config serverConfig;

public boolean isUseQueries()
{
return useQueries;
Expand All @@ -84,7 +88,14 @@ public SessionDataStore getSessionDataStore(SessionHandler handler)
ClientConfig config;
if (StringUtil.isEmpty(configurationLocation))
{
config = new ClientConfig();
if (clientConfig == null)
{
config = new ClientConfig();
}
else
{
config = clientConfig;
}

if (addresses != null && !addresses.isEmpty())
{
Expand All @@ -98,7 +109,15 @@ public SessionDataStore getSessionDataStore(SessionHandler handler)
}
else
{
config = new XmlClientConfigBuilder(configurationLocation).build();
if (clientConfig == null)
{
config = new XmlClientConfigBuilder(configurationLocation).build();
}
else
{
LOG.warn("Both configurationLocation and clientConfig are set, using clientConfig");
config = clientConfig;
}
if (config.getSerializationConfig().getSerializerConfigs().stream().noneMatch(s ->
SessionData.class.getName().equals(s.getTypeClassName()) && s.getImplementation() instanceof SessionDataSerializer))
LOG.warn("Hazelcast xml config is missing org.eclipse.jetty.hazelcast.session.SessionDataSerializer - sessions may not serialize correctly");
Expand All @@ -114,7 +133,14 @@ public SessionDataStore getSessionDataStore(SessionHandler handler)
SerializerConfig sc = new SerializerConfig()
.setImplementation(new SessionDataSerializer())
.setTypeClass(SessionData.class);
config = new Config();
if (serverConfig == null)
{
config = new Config();
}
else
{
config = serverConfig;
}
config.getSerializationConfig().addSerializerConfig(sc);
// configure a default Map if null
if (mapConfig == null)
Expand All @@ -131,7 +157,15 @@ public SessionDataStore getSessionDataStore(SessionHandler handler)
}
else
{
config = new XmlConfigBuilder(configurationLocation).build();
if (serverConfig == null)
{
config = new XmlConfigBuilder(configurationLocation).build();
}
else
{
LOG.warn("Both configurationLocation and serverConfig are set, using serverConfig");
config = serverConfig;
}
if (config.getSerializationConfig().getSerializerConfigs().stream().noneMatch(s ->
SessionData.class.getName().equals(s.getTypeClassName()) && s.getImplementation() instanceof SessionDataSerializer))
LOG.warn("Hazelcast xml config is missing org.eclipse.jetty.hazelcast.session.SessionDataSerializer - sessions may not serialize correctly");
Expand Down Expand Up @@ -160,7 +194,7 @@ public boolean isOnlyClient()

/**
* @param onlyClient if <code>true</code> the session manager will only connect to an external Hazelcast instance
* and not use this JVM to start an Hazelcast instance
* and not use this JVM to start a Hazelcast instance
*/
public void setOnlyClient(boolean onlyClient)
{
Expand All @@ -172,6 +206,12 @@ public String getConfigurationLocation()
return configurationLocation;
}

/**
* @param configurationLocation the location of the XML Hazelcast configuration file to load.
* Depending on whether {@link #setOnlyClient(boolean)} is set to {@code true}
* or not, this will be used to configure either a Hazelcast client or a Hazelcast server.
* This parameter is mutually exclusive with {@link #setClientConfig(ClientConfig)} and {@link #setServerConfig(Config)}.
*/
public void setConfigurationLocation(String configurationLocation)
{
this.configurationLocation = configurationLocation;
Expand Down Expand Up @@ -226,4 +266,34 @@ public void setAddresses(String addresses)
{
this.addresses = addresses;
}

public ClientConfig getClientConfig()
{
return clientConfig;
}

/**
* @param clientConfig the client configuration to use to connect to Hazelcast.
* Only used if {@link #setOnlyClient(boolean)} is set to {@code true}.
* Overrides any configuration set via {@link #setConfigurationLocation(String)}
*/
public void setClientConfig(ClientConfig clientConfig)
{
this.clientConfig = clientConfig;
}

public Config getServerConfig()
{
return serverConfig;
}

/**
* @param serverConfig the server configuration to use to configure the embedded Hazelcast cluster.
* Only used if {@link #setOnlyClient(boolean)} is set to {@code false}.
* Overrides any configuration set via {@link #setConfigurationLocation(String)}
*/
public void setServerConfig(Config serverConfig)
{
this.serverConfig = serverConfig;
}
}