package org.apache.commons.jcs3.admin;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.text.DateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.apache.commons.jcs3.access.exception.CacheException;
import org.apache.commons.jcs3.auxiliary.remote.server.RemoteCacheServer;
import org.apache.commons.jcs3.auxiliary.remote.server.RemoteCacheServerFactory;
import org.apache.commons.jcs3.engine.CacheElementSerialized;
import org.apache.commons.jcs3.engine.behavior.ICacheElement;
import org.apache.commons.jcs3.engine.behavior.IElementAttributes;
import org.apache.commons.jcs3.engine.control.CompositeCache;
import org.apache.commons.jcs3.engine.control.CompositeCacheManager;
import org.apache.commons.jcs3.engine.memory.behavior.IMemoryCache;
/**
* A servlet which provides HTTP access to JCS. Allows a summary of regions to be viewed, and
* removeAll to be run on individual regions or all regions. Also provides the ability to remove
* items (any number of key arguments can be provided with action 'remove'). Should be initialized
* with a properties file that provides at least a classpath resource loader.
*/
public class JCSAdminBean implements JCSJMXBean
{
/** The cache manager. */
private final CompositeCacheManager cacheHub;
/**
* Default constructor
*/
public JCSAdminBean()
{
try
{
this.cacheHub = CompositeCacheManager.getInstance();
}
catch (final CacheException e)
{
throw new RuntimeException("Could not retrieve cache manager instance", e);
}
}
/**
* Parameterized constructor
*
* @param cacheHub the cache manager instance
*/
public JCSAdminBean(final CompositeCacheManager cacheHub)
{
this.cacheHub = cacheHub;
}
/**
* Builds up info about each element in a region.
*
* @param cacheName
* @return List of CacheElementInfo objects
* @throws IOException
*/
@Override
public List buildElementInfo( final String cacheName )
throws IOException
{
final CompositeCache