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
109 changed files
with
1,599 additions
and
1,469 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
33 changes: 33 additions & 0 deletions
33
server/core/src/main/java/org/infinispan/server/core/AbstractCacheIgnoreAware.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,33 @@ | ||
package org.infinispan.server.core; | ||
|
||
import org.infinispan.commons.util.concurrent.ConcurrentHashSet; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* @author gustavonalle | ||
* @author wburns | ||
* @since 9.0 | ||
*/ | ||
public class AbstractCacheIgnoreAware implements CacheIgnoreAware { | ||
|
||
private Set<String> ignoredCaches = new ConcurrentHashSet<>(); | ||
|
||
public void setIgnoredCaches(Set<String> cacheNames) { | ||
ignoredCaches.clear(); | ||
cacheNames.forEach(ignoredCaches::add); | ||
} | ||
|
||
public void unignore(String cacheName) { | ||
ignoredCaches.remove(cacheName); | ||
} | ||
|
||
public void ignoreCache(String cacheName) { | ||
ignoredCaches.add(cacheName); | ||
} | ||
|
||
public boolean isCacheIgnored(String cacheName) { | ||
return ignoredCaches.contains(cacheName); | ||
} | ||
|
||
} |
150 changes: 150 additions & 0 deletions
150
server/core/src/main/java/org/infinispan/server/core/AbstractProtocolServer.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,150 @@ | ||
package org.infinispan.server.core; | ||
|
||
import java.net.InetSocketAddress; | ||
import javax.management.DynamicMBean; | ||
import javax.management.MBeanServer; | ||
import javax.management.ObjectName; | ||
|
||
import org.infinispan.commons.CacheException; | ||
import org.infinispan.commons.logging.LogFactory; | ||
import org.infinispan.configuration.global.GlobalConfiguration; | ||
import org.infinispan.factories.components.ManageableComponentMetadata; | ||
import org.infinispan.jmx.JmxUtil; | ||
import org.infinispan.jmx.ResourceDMBean; | ||
import org.infinispan.manager.EmbeddedCacheManager; | ||
import org.infinispan.server.core.configuration.ProtocolServerConfiguration; | ||
import org.infinispan.server.core.logging.JavaLog; | ||
import org.infinispan.server.core.transport.NettyTransport; | ||
|
||
/** | ||
* A common protocol server dealing with common property parameter validation and assignment and transport lifecycle. | ||
* | ||
* @author Galder Zamarreño | ||
* @author wburns | ||
* @since 4.1 | ||
*/ | ||
public abstract class AbstractProtocolServer<A extends ProtocolServerConfiguration> extends AbstractCacheIgnoreAware | ||
implements ProtocolServer<A> { | ||
|
||
private final JavaLog log = LogFactory.getLog(getClass(), JavaLog.class); | ||
|
||
private final String protocolName; | ||
|
||
protected NettyTransport transport; | ||
protected EmbeddedCacheManager cacheManager; | ||
protected A configuration; | ||
private ObjectName transportObjName; | ||
private MBeanServer mbeanServer; | ||
|
||
protected AbstractProtocolServer(String protocolName) { | ||
this.protocolName = protocolName; | ||
} | ||
|
||
protected void startInternal(A configuration, EmbeddedCacheManager cacheManager) { | ||
this.configuration = configuration; | ||
this.cacheManager = cacheManager; | ||
|
||
if (log.isDebugEnabled()) { | ||
log.debugf("Starting server with configuration: %s", configuration); | ||
} | ||
|
||
// Start default cache | ||
startDefaultCache(); | ||
|
||
startTransport(); | ||
} | ||
|
||
@Override | ||
public final void start(A configuration, EmbeddedCacheManager cacheManager) { | ||
try { | ||
configuration.ignoredCaches().forEach(this::ignoreCache); | ||
startInternal(configuration, cacheManager); | ||
} catch (RuntimeException t) { | ||
stop(); | ||
throw t; | ||
} | ||
} | ||
|
||
protected void startTransport() { | ||
InetSocketAddress address = new InetSocketAddress(configuration.host(), configuration.port()); | ||
transport = new NettyTransport(address, configuration, getQualifiedName(), cacheManager); | ||
transport.initializeHandler(getInitializer()); | ||
|
||
// Register transport MBean regardless | ||
registerTransportMBean(); | ||
|
||
transport.start(); | ||
} | ||
|
||
protected void registerTransportMBean() { | ||
GlobalConfiguration globalCfg = cacheManager.getCacheManagerConfiguration(); | ||
mbeanServer = JmxUtil.lookupMBeanServer(globalCfg); | ||
String groupName = String.format("type=Server,name=%s", getQualifiedName()); | ||
String jmxDomain = JmxUtil.buildJmxDomain(globalCfg, mbeanServer, groupName); | ||
|
||
// Pick up metadata from the component metadata repository | ||
ManageableComponentMetadata meta = LifecycleCallbacks.componentMetadataRepo | ||
.findComponentMetadata(transport.getClass()).toManageableComponentMetadata(); | ||
try { | ||
// And use this metadata when registering the transport as a dynamic MBean | ||
DynamicMBean dynamicMBean = new ResourceDMBean(transport, meta); | ||
|
||
transportObjName = new ObjectName(String.format("%s:%s,component=%s", jmxDomain, groupName, | ||
meta.getJmxObjectName())); | ||
JmxUtil.registerMBean(dynamicMBean, transportObjName, mbeanServer); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
protected void unregisterTransportMBean() throws Exception { | ||
if (mbeanServer != null && transportObjName != null) { | ||
// Unregister mbean(s) | ||
JmxUtil.unregisterMBean(transportObjName, mbeanServer); | ||
} | ||
} | ||
|
||
protected String getQualifiedName() { | ||
return protocolName + (configuration.name().length() > 0 ? "-" : "") + configuration.name(); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
boolean isDebug = log.isDebugEnabled(); | ||
if (isDebug && configuration != null) | ||
log.debugf("Stopping server listening in %s:%d", configuration.host(), configuration.port()); | ||
|
||
if (transport != null) | ||
transport.stop(); | ||
|
||
try { | ||
unregisterTransportMBean(); | ||
} catch (Exception e) { | ||
throw new CacheException(e); | ||
} | ||
|
||
if (isDebug) | ||
log.debug("Server stopped"); | ||
} | ||
|
||
public EmbeddedCacheManager getCacheManager() { | ||
return cacheManager; | ||
} | ||
|
||
public String getHost() { | ||
return configuration.host(); | ||
} | ||
|
||
public int getPort() { | ||
return configuration.port(); | ||
} | ||
|
||
@Override | ||
public A getConfiguration() { | ||
return configuration; | ||
} | ||
|
||
protected void startDefaultCache() { | ||
cacheManager.getCache(configuration.defaultCacheName()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
server/core/src/main/java/org/infinispan/server/core/CacheIgnoreAware.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,21 @@ | ||
package org.infinispan.server.core; | ||
|
||
import org.infinispan.commons.util.concurrent.ConcurrentHashSet; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* @author gustavonalle | ||
* @author wburns | ||
* @since 9.0 | ||
*/ | ||
public interface CacheIgnoreAware { | ||
|
||
void setIgnoredCaches(Set<String> cacheNames); | ||
|
||
void unignore(String cacheName); | ||
|
||
void ignoreCache(String cacheName); | ||
|
||
boolean isCacheIgnored(String cacheName); | ||
} |
29 changes: 29 additions & 0 deletions
29
server/core/src/main/java/org/infinispan/server/core/ExternalizerIds.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,29 @@ | ||
package org.infinispan.server.core; | ||
|
||
/** | ||
* Externalizer ids used by Server module {@link org.infinispan.commons.marshall.AdvancedExternalizer} implementations. | ||
* TODO: update URL below | ||
* Information about the valid id range can be found <a href="http://community.jboss.org/docs/DOC-16198">here</a> | ||
* | ||
* @author Galder Zamarreño | ||
* @author wburns | ||
* @since 9.0 | ||
*/ | ||
public final class ExternalizerIds { | ||
private ExternalizerIds() { } | ||
|
||
public static final int SERVER_ENTRY_VERSION = 1100; | ||
public static final int MEMCACHED_METADATA = 1101; | ||
public static final int TOPOLOGY_ADDRESS = 1102; | ||
public static final int TOPOLOGY_VIEW = 1103; | ||
public static final int SERVER_ADDRESS = 1104; | ||
public static final int MIME_METADATA = 1105; | ||
public static final int BINARY_FILTER = 1106; | ||
public static final int BINARY_CONVERTER = 1107; | ||
public static final int KEY_VALUE_VERSION_CONVERTER = 1108; | ||
public static final int BINARY_FILTER_CONVERTER = 1109; | ||
public static final int KEY_VALUE_WITH_PREVIOUS_CONVERTER = 1110; | ||
public static final int ITERATION_FILTER = 1111; | ||
public static final int QUERY_ITERATION_FILTER = 1112; | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
server/core/src/main/java/org/infinispan/server/core/LifecycleCallbacks.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,30 @@ | ||
package org.infinispan.server.core; | ||
|
||
import org.infinispan.configuration.cache.Configuration; | ||
import org.infinispan.configuration.global.GlobalConfiguration; | ||
import org.infinispan.factories.components.ComponentMetadataRepo; | ||
import org.infinispan.factories.ComponentRegistry; | ||
import org.infinispan.factories.GlobalComponentRegistry; | ||
import org.infinispan.lifecycle.AbstractModuleLifecycle; | ||
|
||
/** | ||
* Module lifecycle callbacks implementation that enables module specific | ||
* {@link org.infinispan.commons.marshall.AdvancedExternalizer} implementations to be registered. | ||
* | ||
* @author Galder Zamarreño | ||
* @since 5.0 | ||
*/ | ||
public class LifecycleCallbacks extends AbstractModuleLifecycle { | ||
|
||
static ComponentMetadataRepo componentMetadataRepo; | ||
|
||
@Override | ||
public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalConfiguration) { | ||
componentMetadataRepo = gcr.getComponentMetadataRepo(); | ||
} | ||
|
||
@Override | ||
public void cacheStarting(ComponentRegistry cr, Configuration configuration, String cacheName) { | ||
configuration.storeAsBinary().enabled(false); | ||
} | ||
} |
30 changes: 16 additions & 14 deletions
30
...finispan/server/core/ProtocolServer.scala → ...nfinispan/server/core/ProtocolServer.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 |
---|---|---|
@@ -1,48 +1,50 @@ | ||
package org.infinispan.server.core | ||
package org.infinispan.server.core; | ||
|
||
import org.infinispan.manager.EmbeddedCacheManager | ||
import org.infinispan.server.core.configuration.ProtocolServerConfiguration | ||
import io.netty.channel.{Channel, ChannelInitializer, ChannelInboundHandler, ChannelOutboundHandler} | ||
import io.netty.channel.Channel; | ||
import io.netty.channel.ChannelInboundHandler; | ||
import io.netty.channel.ChannelInitializer; | ||
import io.netty.channel.ChannelOutboundHandler; | ||
import org.infinispan.manager.EmbeddedCacheManager; | ||
import org.infinispan.server.core.configuration.ProtocolServerConfiguration; | ||
|
||
/** | ||
* Represents a protocol compliant server. | ||
* | ||
* @author Galder Zamarreño | ||
* @since 4.1 | ||
* @author wburns | ||
* @since 9.0 | ||
*/ | ||
trait ProtocolServer extends CacheIgnoreAware { | ||
type SuitableConfiguration <: ProtocolServerConfiguration | ||
|
||
public interface ProtocolServer<C extends ProtocolServerConfiguration> extends CacheIgnoreAware { | ||
/** | ||
* Starts the server backed by the given cache manager and with the corresponding configuration. | ||
*/ | ||
def start(configuration: SuitableConfiguration, cacheManager: EmbeddedCacheManager) | ||
void start(C configuration, EmbeddedCacheManager cacheManager); | ||
|
||
/** | ||
* Stops the server | ||
*/ | ||
def stop | ||
void stop(); | ||
|
||
/** | ||
* Gets the encoder for this protocol server. The encoder is responsible for writing back common header responses | ||
* back to client. This method can return null if the server has no encoder. You can find an example of the server | ||
* that has no encoder in the Memcached server. | ||
*/ | ||
def getEncoder: ChannelOutboundHandler | ||
ChannelOutboundHandler getEncoder(); | ||
|
||
/** | ||
* Gets the decoder for this protocol server. The decoder is responsible for reading client requests. | ||
* This method cannot return null. | ||
*/ | ||
def getDecoder: ChannelInboundHandler | ||
ChannelInboundHandler getDecoder(); | ||
|
||
/** | ||
* Returns the configuration used to start this server | ||
*/ | ||
def getConfiguration: SuitableConfiguration | ||
C getConfiguration(); | ||
|
||
/** | ||
* Returns a pipeline factory | ||
*/ | ||
def getInitializer: ChannelInitializer[Channel] | ||
ChannelInitializer<Channel> getInitializer(); | ||
} |
14 changes: 14 additions & 0 deletions
14
server/core/src/main/java/org/infinispan/server/core/QueryFacade.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,14 @@ | ||
package org.infinispan.server.core; | ||
|
||
import org.infinispan.AdvancedCache; | ||
|
||
/** | ||
* Query facade | ||
* | ||
* @author Galder Zamarreño | ||
* @author wburns | ||
* @since 9.0 | ||
*/ | ||
public interface QueryFacade { | ||
byte[] query(AdvancedCache<byte[], byte[]> cache, byte[] query); | ||
} |
14 changes: 14 additions & 0 deletions
14
server/core/src/main/java/org/infinispan/server/core/ServerConstants.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,14 @@ | ||
package org.infinispan.server.core; | ||
|
||
/** | ||
* Server Constant values | ||
* | ||
* @author Tristan Tarrant | ||
* @author wburns | ||
* @since 9.0 | ||
*/ | ||
public final class ServerConstants { | ||
private ServerConstants() { } | ||
public static final int EXPIRATION_NONE = -1; | ||
public static final int EXPIRATION_DEFAULT = -2; | ||
} |
Oops, something went wrong.