/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.jboss.msc.bench;

import org.jboss.msc.service.Service;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;

/**
 * A test service which performs a long-ish calculation with embedded sleeps.
 *
 * @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
 */
public final class NonBusyService implements Service<NonBusyService> {
    private static final int N = 1000000;
    double sum = 0;

    public void start(final StartContext context) throws StartException {
        // calculate pi, slowly (and inaccurately).  Takes around 232 ms on my 1.86GHz system (with embedded sleeps).
        double sum = 0.0;
        double term;
        double sign = 1.0;
        for (int k = 0; k < N; k++) {
           term = 1.0/(2.0*k + 1.0);
           sum = sum + sign*term;
           sign = -sign;
            if (k % (N/5) == 0) {
                try {
                    Thread.sleep(40L);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    throw new StartException("Interrupted", e);
                }
            }
        }
        this.sum = sum;
    }

    public void stop(final StopContext context) {
    }

    public NonBusyService getValue() throws IllegalStateException {
        return this;
    }

    public static void main(String[] args) throws StartException {
        long start = System.currentTimeMillis();
        new NonBusyService().start(null);
        long t = System.currentTimeMillis() - start;
        System.out.println("Time = " + t);
    }
}
@@ -1257,62 +1257,16 @@
 ich 
-performs a long-ish calculation with embedded 
 sleeps.%0A
  *%0A 
@@ -1261,16 +1261,16 @@
 sleeps.%0A
+
  *%0A * @a
@@ -1412,70 +1412,8 @@
 e%3E %7B
-%0A    private static final int N = 1000000;%0A    double sum = 0;
 %0A%0A  
@@ -1496,390 +1496,14 @@
     
-// calculate pi, slowly (and inaccurately).  Takes around 232 ms on my 1.86GHz system (with embedded sleeps).%0A        double sum = 0.0;%0A        double term;%0A        double sign = 1.0;%0A        for (int k = 0; k %3C N; k++) %7B%0A           term = 1.0/(2.0*k + 1.0);%0A           sum = sum + sign*term;%0A           sign = -sign;%0A            if (k %25 (N/5) == 0) %7B%0A                try %7B%0A        
+try %7B%0A
     
@@ -1527,22 +1527,15 @@
 eep(
-4
+23
 0L);%0A
-        
     
@@ -1581,32 +1581,24 @@
             
-   
-     
 Thread.curre
@@ -1633,24 +1633,16 @@
         
-        
 throw ne
@@ -1659,17 +1659,17 @@
 eption(%22
-I
+i
 nterrupt
@@ -1689,65 +1689,9 @@
     
-        %7D%0A            %7D%0A        %7D%0A        this.sum = sum;
+%7D
 %0A   

Add a sleeping service