标签:emc insert down 插件 安装 注意 second des value
package com.defonds.wms.module.cache.service; public interface CacheService { void init(); // while server start up, do something void destory(); // while server shut down, do something void put(String key, Object object); // set new value to cache void remove(String key); // remove from cache Object get(String key); // get current value from cache boolean exist(String key); // check whether the key already exist in cache or not }
package com.defonds.wms.module.cache.service; import java.io.IOException; import java.net.InetSocketAddress; import net.spy.memcached.MemcachedClient; import com.wowza.wms.logging.WMSLogger; import com.wowza.wms.logging.WMSLoggerFactory; public class CacheServiceImpl implements CacheService { private static final WMSLogger logger = WMSLoggerFactory.getInstance().getLoggerObj(CacheServiceImpl.class.getName()); private MemcachedClient memcachedClient = null; private String memcachedIpAddress; // memcached server ip address private Integer memcachedServerPort; // memcached server port private Integer memcachedObjectExpiration; // objects set to memcached will be expired after 86400 (86400 = 60 * 60 * 24) seconds @Override public void init() { logger.debug("CacheServiceImpl--init--debug--memcachedIpAddress=" + this.memcachedIpAddress + ";memcachedServerPort=" + this.memcachedServerPort + ";memcachedObjectExpiration=" + this.memcachedObjectExpiration); try { logger.debug("CacheServiceImpl--init--debug--MemcachedClient will init now"); this.memcachedClient = new MemcachedClient(new InetSocketAddress(this.memcachedIpAddress, this.memcachedServerPort)); } catch (IOException e) { logger.error(e.getMessage(), e); } } @Override public void destory() { this.memcachedClient.shutdown(); } @Override public void put(String key, Object object) { try { this.memcachedClient.set(key, this.memcachedObjectExpiration, object); } catch (Exception e) { logger.error("CacheServiceImpl--put-- insert object into memcached failed!"); } } @Override public void remove(String key) { try { this.memcachedClient.delete(key); } catch (Exception e) { logger.error("CacheServiceImpl--remove-- delete object from memcached failed!"); } } @Override public Object get(String key) { Object object = null; try { object = this.memcachedClient.get(key); } catch (Exception e) { logger.error("CacheServiceImpl--get-- select object from memcached failed!"); } return object; } @Override public boolean exist(String key) { Object object = null; try { object = this.memcachedClient.get(key); } catch (Exception e) { logger.error("CacheServiceImpl--exist-- select object from memcached failed!"); } if (object == null) { return false; } else { return true; } } public void setMemcachedIpAddress(String memcachedIpAddress) { this.memcachedIpAddress = memcachedIpAddress; } public void setMemcachedServerPort(Integer memcachedServerPort) { this.memcachedServerPort = memcachedServerPort; } public void setMemcachedObjectExpiration(Integer memcachedObjectExpiration) { this.memcachedObjectExpiration = memcachedObjectExpiration; } }
memcached.ip.address=172.21.0.117 memcached.server.port=12111 #objects set to memcached will be expired after 86400 (86400 = 60 * 60 * 24) seconds memcached.object.expiration=86400
<!-- cache related --> <bean id="cacheService" class="com.defonds.wms.module.cache.service.CacheServiceImpl" init-method="init"> <property name="memcachedIpAddress" value="${memcached.ip.address}"></property> <property name="memcachedServerPort" value="${memcached.server.port}"></property> <property name="memcachedObjectExpiration" value="${memcached.object.expiration}"></property> </bean>
<ServerListener> <BaseClass>com.defonds.wms.module.server.DefondsWowzaServerListener</BaseClass> </ServerListener>
ApplicationContext appCtx = ApplicationContextUtils.getApplicationContext(); // test cache String testFlag = "now" + System.currentTimeMillis(); CacheService cacheService = (CacheService) appCtx.getBean("cacheService"); if (!cacheService.exist("somekey")) { cacheService.put("somekey", testFlag); } logger.debug("DefondsWowzaServerListener-onServerInit-memcached-somekey=" + cacheService.get("somekey"));
注意:关于 Wowza 插件的 log
Wowza 的 logging 实现採用的是 Apache 的 log4j logging 工具。log4j 的配置文件在 %wowza%/conf/log4j.properties,默认配置例如以下:
log4j.rootCategory=INFO, stdout, serverAccess, serverError
log4j.logger.com.defonds.wms.module.cache.service=DEBUG
WMSLogger logger = WMSLoggerFactory.getInstance().getLoggerObj(CacheServiceImpl.class.getName());
标签:emc insert down 插件 安装 注意 second des value
原文地址:http://www.cnblogs.com/jzdwajue/p/6724418.html