private void refreshSocket() { if (socket.isClosed()) { logHandler.info(address + "<-- Socket closed, reopening it"); try { socket = MulticastUtil.newMulticastSocket(address, logHandler); } catch (IOException exp) { logHandler.error("Cannot reopen socket. Exiting multicast listener thread ...",exp); throw new SocketVerificationFailedException(exp); } } }
/** * Log at debug level * * @param msg message to log */ public void debug(String msg) { logHandler.debug(msg); if (debugStore != null) { debugStore.log(msg); } }
/** {@inheritDoc} */ public void run() { setRunning(true); try { while (isRunning()) { refreshSocket(); logHandler.debug(address + "<-- Waiting"); DiscoveryIncomingMessage msg = receiveMessage(); if (shouldMessageBeProcessed(msg)) { handleQuery(msg); } } } catch (IllegalStateException e) { logHandler.error(address + "<-- Cannot reopen socket, exiting listener thread: " + e.getCause(),e.getCause()); } finally { if (socket != null) { socket.close(); } logHandler.debug(address + "<-- Stop listening"); } }
private void intError(String message,Throwable t) { logHandler.error(message, t); debugStore.log(message, t); } }
/** * Log at info level * * @param msg to log */ public void info(String msg) { logHandler.info(msg); if (debugStore != null) { debugStore.log(msg); } }
/** * Log at error level. * * @param message message to log * @param t ecxeption occured */ public void error(String message, Throwable t) { // Must not be final so that we can mock it in EasyMock for our tests logHandler.error(message, t); if (debugStore != null) { debugStore.log(message, t); } }
/** {@inheritDoc} */ public void run() { setRunning(true); try { while (isRunning()) { refreshSocket(); logHandler.debug(address + "<-- Waiting"); DiscoveryIncomingMessage msg = receiveMessage(); if (shouldMessageBeProcessed(msg)) { handleQuery(msg); } } } catch (IllegalStateException e) { logHandler.error(address + "<-- Cannot reopen socket, exiting listener thread: " + e.getCause(),e.getCause()); } finally { if (socket != null) { socket.close(); } logHandler.debug(address + "<-- Stop listening"); } }
private static int joinMcGroupsOnAllNetworkInterfaces(MulticastSocket pSocket, InetSocketAddress pSocketAddress, LogHandler pLogHandler) throws IOException { // V6: ffx8::/16 Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces(); int interfacesJoined = 0; while (nifs.hasMoreElements()) { NetworkInterface n = nifs.nextElement(); if (NetworkUtil.isMulticastSupported(n)) { try { pSocket.joinGroup(pSocketAddress, n); interfacesJoined++; } catch (IOException exp) { pLogHandler.info("Cannot join multicast group on NIF " + n.getDisplayName() + ": " + exp.getMessage()); } } } return interfacesJoined; }
public static Restrictor createRestrictor(Configuration pConfig, LogHandler logHandler) { Restrictor customRestrictor = createCustomRestrictor(pConfig); if (customRestrictor != null) { logHandler.info("Using restrictor " + customRestrictor.getClass().getCanonicalName()); return customRestrictor; } String location = NetworkUtil.replaceExpression(pConfig.get(ConfigKey.POLICY_LOCATION)); try { Restrictor ret = RestrictorFactory.lookupPolicyRestrictor(location); if (ret != null) { logHandler.info("Using policy access restrictor " + location); return ret; } else { logHandler.info("No access restrictor found, access to any MBean is allowed"); return new AllowAllRestrictor(); } } catch (IOException e) { logHandler.error("Error while accessing access restrictor at " + location + ". Denying all access to MBeans for security reasons. Exception: " + e, e); return new DenyAllRestrictor(); } }
private void addIncomingMessage(List<DiscoveryIncomingMessage> ret, DatagramPacket in) { try { DiscoveryIncomingMessage inMsg = new DiscoveryIncomingMessage(in); if (!inMsg.isQuery()) { ret.add(inMsg); } } catch (Exception exp) { logHandler.debug("Invalid incoming package from " + in.getAddress() + " --> " + exp + ". Ignoring"); } }
/** {@inheritDoc} */ public void run() { setRunning(true); try { while (isRunning()) { refreshSocket(); logHandler.debug(address + "<-- Waiting"); DiscoveryIncomingMessage msg = receiveMessage(); if (shouldMessageBeProcessed(msg)) { handleQuery(msg); } } } catch (IllegalStateException e) { logHandler.error(address + "<-- Cannot reopen socket, exiting listener thread: " + e.getCause(),e.getCause()); } finally { if (socket != null) { socket.close(); } logHandler.debug(address + "<-- Stop listening"); } }
/** * Start the responder (if not already started) */ public synchronized void start() throws IOException { if (listenerThreads.size() == 0) { List<InetAddress> addresses = hostAddress == null ? NetworkUtil.getMulticastAddresses() : Arrays.asList(hostAddress); if (addresses.size() == 0) { logHandler.info("No suitable address found for listening on multicast discovery requests"); return; } // We start a thread for every address found for (InetAddress addr : addresses) { try { MulticastSocketListenerThread thread = new MulticastSocketListenerThread("JolokiaDiscoveryListenerThread-" + addr.getHostAddress(), addr, detailsHolder, restrictor, logHandler); thread.start(); listenerThreads.add(thread); } catch (IOException exp) { logHandler.info("Couldn't start discovery thread for " + addr + ": " + exp); } } } }
log.info(oName + " is already registered. Adding it with " + alternativeOName + ", but you should revise your setup in " + "order to either use a qualifier or ensure, that only a single agent gets registered (otherwise history functionality might not work)"); Config config = new Config(pHistoryStore,pDebugStore,alternativeOName); mBeanServerHandler.registerMBean(config,alternativeOName); } catch (InstanceAlreadyExistsException e) { log.error("Cannot even register fallback MBean with name " + alternativeOName + ". Should never happen. Really.",e); mBeanServerHandler.registerMBean(legacyConfig,legacyOName); } catch (InstanceAlreadyExistsException exp) { log.info("Cannot register (legacy) MBean handler for config store with name " + legacyOName + " since it already exists. " + "This is the case if another agent has been already started within the same JVM. The registration is skipped."); } catch (InstanceAlreadyExistsException e) { log.info("Jolokia Discovery MBean registration is skipped because there is already one registered.");
private ServerHandle detectServers(List<ServerDetector> pDetectors, LogHandler pLogHandler) { // Now detect the server for (ServerDetector detector : pDetectors) { try { ServerHandle info = detector.detect(mBeanServerManager); if (info != null) { return info; } } catch (Exception exp) { // We are defensive here and wont stop the servlet because // there is a problem with the server detection. A error will be logged // nevertheless, though. pLogHandler.error("Error while using detector " + detector.getClass().getSimpleName() + ": " + exp,exp); } } return null; }
logHandler.debug(address + "--> Sending"); socket.send(outPacket); } catch (IOException exp) { DatagramPacket in = new DatagramPacket(buf, buf.length); socket.receive(in); logHandler.debug(address + "--> Received answer from " + in.getAddress()); addIncomingMessage(ret, in); } while (true); // Leave loop with a SocketTimeoutException in receive() } catch (SocketTimeoutException exp) { logHandler.debug(address + "--> Timeout");
private DiscoveryIncomingMessage receiveMessage() { byte buf[] = new byte[AbstractDiscoveryMessage.MAX_MSG_SIZE]; DatagramPacket packet = new DatagramPacket(buf, buf.length); try { packet.setLength(buf.length); socket.receive(packet); return new DiscoveryIncomingMessage(packet); } catch (IOException e) { if (!socket.isClosed()) { logHandler.info("Error while handling discovery request" + (packet.getAddress() != null ? " from " + packet.getAddress() : "") + ". Ignoring this request. --> " + e); } return null; } }
private void refreshSocket() { if (socket.isClosed()) { logHandler.info(address + "<-- Socket closed, reopening it"); try { socket = MulticastUtil.newMulticastSocket(address, logHandler); } catch (IOException exp) { logHandler.error("Cannot reopen socket. Exiting multicast listener thread ...",exp); throw new SocketVerificationFailedException(exp); } } }
/** * Get the optional options used for detectors. This should be a JSON string specifying all options * for all detectors. Keys are the name of the detector's product, the values are JSON object containing * specific parameters for this agent. E.g. * * <pre> * { * "glassfish" : { "bootAmx": true } * } * </pre> * * * @param pConfig the agent configuration * @param pLogHandler a log handler for putting out error messages * @return the detector specific configuration */ protected JSONObject getDetectorOptions(Configuration pConfig, LogHandler pLogHandler) { String options = pConfig.get(ConfigKey.DETECTOR_OPTIONS); try { if (options != null) { JSONObject opts = (JSONObject) new JSONParser().parse(options); return (JSONObject) opts.get(getProduct()); } return null; } catch (ParseException e) { pLogHandler.error("Could not parse detector options '" + options + "' as JSON object: " + e,e); } return null; } }
/** * Handle a GET request * * @param pUri URI leading to this request * @param pPathInfo path of the request * @param pParameterMap parameters of the GET request @return the response */ public JSONAware handleGetRequest(String pUri, String pPathInfo, Map<String, String[]> pParameterMap) { String pathInfo = extractPathInfo(pUri, pPathInfo); JmxRequest jmxReq = JmxRequestFactory.createGetRequest(pathInfo,getProcessingParameter(pParameterMap)); if (backendManager.isDebug()) { logHandler.debug("URI: " + pUri); logHandler.debug("Path-Info: " + pathInfo); logHandler.debug("Request: " + jmxReq.toString()); } return executeRequest(jmxReq); }