use of com.zimbra.soap.admin.type.CacheEntryType in project zm-mailbox by Zimbra.
the class CacheExtension method register.
/*
* Register a cache type that can be flushed by the zmprov fc <cache> command.
*
* It should be invoked from the init() method of ZimbraExtension.
*/
public static synchronized void register(String cacheType, CacheExtension handler) {
if (mHandlers == null)
mHandlers = new HashMap<String, CacheExtension>();
else {
// make sure the cache is not already registered
CacheExtension obj = mHandlers.get(cacheType);
if (obj != null) {
ZimbraLog.account.warn("cache type " + cacheType + " is already registered, " + "registering of " + obj.getClass().getCanonicalName() + " is ignored");
return;
}
// make sure the cache type does not clash with one on of the internal cache type
CacheEntryType cet = null;
try {
cet = CacheEntryType.fromString(cacheType);
} catch (ServiceException e) {
// this is good
}
if (cet != null) {
ZimbraLog.account.warn("cache type " + cacheType + " is one of the internal cache type, " + "registering of " + obj.getClass().getCanonicalName() + " is ignored");
return;
}
}
mHandlers.put(cacheType, handler);
}
use of com.zimbra.soap.admin.type.CacheEntryType in project zm-mailbox by Zimbra.
the class TestImapViaImapDaemon method flushNonImapCacheTypes.
@Test
public void flushNonImapCacheTypes() throws Exception {
// Flushing these cache types won't do anything on the imapd server, but
// we want to make sure that this does not fail;
ImapConnection adminConn = getAdminConnection();
Set<CacheEntryType> allTypes = new HashSet<CacheEntryType>(Arrays.asList(CacheEntryType.values()));
Set<CacheEntryType> nonImapTypes = Sets.difference(allTypes, ImapHandler.IMAP_CACHE_TYPES);
for (CacheEntryType type : nonImapTypes) {
try {
adminConn.flushCache(CacheEntryType.license.toString());
} catch (CommandFailedException e) {
fail("should be able issue X-ZIMBRA-FLUSHCACHE command for cache type " + type.toString());
}
}
}
use of com.zimbra.soap.admin.type.CacheEntryType in project zm-mailbox by Zimbra.
the class FlushCache method doFlushCache.
public static void doFlushCache(AdminDocumentHandler handler, Map<String, Object> context, FlushCacheRequest req) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Server localServer = Provisioning.getInstance().getLocalServer();
handler.checkRight(zsc, context, localServer, Admin.R_flushCache);
CacheSelector cacheSelector = req.getCache();
boolean allServers = cacheSelector.isAllServers();
boolean imapServers = cacheSelector.isIncludeImapServers();
String[] types = cacheSelector.getTypes().split(",");
for (String type : types) {
CacheEntryType cacheType = null;
try {
cacheType = CacheEntryType.fromString(type);
doFlush(context, cacheType, cacheSelector);
} catch (ServiceException e) {
if (cacheType == null) {
// see if it is a registered extension
CacheExtension ce = CacheExtension.getHandler(type);
if (ce != null) {
ce.flushCache();
} else {
throw e;
}
} else {
throw e;
}
}
}
if (imapServers) {
flushCacheOnImapDaemons(req, zsc);
}
if (allServers) {
flushCacheOnAllServers(zsc, req);
}
}
use of com.zimbra.soap.admin.type.CacheEntryType in project zm-mailbox by Zimbra.
the class ImapHandler method doFLUSHCACHE.
private boolean doFLUSHCACHE(String tag, List<CacheEntryType> types, List<CacheEntrySelector> entries) throws IOException {
if (!checkState(tag, State.AUTHENTICATED)) {
return true;
} else if (!checkZimbraAdminAuth()) {
sendNO(tag, "must be authenticated as admin with X-ZIMBRA auth mechanism");
return true;
}
if (types.isEmpty()) {
// nothing to do here
sendOK(tag, "FLUSHCACHE completed");
return true;
}
AuthToken authToken = ((ZimbraAuthenticator) authenticator).getAuthToken();
try {
AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(authToken);
Server localServer = Provisioning.getInstance().getLocalServer();
aac.checkRight(localServer, Admin.R_flushCache);
} catch (ServiceException e) {
if (e.getCode().equalsIgnoreCase(ServiceException.PERM_DENIED)) {
ZimbraLog.imap.error("insufficient rights for flushing cache on IMAP server", e);
} else {
ZimbraLog.imap.error("error while checking rights for flushing cache on IMAP server", e);
}
return canContinue(e);
}
CacheSelector cacheSelector = new CacheSelector();
cacheSelector.setEntries(entries);
for (CacheEntryType type : types) {
try {
FlushCache.doFlush(null, type, cacheSelector);
} catch (ServiceException e) {
ZimbraLog.imap.error("error flushing cache on IMAP server", e);
return canContinue(e);
}
}
sendOK(tag, "FLUSHCACHE completed");
return true;
}
use of com.zimbra.soap.admin.type.CacheEntryType in project zm-mailbox by Zimbra.
the class ImapRequest method readCacheEntryTypes.
protected List<CacheEntryType> readCacheEntryTypes() throws IOException, ImapParseException {
if (peekChar() != '(') {
CacheEntryType type = readCacheEntryType();
if (type != null) {
return Arrays.asList(new CacheEntryType[] { type });
} else {
return Collections.emptyList();
}
}
skipChar('(');
List<CacheEntryType> cacheTypes = new ArrayList<CacheEntryType>();
if (peekChar() != ')') {
do {
CacheEntryType cacheType = readCacheEntryType();
if (cacheType != null) {
cacheTypes.add(cacheType);
}
if (peekChar() == ')') {
break;
}
skipSpace();
} while (true);
skipChar(')');
return cacheTypes;
} else {
throw new ImapParseException(tag, "must specify a cache type");
}
}
Aggregations