下午好朋友。
我需要有关gemfire 8.2.11版的帮助。
我的班级配置
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Configuration;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientCacheFactory;
import com.gemstone.gemfire.pdx.ReflectionBasedAutoSerializer;
@Configuration
@ComponentScans({
@ComponentScan("br.com.teste.gemfire.ttl.util"),
@ComponentScan("br.com.teste.gemfire.ttl.writer")})
public class GemfireConfiguration {
private ClientCacheFactory clientCacheFactory() {
return new ClientCacheFactory()
.set("name", GemfireConfiguration.class.getSimpleName())
.set("mcast-port", "0")
.set("log-level", "config")
.set("jmx-manager", "false")
.set("jmx-manager-port", "1099")
.set("jmx-manager-start", "false")
.set("security-log-level","all")
.setPdxReadSerialized(false)
.setPdxSerializer(new ReflectionBasedAutoSerializer("br.com.teste.ExpirationObject"))
.setPdxIgnoreUnreadFields(true)
.setPdxPersistent(true)
.addPoolLocator("hostLocator1",10000)
.addPoolLocator("hostLocator2",10000);
}
@Bean(destroyMethod="close")
public ClientCache clientCache() {
return clientCacheFactory().create();
}
}
我的作家类
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.gemfire.ExpirationActionType;
import org.springframework.data.gemfire.support.GemfireCacheManager;
import org.springframework.stereotype.Component;
import com.gemstone.gemfire.cache.AttributesMutator;
import com.gemstone.gemfire.cache.ExpirationAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.client.ClientRegionFactory;
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
import com.gemstone.gemfire.cache.query.FunctionDomainException;
import com.gemstone.gemfire.cache.query.NameResolutionException;
import com.gemstone.gemfire.cache.query.Query;
import com.gemstone.gemfire.cache.query.QueryInvocationTargetException;
import com.gemstone.gemfire.cache.query.SelectResults;
import com.gemstone.gemfire.cache.query.TypeMismatchException;
import br.com.teste.gemfire.ttl.util.ObjectCustomExpiry;
@Component
public class WriterInRegion {
@Autowired
private ClientCache clientCache ;
public void writer() {
ClientRegionFactory<Long, ExpirationObject> clientRegionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU);
clientRegionFactory.setStatisticsEnabled(true);
Region<Long, ExpirationObject> region = clientRegionFactory.create("ExpirationObject");
AttributesMutator<Long, ExpirationObject> attributesMutator = region.getAttributesMutator();
attributesMutator.setCustomEntryTimeToLive(new ObjectCustomExpiry());
ExpirationObject expirationObject= new ExpirationObject();
expirationObject.setId(11111111111L);
expirationObject.setValue(50);
expirationObject.setTimeToLive(15);
clientCache.getCacheTransactionManager().begin();
region.create(expirationObject.getId(), expirationObject);
clientCache.getCacheTransactionManager().commit();
region.localClear();
region.localDestroyRegion();
}
}
我的CustomTTL类
import java.util.Properties;
import org.springframework.data.gemfire.ExpirationActionType;
import com.gemstone.gemfire.cache.CustomExpiry;
import com.gemstone.gemfire.cache.Declarable;
import com.gemstone.gemfire.cache.ExpirationAttributes;
import com.gemstone.gemfire.cache.Region.Entry;
public class ObjectCustomExpiry implements CustomExpiry<Long,ExpirationObject>,Declarable {
@Override
public void close() {
}
@Override
public ExpirationAttributes getExpiry(Entry<Long,ExpirationObject> entry) {
try {
System.out.println("Create expiration ttl");
ExpirationObject expirationObject = entry.getValue();
return new ExpirationAttributes(expirationObject.getTimeToLive(), ExpirationActionType.INVALIDATE.getExpirationAction());
} catch (Exception e) {
}
return new ExpirationAttributes(10, ExpirationActionType.INVALIDATE.getExpirationAction());
}
@Override
public void init(Properties props) {
}
}
Gemfire服务器结果
Cluster gfsh>query --query="select * from /ExpirationObject" Result : true startCount : 0 endCount : 20 Rows : 1 Query Trace : Query Executed in 2.733096 ms; indexesUsed(0) Id | value | timeToLive -------------| ----- | ---------- 11111111111L | 50 | 15 NEXT_STEP_NAME : END
我的问题是15秒钟后该条目在定位器和服务器中没有过期。
你能帮我吗?