
blazingcache.server.HttpAPIImplementation Maven / Gradle / Ivy
/*
Licensed to Diennea S.r.l. under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. Diennea S.r.l. 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.
*/
package blazingcache.server;
import blazingcache.utils.RawString;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Implementation of the HTTP API, both for embedded and for standalone installation
*
* @author enrico.olivelli
*/
public class HttpAPIImplementation {
private static final Logger LOGGER = Logger.getLogger(HttpAPIImplementation.class.getName());
private static final ObjectMapper MAPPER = new ObjectMapper();
public static void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
CacheServer broker = (CacheServer) JVMServersRegistry.getDefaultServer();
String view = req.getParameter("view");
if (view == null) {
view = "status";
}
Map resultMap = new HashMap<>();
resultMap.put("ok", "true");
resultMap.put("version", CacheServer.VERSION());
if (broker == null) {
resultMap.put("ok", "false");
resultMap.put("status", "not_started");
} else {
resultMap.put("status", broker.isLeader() ? "LEADER" : "BACKUP");
}
switch (view) {
case "status": {
if (broker != null) {
CacheStatus status = broker.getCacheStatus();
BroadcastRequestStatusMonitor monitor = broker.getNetworkRequestsStatusMonitor();
resultMap.put("entryCount", status.getTotalEntryCount());
resultMap.put("clientsWithData", status.getAllClientsWithListener());
resultMap.put("connections", broker.getAcceptor().getConnections().size());
{
List broadcasts = monitor.getActualBroadcasts();
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy