Allow a list of memcached servers to be configured for session caching.
This commit is contained in:
parent
e3936d2046
commit
3f10652361
|
@ -3,8 +3,23 @@
|
|||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
<New id="sessionDataMapFactory" class="org.eclipse.jetty.memcached.session.MemcachedSessionDataMapFactory">
|
||||
<Set name="host"><Property name="jetty.session.memcache.host" default="localhost"/></Set>
|
||||
<Set name="port"><Property name="jetty.session.memcache.port" default="11211"/></Set>
|
||||
<Set name="expirySec"><Property name="etty.session.memcache.expirySec" default="0"/></Set>
|
||||
<Set name="addresses">
|
||||
<Array type="java.net.InetSocketAddress">
|
||||
<Item>
|
||||
<New class="java.net.InetSocketAddress">
|
||||
<Arg><Property name="jetty.session.memcache.host" default="localhost"/></Arg>
|
||||
<Arg type="int"><Property name="jetty.session.memcache.port" default="11211"/></Arg>
|
||||
</New>
|
||||
</Item>
|
||||
<!-- Add more here -->
|
||||
</Array>
|
||||
</Set>
|
||||
<!-- Optionally set the weight of each server in the list -->
|
||||
<Set name="weights">
|
||||
<Array type="int">
|
||||
<Item type="int">100</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
<Set name="expirySec"><Property name="jetty.session.memcache.expirySec" default="0"/></Set>
|
||||
</New>
|
||||
</Configure>
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
package org.eclipse.jetty.memcached.session;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.server.session.SessionContext;
|
||||
import org.eclipse.jetty.server.session.SessionData;
|
||||
|
@ -58,6 +60,16 @@ public class MemcachedSessionDataMap extends AbstractLifeCycle implements Sessio
|
|||
}
|
||||
|
||||
|
||||
public MemcachedSessionDataMap (List<InetSocketAddress> addresses)
|
||||
{
|
||||
_builder = new XMemcachedClientBuilder(addresses);
|
||||
}
|
||||
|
||||
|
||||
public MemcachedSessionDataMap (List<InetSocketAddress> addresses, int[] weights)
|
||||
{
|
||||
_builder = new XMemcachedClientBuilder(addresses, weights);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the builder
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
package org.eclipse.jetty.memcached.session;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.server.session.SessionDataMap;
|
||||
import org.eclipse.jetty.server.session.SessionDataMapFactory;
|
||||
|
||||
|
@ -28,44 +32,40 @@ import org.eclipse.jetty.server.session.SessionDataMapFactory;
|
|||
*/
|
||||
public class MemcachedSessionDataMapFactory implements SessionDataMapFactory
|
||||
{
|
||||
protected String _host = "localhost";
|
||||
protected String _port = "11211";
|
||||
protected int _expiry;
|
||||
protected int[] _weights;
|
||||
protected List<InetSocketAddress> _addresses;
|
||||
|
||||
/**
|
||||
* @param addresses host and port address of memcached servers
|
||||
*/
|
||||
public void setAddresses(InetSocketAddress... addresses)
|
||||
{
|
||||
if (addresses == null)
|
||||
_addresses = null;
|
||||
_addresses = new ArrayList<>();
|
||||
for (InetSocketAddress a:addresses)
|
||||
_addresses.add(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getHost()
|
||||
/**
|
||||
* @param weights the relative weight to give each server in the list of addresses
|
||||
*/
|
||||
public void setWeights(int[] weights)
|
||||
{
|
||||
return _host;
|
||||
_weights = weights;
|
||||
}
|
||||
|
||||
|
||||
public void setHost(String host)
|
||||
{
|
||||
_host = host;
|
||||
}
|
||||
|
||||
|
||||
public String getPort()
|
||||
{
|
||||
return _port;
|
||||
}
|
||||
|
||||
|
||||
public void setPort(String port)
|
||||
{
|
||||
_port = port;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getExpirySec()
|
||||
{
|
||||
return _expiry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param expiry time in secs that memcached item remains valid
|
||||
*/
|
||||
public void setExpirySec(int expiry)
|
||||
{
|
||||
_expiry = expiry;
|
||||
|
@ -77,7 +77,7 @@ public class MemcachedSessionDataMapFactory implements SessionDataMapFactory
|
|||
@Override
|
||||
public SessionDataMap getSessionDataMap()
|
||||
{
|
||||
MemcachedSessionDataMap m = new MemcachedSessionDataMap(_host, _port);
|
||||
MemcachedSessionDataMap m = new MemcachedSessionDataMap(_addresses, _weights);
|
||||
m.setExpirySec(_expiry);
|
||||
return m;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue