Package mx4j.log

Examples of mx4j.log.Logger


      }


      public void run()
      {
         Logger log = getLogger();
         HttpInputStream httpIn = null;
         HttpOutputStream httpOut = null;
         try
         {
            // get input streams
            InputStream in = client.getInputStream();
            httpIn = new HttpInputStream(in);
            httpIn.readRequest();

            // Find a suitable command processor
            String path = httpIn.getPath();
            String queryString = httpIn.getQueryString();
            if (log.isEnabledFor(Logger.DEBUG)) log.debug("Request " + path + ((queryString == null) ? "" : ("?" + queryString)));
            String postPath = preProcess(path);
            if (!postPath.equals(path))
            {
               if (log.isEnabledFor(Logger.DEBUG)) log.debug("Processor replaced path " + path + " with the path " + postPath);
               path = postPath;
            }
            OutputStream out = client.getOutputStream();
            httpOut = new HttpOutputStream(out, httpIn);
            if (!handleAuthentication(httpIn, httpOut))
            {
               return;
            }
            HttpCommandProcessor processor = getProcessor(path.substring(1, path.length()));
            if (processor == null)
            {
               if (log.isEnabledFor(Logger.DEBUG)) log.debug("No suitable command processor found, requesting from processor path " + path);
               findUnknownElement(path, httpOut, httpIn);
            }
            else
            {
               Document document = processor.executeRequest(httpIn);
               postProcess(httpOut, httpIn, document);
            }
         }
         catch (Exception ex)
         {
            log.warn("Exception during http request", ex);
            if (httpOut != null)
            {
               try
               {
                  postProcess(httpOut, httpIn, ex);
               }
               catch (IOException e)
               {
                  log.warn("IOException during http request", e);
               }
               catch (JMException e)
               {
                  log.warn("JMException during http request", e);
               }
               catch (RuntimeException rte)
               {
                  log.error("RuntimeException during http request", rte);
               }
               catch (Error er)
               {
                  log.error("Error during http request ", er);
               }
               catch (Throwable t)
               {
                  log.fatal("Throwable during http request ", t);
               }
            }
         }
         catch (Error ex)
         {
            log.error("Error during http request ", ex);
         }
         finally
         {
            try
            {
               if (httpOut != null)
               {
                  httpOut.flush();
               }
            }
            catch (IOException e)
            {
               log.warn("Exception during request processing", e);
            }
            finally
            {
               try
               {
// always close the socket
                  client.close();
               }
               catch (IOException e)
               {
                  log.info("Exception during socket close", e);
               }
            }
         }
      }
View Full Code Here


      return Log.getLogger(getClass().getName());
   }

   public void start()
   {
      Logger logger = getLogger();
      if (!isActive)
      {
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Starting statistics recorder " + this);
         this.isActive = true;
         recordingStart = new Date();
         entries.clear();
         minimumValue = maximumValue = averageValue = 0;
         count = 0;
         isDouble = false;
         try
         {
            doStart();
         }
         catch (Exception e)
         {
            logger.error("Exception while starting recorder " + this, e);
         }
      }
   }
View Full Code Here

      }
   }

   public void stop()
   {
      Logger logger = getLogger();
      if (isActive)
      {
         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Starting statistics recorder " + this);
         this.isActive = false;
         try
         {
            doStop();
         }
         catch (Exception e)
         {
            logger.error("Exception starting recorder " + this, e);
         }
      }
   }
View Full Code Here

         HttpCommandProcessor processor = (HttpCommandProcessor)Class.forName(processorClass).newInstance();
         addCommandProcessor(path, processor);
      }
      catch (Exception e)
      {
         Logger log = getLogger();
         log.error("Exception creating Command Processor of class " + processorClass, e);
      }
   }
View Full Code Here

    * Starts the server
    */
   public void start()
           throws IOException
   {
      final Logger logger = getLogger();

      if (server != null)
      {
         serverSocket = createServerSocket();

         if (serverSocket == null)
         {
            logger.error("Server socket is null");
            return;
         }

         if (processorClass != null && processorName != null)
         {
            if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Building processor class of type " + processorClass + " and name " + processorName);
            try
            {
               server.createMBean(processorClass, processorName, null);
            }
            catch (JMException e)
            {
               logger.error("Exception creating processor class", e);
            }
         }

         Iterator i = commands.values().iterator();
         while (i.hasNext())
         {
            HttpCommandProcessor processor = (HttpCommandProcessor)i.next();
            processor.setMBeanServer(server);
            processor.setDocumentBuilder(builder);
         }

         if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("HttpAdaptor server listening on port " + port);
         alive = true;
         Thread serverThread = new Thread(new Runnable()
         {
            public void run()
            {
               if (logger.isEnabledFor(Logger.INFO)) logger.info("HttpAdaptor version " + VERSION + " started on port " + port);

               startDate = new Date();
               requestsCount = 0;

               while (alive)
               {
                  try
                  {
                     Socket client = null;
                     client = serverSocket.accept();
                     if (!alive)
                     {
                        client.close();
                        break;
                     }
                     requestsCount++;
                     new HttpClient(client).start();
                  }
                  catch (InterruptedIOException e)
                  {
                     continue;
                  }
                  catch (IOException e)
                  {
                     continue;
                  }
                  catch (Exception e)
                  {
                     logger.warn("Exception during request processing", e);
                     continue;
                  }
                  catch (Error e)
                  {
                     logger.error("Error during request processing", e);
                     continue;
                  }
               }
               try
               {
                  serverSocket.close();
               }
               catch (IOException e)
               {
                  logger.warn("Exception closing the server", e);
               }
               serverSocket = null;
               alive = false;
               if (logger.isEnabledFor(Logger.INFO)) logger.info("HttpAdaptor version " + VERSION + " stopped on port " + port);
            }
         });
         serverThread.start();
      }
      else
      {
         if (logger.isEnabledFor(Logger.INFO)) logger.info("Start failed, no server target server has been set");
      }
   }
View Full Code Here

         return children;
      }

      public void setAttributes(NamedNodeMap attributes) throws ConfigurationException
      {
         Logger logger = getLogger();
         for (int i = 0; i < attributes.getLength(); ++i)
         {
            org.w3c.dom.Node attribute = attributes.item(i);
            String name = attribute.getNodeName();
            String value = attribute.getNodeValue();
            String setterName = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
            try
            {
               if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Calling " + setterName + " with " + value + " on " + this);
               Method setter = getClass().getMethod(setterName, new Class[]{String.class});
               setter.invoke(this, new java.lang.Object[]{value});
            }
            catch (InvocationTargetException x)
            {
View Full Code Here

         }
      }

      private java.lang.Object startup(MBeanServer server) throws ConfigurationException
      {
         Logger logger = getLogger();
         List children = getChildren();
         if (children != null)
         {
            for (int i = 0; i < children.size(); ++i)
            {
               Node child = (Node)children.get(i);
               if (child instanceof DefaultConfigurationBuilder.Startup) child.configure(server);
            }
         }
         if (port > 0)
         {
            thread = new Thread(this, "Configuration Shutdown");
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Starting " + thread.getName() + " Thread on port " + port);
            thread.start();
         }
         return null;
      }
View Full Code Here

         return null;
      }

      private java.lang.Object shutdown(MBeanServer server) throws ConfigurationException
      {
         Logger logger = getLogger();
         List children = getChildren();
         if (children != null)
         {
            for (int i = 0; i < children.size(); ++i)
            {
               Node child = (Node)children.get(i);
               if (child instanceof DefaultConfigurationBuilder.Shutdown) child.configure(server);
            }
         }
         if (port > 0)
         {
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Stopping " + thread.getName() + " Thread on port " + port);
            thread.interrupt();
         }
         return null;
      }
View Full Code Here

         return null;
      }

      public void run()
      {
         Logger logger = getLogger();
         ServerSocket server = null;
         try
         {
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Started " + thread.getName() + " Thread on port " + port);

            server = new ServerSocket(port, 50, InetAddress.getByName(null));
            server.setSoTimeout(1000);

            byte[] buffer = new byte[64];
            StringBuffer command = new StringBuffer();
            while (!thread.isInterrupted())
            {
               Socket client = null;
               try
               {
                  client = server.accept();
               }
               catch (InterruptedIOException x)
               {
                  continue;
               }
               if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Client connected " + client);
               InputStream is = new BufferedInputStream(client.getInputStream());

               command.setLength(0);
               int read = -1;
               while ((read = is.read(buffer)) >= 0) command.append(new String(buffer, 0, read));

               String cmd = command.toString();
               if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Got command '" + cmd + "'");

               if (SHUTDOWN_COMMAND.equals(cmd))
               {
                  try
                  {
                     configure(null);
                     break;
                  }
                  catch (ConfigurationException x)
                  {
                     if (logger.isEnabledFor(Logger.WARN)) logger.warn("Bad configuration for shutdown", x);
                  }
               }
            }
         }
         catch (Exception x)
         {
            if (logger.isEnabledFor(Logger.INFO)) logger.info("Caught Exception in " + thread.getName() + " Thread, exiting", x);
         }
         finally
         {
            if (logger.isEnabledFor(Logger.TRACE)) logger.trace("Stopped " + thread.getName() + " Thread on port " + port);
            try
            {
               if (server != null) server.close();
            }
            catch (IOException x)
View Full Code Here

      return stopped;
   }

   public synchronized void start() throws IOException, IllegalStateException
   {
      Logger logger = getLogger();

      if (isActive())
      {
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("This JMXConnectorServer has already been started");
         return;
      }
      if (isStopped())
      {
         if (logger.isEnabledFor(Logger.TRACE)) logger.trace("This JMXConnectorServer has already been stopped");
         throw new IOException("This RMIConnectorServer has already been stopped");
      }

      doStart();

      active = true;

      if (logger.isEnabledFor(Logger.INFO)) logger.info("JMXConnectorServer started at: " + getAddress());
   }
View Full Code Here

TOP

Related Classes of mx4j.log.Logger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.