Example usage for java.lang Thread setName

List of usage examples for java.lang Thread setName

Introduction

In this page you can find the example usage for java.lang Thread setName.

Prototype

public final synchronized void setName(String name) 

Source Link

Document

Changes the name of this thread to be equal to the argument name .

Usage

From source file:ECallCenter21.java

/**
 *
 * @param callCenterModeParam/*w  w w.j av a2  s . c  om*/
 * @param managedModeParam
 * @param campaignIdParam
 * @throws SQLException
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws Exception
 */
public ECallCenter21(final String callCenterModeParam, final boolean managedModeParam,
        final int campaignIdParam) throws SQLException, ClassNotFoundException, InstantiationException,
        IllegalAccessException, NoSuchMethodException, InvocationTargetException, Exception {
    this();
    while (!defaultConstructorIsReady) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException ex) {
        }
    }

    Thread outboundCampaignThread = new Thread(allThreadsGroup, new Runnable() {
        @Override
        public void run() {
            callCenterIsNetManaged = managedModeParam;

            if (callCenterModeParam.equals("Outbound")) {
                positionWindow("Left");
                callCenterIsOutBound = true;
                try {
                    Thread.sleep(mediumMessagePeriod);
                } catch (InterruptedException ex) {
                }
                autoPowerOff = true;
                setPowerOn(true);
                while ((getCallCenterStatus() != POWEREDON) && (getCallCenterStatus() != RUNNING)
                        && (getCallCenterStatus() != PAUSING) && (getCallCenterStatus() != RERUNBREAK)) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                    }
                }
                initSlidersSmooth();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                }
                powerToggleButton.setSelected(true);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                }
                campaignComboBox.setSelectedItem(campaignIdParam);
                campaignComboBox.setEnabled(false);

                if (callCenterIsNetManaged) {
                    netManagerOutboundServerToggleButton.setEnabled(callCenterIsNetManaged);
                    netManagerOutboundServerToggleButton.setSelected(callCenterIsNetManaged);
                    enableOutboundNetManagerServer(true);
                }

                runCampaignToggleButton.setSelected(true);
                runCampaign(campaignIdParam);
            } else {
                usage();
                System.exit(0);
            }
        }
    });
    outboundCampaignThread.setName("outboundCampaignThread");
    outboundCampaignThread.setDaemon(runThreadsAsDaemons);
    outboundCampaignThread.setPriority(7);
    outboundCampaignThread.start();
}

From source file:ECallCenter21.java

/**
 *
 *///  w  w  w .java2 s .  c  o  m
public void timedAutoSpeedUpdate() {
    Thread timedAutoSpeedUpdateThread = new Thread(allThreadsGroup, new Runnable() {
        @Override
        @SuppressWarnings({ "static-access", "empty-statement" })
        public void run() {
            // Get the vmUsage load
            vmUsage = (sysMonitor.getProcessTime());
            //showStatus("vmUsage: " + vmUsage, true, false);

            // Set the vmUsage visualisers
            systemStatsTable.setValueAt(Long.toString(vmUsage), 0, 1);
            if (smoothCheckBox.isSelected()) {
                moveVMUsageMeter(((int) vmUsage), true);
            } else {
                moveVMUsageMeter(((int) vmUsage), false);
            }

            // Adjust Sliders
            if (autoSlidersEnabled) {
                if (outboundSoftPhonesAvailable > 0) {
                    long percentageRangeUsed;
                    if ((int) vmUsage > vmUsageDecelerationThreashold) {
                        int slowDownRange = 100 - vmUsageDecelerationThreashold;
                        int vmUsageAboveThreshhold = ((int) vmUsage - vmUsageDecelerationThreashold);
                        percentageRangeUsed = Math.round(vmUsageAboveThreshhold / (slowDownRange * 0.01));
                    } else {
                        percentageRangeUsed = 0;
                    }

                    if (smoothCheckBox.isSelected()) {
                        moveCallSpeedSlider((int) Math.round((percentageRangeUsed
                                * ((callSpeedSlider.getMaximum() - callSpeedSlider.getMinimum()) * 0.01))
                                + callSpeedSlider.getMinimum()), true);
                    } else {
                        moveCallSpeedSlider((int) Math.round((percentageRangeUsed
                                * ((callSpeedSlider.getMaximum() - callSpeedSlider.getMinimum()) * 0.01))
                                + callSpeedSlider.getMinimum()), false);
                    }
                }
            }
        }
    });
    timedAutoSpeedUpdateThread.setName("timedAutoSpeedUpdateThread");
    timedAutoSpeedUpdateThread.setDaemon(runThreadsAsDaemons);
    timedAutoSpeedUpdateThread.start();
}

From source file:ECallCenter21.java

/**
 *
 * @param displaymessage/*from  w ww.j  a va  2s  . c  o  m*/
 */
@Override
synchronized public void logToFile(final String displaymessage) {
    Thread logToFileThread = new Thread(new Runnable() {
        @Override
        @SuppressWarnings({ "static-access" })
        public void run() {
            Calendar logCalendar = Calendar.getInstance();

            String humanDate = "" + String.format("%04d", logCalendar.get(Calendar.YEAR)) + "-"
                    + String.format("%02d", logCalendar.get(Calendar.MONTH) + 1) + "-"
                    + String.format("%02d", logCalendar.get(Calendar.DAY_OF_MONTH)) + " "
                    + String.format("%02d", logCalendar.get(Calendar.HOUR_OF_DAY)) + ":"
                    + String.format("%02d", logCalendar.get(Calendar.MINUTE)) + ":"
                    + String.format("%02d", logCalendar.get(Calendar.SECOND));

            try {
                logFileWriter = new FileWriter(logFileString, true);
            } catch (IOException ex) {
                showStatus("Error: IOException: new FileWriter(" + logFileString + ")" + ex.getMessage(), false,
                        false);
                logBuffer += humanDate + " " + displaymessage + lineTerminator;
                return;
            }

            try {
                logFileWriter.flush();
            } catch (IOException ex) {
                showStatus("Error: IOException: logFileWriter.flush()1;", false, false);
                logBuffer += humanDate + " " + displaymessage + lineTerminator;
                return;
            }

            try {
                logFileWriter.write(logBuffer + humanDate + " " + displaymessage + lineTerminator);
            } catch (IOException ex) {
                showStatus("Error: IOException: logFileWriter.write()", false, false);
                logBuffer += humanDate + " " + displaymessage + lineTerminator;
                return;
            }

            try {
                logFileWriter.flush();
            } catch (IOException ex) {
                showStatus("Error: IOException: logFileWriter.flush()2;", false, false);
                logBuffer += humanDate + " " + displaymessage + lineTerminator;
                return;
            }

            logBuffer = "";

            try {
                logFileWriter.close();
            } catch (IOException ex) {
                showStatus("Error: IOException: logFileWriter.close();", false, false);
                return;
            }
        }
    });
    logToFileThread.setName("logToFileThread");
    logToFileThread.setDaemon(runThreadsAsDaemons);
    logToFileThread.start();
}

From source file:ECallCenter21.java

/**
 *
 */// w  ww .  ja v a 2s .  c  o m
public void unRegister() {
    Thread registerToggleButtonActionPerformedThread5 = new Thread(allThreadsGroup, new Runnable() {
        @Override
        @SuppressWarnings("static-access")
        public void run() {
            String[] status = new String[2];
            //              myClickOffSoundTool.play();
            runCampaignCounter = 0;

            showStatus("Sending Unregister requests to PBX...", true, true);
            registerToggleButton.setSelected(false);
            registerCounter = 0;
            while (registerCounter < outboundSoftPhonesAvailable) // Starts looping through the user-range
            {
                SoftPhone thisSoftPhoneInstance = (SoftPhone) threadArray[registerCounter]; // Get the reference to the SoftPhone object in the loop
                if (thisSoftPhoneInstance != null) {
                    status = thisSoftPhoneInstance.userInput(REGISTERBUTTON, "0", "", ""); // 1 ringResponseDelay, 2 BusyPercentage, 3 EndDelay
                    if (status[0].equals("1")) {
                        showStatus("Registration Error: " + status[1], true, true);
                    }
                    try {
                        Thread.sleep(registrationBurstDelay);
                    } catch (InterruptedException ex) {
                    }
                }
                phoneStatsTable.setValueAt(registerCounter + 1, 1, 1); // ProcessingInstance
                serviceLoopProgressBar.setValue(registerCounter);
                registerCounter++;
            }
            serviceLoopProgressBar.setEnabled(false);
            serviceLoopProgressBar.setValue(0);
            // Do another round to recheck and redo the leftovers
            registerCounter = 0;
            int lastRegisteredActiveCount = 0;
            showStatus("Receiving delayed PBX Unregister responses...", true, true);
            while (lastRegisteredActiveCount != registeredActiveCount) // This codeblock waits until no more PBX registries are detected in time before doing another last (extra) register round
            {
                lastRegisteredActiveCount = registeredActiveCount;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                }
            }
            showStatus("Sending Unregister requests to PBX completed", true, true);
            registerToggleButton.setForeground(Color.BLACK);
            phoneStatsTable.setValueAt("-", 1, 1); // ProcessingInstance
        }
    });
    registerToggleButtonActionPerformedThread5.setName("registerToggleButtonActionPerformed5");
    registerToggleButtonActionPerformedThread5.setDaemon(runThreadsAsDaemons);
    registerToggleButtonActionPerformedThread5.start();

    humanResponseSimulator("0"); // Human Simulator must wait for reregistering
}

From source file:ECallCenter21.java

/**
 *
 * @param callCenterModeParam//from www  .  j  a v  a2  s  .  c o  m
 * @param managedModeParam
 * @throws SQLException
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws Exception
 */
public ECallCenter21(final String callCenterModeParam, final boolean managedModeParam)
        throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException,
        NoSuchMethodException, InvocationTargetException, Exception {
    this(); // Execute default constructor
    while (!defaultConstructorIsReady) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException ex) {
        }
    }

    Thread inboundCampaignThread = new Thread(allThreadsGroup, new Runnable() {
        @Override
        public void run() {
            callCenterIsNetManaged = managedModeParam;

            if (callCenterModeParam.equals("Inbound")) {
                positionWindow("Right");
                callCenterIsOutBound = false;
                try {
                    Thread.sleep(mediumMessagePeriod);
                } catch (InterruptedException ex) {
                }
                setPowerOn(true);
                while (getCallCenterStatus() != POWEREDON) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                    }
                }
                powerToggleButton.setSelected(true);
                register();

                initSlidersSmooth();
            } else if (callCenterModeParam.equals("Outbound")) {
                positionWindow("Left");
                callCenterIsOutBound = true;
                try {
                    Thread.sleep(mediumMessagePeriod);
                } catch (InterruptedException ex) {
                }
                setPowerOn(true);
                while (getCallCenterStatus() != POWEREDON) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                    }
                }
                powerToggleButton.setSelected(true);

                if (callCenterIsNetManaged) {
                    netManagerOutboundServerToggleButton.setEnabled(callCenterIsNetManaged);
                    netManagerOutboundServerToggleButton.setSelected(callCenterIsNetManaged);
                    enableOutboundNetManagerServer(true);
                }

                initSlidersSmooth();
            } else {
                positionWindow("Right");
                callCenterIsOutBound = true;
                try {
                    Thread.sleep(mediumMessagePeriod);
                } catch (InterruptedException ex) {
                }
                setPowerOn(true);
                while (getCallCenterStatus() != POWEREDON) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ex) {
                    }
                }
                powerToggleButton.setSelected(true);
                initSlidersSmooth();
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException ex) {
                }
            }
        }
    });
    inboundCampaignThread.setName("inboundCampaignThread");
    inboundCampaignThread.setDaemon(runThreadsAsDaemons);
    inboundCampaignThread.setPriority(7);
    inboundCampaignThread.start();
}

From source file:ECallCenter21.java

private void debugSoftPhones(final boolean muteParam) {
    Thread debugSoftPhonesThread = new Thread(allThreadsGroup, new Runnable() {
        @Override/*  ww w . j a  v  a2  s .  c om*/
        public void run() {
            serviceLoopProgressBar.setEnabled(true);
            if (muteParam) {
                //                    myClickOnSoundTool.play();
                runCampaignCounter = 0;
                showStatus("Enable Mute Audio SoftPhone...", true, true);
                while (runCampaignCounter < outboundSoftPhonesAvailable) // Starts looping through the user-range
                {
                    SoftPhone thisSoftPhoneInstance = (SoftPhone) threadArray[runCampaignCounter]; // Get the reference to the SoftPhone object in the loop
                    thisSoftPhoneInstance.userInput(DEBUGBUTTON, "1", "", ""); // Send a registerButton response to this object's method userInput
                    phoneStatsTable.setValueAt(runCampaignCounter + 1, 1, 1);
                    serviceLoopProgressBar.setValue(runCampaignCounter);
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException ex) {
                    }
                    runCampaignCounter++;
                }
                showStatus("Enable Mute Audio SoftPhone Completed", true, true);
                muteAudioToggleButton.setForeground(Color.blue);
                phoneStatsTable.setValueAt("-", 1, 1);
            } else {
                showStatus("Disable Mute Audio SoftPhone...", true, true);
                //                    myClickOffSoundTool.play();
                runCampaignCounter = 0;
                while (runCampaignCounter < outboundSoftPhonesAvailable) // Starts looping through the user-range
                {
                    SoftPhone thisSoftPhoneInstance = (SoftPhone) threadArray[runCampaignCounter]; // Get the reference to the SoftPhone object in the loop
                    thisSoftPhoneInstance.userInput(DEBUGBUTTON, "0", "", ""); // Send a registerButton response to this object's method userInput
                    phoneStatsTable.setValueAt(runCampaignCounter + 1, 1, 1); // ProcessingInstance
                    serviceLoopProgressBar.setValue(runCampaignCounter);
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException ex) {
                    }
                    runCampaignCounter++;
                }
                showStatus("Disable Mute Audio SoftPhone Completed", true, true);
                muteAudioToggleButton.setForeground(Color.black);
                phoneStatsTable.setValueAt("-", 1, 1);
            }
            serviceLoopProgressBar.setValue(0);
            serviceLoopProgressBar.setEnabled(false);
            return;
        }
    });
    debugSoftPhonesThread.setName("debugSoftPhonesThread");
    debugSoftPhonesThread.setDaemon(runThreadsAsDaemons);
    debugSoftPhonesThread.start();
}

From source file:jp.ne.sakura.kkkon.android.exceptionhandler.testapp.ExceptionHandlerReportApp.java

/** Called when the activity is first created. */
@Override// www . ja va  2s. co  m
public void onCreate(Bundle savedInstanceState) {
    final Context context = this.getApplicationContext();

    {
        ExceptionHandler.initialize(context);
        if (ExceptionHandler.needReport()) {
            final String fileName = ExceptionHandler.getBugReportFileAbsolutePath();
            final File file = new File(fileName);
            final File fileZip;
            {
                String strFileZip = file.getAbsolutePath();
                {
                    int index = strFileZip.lastIndexOf('.');
                    if (0 < index) {
                        strFileZip = strFileZip.substring(0, index);
                        strFileZip += ".zip";
                    }
                }
                Log.d(TAG, strFileZip);
                fileZip = new File(strFileZip);
                if (fileZip.exists()) {
                    fileZip.delete();
                }
            }
            if (file.exists()) {
                Log.d(TAG, file.getAbsolutePath());
                InputStream inStream = null;
                ZipOutputStream outStream = null;
                try {
                    inStream = new FileInputStream(file);
                    String strFileName = file.getAbsolutePath();
                    {
                        int index = strFileName.lastIndexOf(File.separatorChar);
                        if (0 < index) {
                            strFileName = strFileName.substring(index + 1);
                        }
                    }
                    Log.d(TAG, strFileName);

                    outStream = new ZipOutputStream(new FileOutputStream(fileZip));
                    byte[] buff = new byte[8124];
                    {
                        ZipEntry entry = new ZipEntry(strFileName);
                        outStream.putNextEntry(entry);

                        int len = 0;
                        while (0 < (len = inStream.read(buff))) {
                            outStream.write(buff, 0, len);
                        }
                        outStream.closeEntry();
                    }
                    outStream.finish();
                    outStream.flush();

                } catch (IOException e) {
                    Log.e(TAG, "got exception", e);
                } finally {
                    if (null != outStream) {
                        try {
                            outStream.close();
                        } catch (Exception e) {
                        }
                    }
                    outStream = null;

                    if (null != inStream) {
                        try {
                            inStream.close();
                        } catch (Exception e) {
                        }
                    }
                    inStream = null;
                }
                Log.i(TAG, "zip created");
            }

            if (file.exists()) {
                // upload or send e-mail
                InputStream inStream = null;
                StringBuilder sb = new StringBuilder();
                try {
                    inStream = new FileInputStream(file);
                    byte[] buff = new byte[8124];
                    int readed = 0;
                    do {
                        readed = inStream.read(buff);
                        for (int i = 0; i < readed; i++) {
                            sb.append((char) buff[i]);
                        }
                    } while (readed >= 0);

                    final String str = sb.toString();
                    Log.i(TAG, str);
                } catch (IOException e) {
                    Log.e(TAG, "got exception", e);
                } finally {
                    if (null != inStream) {
                        try {
                            inStream.close();
                        } catch (Exception e) {
                        }
                    }
                    inStream = null;
                }

                AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
                final Locale defaultLocale = Locale.getDefault();

                String title = "";
                String message = "";
                String positive = "";
                String negative = "";

                boolean needDefaultLang = true;
                if (null != defaultLocale) {
                    if (defaultLocale.equals(Locale.JAPANESE) || defaultLocale.equals(Locale.JAPAN)) {
                        title = "";
                        message = "?????????";
                        positive = "?";
                        negative = "";
                        needDefaultLang = false;
                    }
                }
                if (needDefaultLang) {
                    title = "ERROR";
                    message = "Got unexpected error. Do you want to send information of error.";
                    positive = "Send";
                    negative = "Cancel";
                }
                alertDialog.setTitle(title);
                alertDialog.setMessage(message);
                alertDialog.setPositiveButton(positive + " mail", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface di, int i) {
                        DefaultUploaderMailClient.upload(context, file,
                                new String[] { "diverKon+sakura@gmail.com" });
                    }
                });
                alertDialog.setNeutralButton(positive + " http", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface di, int i) {
                        DefaultUploaderWeb.upload(ExceptionHandlerReportApp.this, fileZip,
                                "http://kkkon.sakura.ne.jp/android/bug");
                    }
                });
                alertDialog.setNegativeButton(negative, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface di, int i) {
                        ExceptionHandler.clearReport();
                    }
                });
                alertDialog.show();
            }
            // TODO separate activity for crash report
            //DefaultCheckerAPK.checkAPK( this, null );
        }
        ExceptionHandler.registHandler();
    }

    super.onCreate(savedInstanceState);

    /* Create a TextView and set its content.
     * the text is retrieved by calling a native
     * function.
     */
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);

    TextView tv = new TextView(this);
    tv.setText("ExceptionHandler");
    layout.addView(tv);

    Button btn1 = new Button(this);
    btn1.setText("invoke Exception");
    btn1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final int count = 2;
            int[] array = new int[count];
            int value = array[count]; // invoke IndexOutOfBOundsException
        }
    });
    layout.addView(btn1);

    Button btn2 = new Button(this);
    btn2.setText("reinstall apk");
    btn2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            boolean foundApk = false;
            {
                final String apkPath = context.getPackageCodePath(); // API8
                Log.d(TAG, "PackageCodePath: " + apkPath);
                final File fileApk = new File(apkPath);
                if (fileApk.exists()) {
                    foundApk = true;

                    Intent promptInstall = new Intent(Intent.ACTION_VIEW);
                    promptInstall.setDataAndType(Uri.fromFile(fileApk),
                            "application/vnd.android.package-archive");
                    promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(promptInstall);
                }
            }

            if (false == foundApk) {
                for (int i = 0; i < 10; ++i) {
                    File fileApk = new File("/data/app/" + context.getPackageName() + "-" + i + ".apk");
                    Log.d(TAG, "check apk:" + fileApk.getAbsolutePath());
                    if (fileApk.exists()) {
                        Log.i(TAG, "apk found. path=" + fileApk.getAbsolutePath());
                        /*
                         * // require parmission
                        {
                        final String strCmd = "pm install -r " + fileApk.getAbsolutePath();
                        try
                        {
                            Runtime.getRuntime().exec( strCmd );
                        }
                        catch ( IOException e )
                        {
                            Log.e( TAG, "got exception", e );
                        }
                        }
                        */
                        Intent promptInstall = new Intent(Intent.ACTION_VIEW);
                        promptInstall.setDataAndType(Uri.fromFile(fileApk),
                                "application/vnd.android.package-archive");
                        promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(promptInstall);
                        break;
                    }
                }
            }
        }
    });
    layout.addView(btn2);

    Button btn3 = new Button(this);
    btn3.setText("check apk");
    btn3.setOnClickListener(new View.OnClickListener() {
        private boolean checkApk(final File fileApk, final ZipEntryFilter filter) {
            final boolean[] result = new boolean[1];
            result[0] = true;

            final Thread thread = new Thread(new Runnable() {

                @Override
                public void run() {
                    if (fileApk.exists()) {
                        ZipFile zipFile = null;
                        try {
                            zipFile = new ZipFile(fileApk);
                            List<ZipEntry> list = new ArrayList<ZipEntry>(zipFile.size());
                            for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();) {
                                ZipEntry ent = e.nextElement();
                                Log.d(TAG, ent.getName());
                                Log.d(TAG, "" + ent.getSize());
                                final boolean accept = filter.accept(ent);
                                if (accept) {
                                    list.add(ent);
                                }
                            }

                            Log.d(TAG, Build.CPU_ABI); // API 4
                            Log.d(TAG, Build.CPU_ABI2); // API 8

                            final String[] abiArray = { Build.CPU_ABI // API 4
                                    , Build.CPU_ABI2 // API 8
                            };

                            String abiMatched = null;
                            {
                                boolean foundMatched = false;
                                for (final String abi : abiArray) {
                                    if (null == abi) {
                                        continue;
                                    }
                                    if (0 == abi.length()) {
                                        continue;
                                    }

                                    for (final ZipEntry entry : list) {
                                        Log.d(TAG, entry.getName());

                                        final String prefixABI = "lib/" + abi + "/";
                                        if (entry.getName().startsWith(prefixABI)) {
                                            abiMatched = abi;
                                            foundMatched = true;
                                            break;
                                        }
                                    }

                                    if (foundMatched) {
                                        break;
                                    }
                                }
                            }
                            Log.d(TAG, "matchedAbi=" + abiMatched);

                            if (null != abiMatched) {
                                boolean needReInstall = false;

                                for (final ZipEntry entry : list) {
                                    Log.d(TAG, entry.getName());

                                    final String prefixABI = "lib/" + abiMatched + "/";
                                    if (entry.getName().startsWith(prefixABI)) {
                                        final String jniName = entry.getName().substring(prefixABI.length());
                                        Log.d(TAG, "jni=" + jniName);

                                        final String strFileDst = context.getApplicationInfo().nativeLibraryDir
                                                + "/" + jniName;
                                        Log.d(TAG, strFileDst);
                                        final File fileDst = new File(strFileDst);
                                        if (!fileDst.exists()) {
                                            Log.w(TAG, "needReInstall: content missing " + strFileDst);
                                            needReInstall = true;
                                        } else {
                                            assert (entry.getSize() <= Integer.MAX_VALUE);
                                            if (fileDst.length() != entry.getSize()) {
                                                Log.w(TAG, "needReInstall: size broken " + strFileDst);
                                                needReInstall = true;
                                            } else {
                                                //org.apache.commons.io.IOUtils.contentEquals( zipFile.getInputStream( entry ), new FileInputStream(fileDst) );

                                                final int size = (int) entry.getSize();
                                                byte[] buffSrc = new byte[size];

                                                {
                                                    InputStream inStream = null;
                                                    try {
                                                        inStream = zipFile.getInputStream(entry);
                                                        int pos = 0;
                                                        {
                                                            while (pos < size) {
                                                                final int ret = inStream.read(buffSrc, pos,
                                                                        size - pos);
                                                                if (ret <= 0) {
                                                                    break;
                                                                }
                                                                pos += ret;
                                                            }
                                                        }
                                                    } catch (IOException e) {
                                                        Log.d(TAG, "got exception", e);
                                                    } finally {
                                                        if (null != inStream) {
                                                            try {
                                                                inStream.close();
                                                            } catch (Exception e) {
                                                            }
                                                        }
                                                    }
                                                }
                                                byte[] buffDst = new byte[(int) fileDst.length()];
                                                {
                                                    InputStream inStream = null;
                                                    try {
                                                        inStream = new FileInputStream(fileDst);
                                                        int pos = 0;
                                                        {
                                                            while (pos < size) {
                                                                final int ret = inStream.read(buffDst, pos,
                                                                        size - pos);
                                                                if (ret <= 0) {
                                                                    break;
                                                                }
                                                                pos += ret;
                                                            }
                                                        }
                                                    } catch (IOException e) {
                                                        Log.d(TAG, "got exception", e);
                                                    } finally {
                                                        if (null != inStream) {
                                                            try {
                                                                inStream.close();
                                                            } catch (Exception e) {
                                                            }
                                                        }
                                                    }
                                                }

                                                if (Arrays.equals(buffSrc, buffDst)) {
                                                    Log.d(TAG, " content equal " + strFileDst);
                                                    // OK
                                                } else {
                                                    Log.w(TAG, "needReInstall: content broken " + strFileDst);
                                                    needReInstall = true;
                                                }
                                            }

                                        }

                                    }
                                } // for ZipEntry

                                if (needReInstall) {
                                    // need call INSTALL APK
                                    Log.w(TAG, "needReInstall apk");
                                    result[0] = false;
                                } else {
                                    Log.d(TAG, "no need ReInstall apk");
                                }
                            }

                        } catch (IOException e) {
                            Log.d(TAG, "got exception", e);
                        } finally {
                            if (null != zipFile) {
                                try {
                                    zipFile.close();
                                } catch (Exception e) {
                                }
                            }
                        }
                    }
                }

            });
            thread.setName("check jni so");

            thread.start();
            /*
            while ( thread.isAlive() )
            {
            Log.d( TAG, "check thread.id=" + android.os.Process.myTid() + ",state=" + thread.getState() );
            if ( ! thread.isAlive() )
            {
                break;
            }
            AlertDialog.Builder alertDialog = new AlertDialog.Builder( ExceptionHandlerTestApp.this );
            final Locale defaultLocale = Locale.getDefault();
                    
            String title = "";
            String message = "";
            String positive = "";
            String negative = "";
                    
            boolean needDefaultLang = true;
            if ( null != defaultLocale )
            {
                if ( defaultLocale.equals( Locale.JAPANESE ) || defaultLocale.equals( Locale.JAPAN ) )
                {
                    title = "";
                    message = "???????";
                    positive = "?";
                    negative = "";
                    needDefaultLang = false;
                }
            }
            if ( needDefaultLang )
            {
                title = "INFO";
                message = "Now checking installation. Cancel check?";
                positive = "Wait";
                negative = "Cancel";
            }
            alertDialog.setTitle( title );
            alertDialog.setMessage( message );
            alertDialog.setPositiveButton( positive, null);
            alertDialog.setNegativeButton( negative, new DialogInterface.OnClickListener() {
                    
                @Override
                public void onClick(DialogInterface di, int i) {
                    if ( thread.isAlive() )
                    {
                        Log.d( TAG, "request interrupt" );
                        thread.interrupt();
                    }
                    else
                    {
                        // nothing
                    }
                }
            } );
                    
            if ( ! thread.isAlive() )
            {
                break;
            }
                    
            alertDialog.show();
                    
            if ( ! Thread.State.RUNNABLE.equals(thread.getState()) )
            {
                break;
            }
                    
            }
            */

            try {
                thread.join();
            } catch (InterruptedException e) {
                Log.d(TAG, "got exception", e);
            }

            return result[0];
        }

        @Override
        public void onClick(View view) {
            boolean foundApk = false;
            {
                final String apkPath = context.getPackageCodePath(); // API8
                Log.d(TAG, "PackageCodePath: " + apkPath);
                final File fileApk = new File(apkPath);
                this.checkApk(fileApk, new ZipEntryFilter() {
                    @Override
                    public boolean accept(ZipEntry entry) {
                        if (entry.isDirectory()) {
                            return false;
                        }

                        final String filename = entry.getName();
                        if (filename.startsWith("lib/")) {
                            return true;
                        }

                        return false;
                    }
                });
            }

        }
    });
    layout.addView(btn3);

    Button btn4 = new Button(this);
    btn4.setText("print dir and path");
    btn4.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            {
                final File file = context.getCacheDir();
                Log.d(TAG, "Ctx.CacheDir=" + file.getAbsoluteFile());
            }
            {
                final File file = context.getExternalCacheDir(); // API 8
                if (null == file) {
                    // no permission
                    Log.d(TAG, "Ctx.ExternalCacheDir=");
                } else {
                    Log.d(TAG, "Ctx.ExternalCacheDir=" + file.getAbsolutePath());
                }
            }
            {
                final File file = context.getFilesDir();
                Log.d(TAG, "Ctx.FilesDir=" + file.getAbsolutePath());
            }
            {
                final String value = context.getPackageResourcePath();
                Log.d(TAG, "Ctx.PackageResourcePath=" + value);
            }
            {
                final String[] files = context.fileList();
                if (null == files) {
                    Log.d(TAG, "Ctx.fileList=" + files);
                } else {
                    for (final String filename : files) {
                        Log.d(TAG, "Ctx.fileList=" + filename);
                    }
                }
            }

            {
                final File file = Environment.getDataDirectory();
                Log.d(TAG, "Env.DataDirectory=" + file.getAbsolutePath());
            }
            {
                final File file = Environment.getDownloadCacheDirectory();
                Log.d(TAG, "Env.DownloadCacheDirectory=" + file.getAbsolutePath());
            }
            {
                final File file = Environment.getExternalStorageDirectory();
                Log.d(TAG, "Env.ExternalStorageDirectory=" + file.getAbsolutePath());
            }
            {
                final File file = Environment.getRootDirectory();
                Log.d(TAG, "Env.RootDirectory=" + file.getAbsolutePath());
            }
            {
                final ApplicationInfo appInfo = context.getApplicationInfo();
                Log.d(TAG, "AppInfo.dataDir=" + appInfo.dataDir);
                Log.d(TAG, "AppInfo.nativeLibraryDir=" + appInfo.nativeLibraryDir); // API 9
                Log.d(TAG, "AppInfo.publicSourceDir=" + appInfo.publicSourceDir);
                {
                    final String[] sharedLibraryFiles = appInfo.sharedLibraryFiles;
                    if (null == sharedLibraryFiles) {
                        Log.d(TAG, "AppInfo.sharedLibraryFiles=" + sharedLibraryFiles);
                    } else {
                        for (final String fileName : sharedLibraryFiles) {
                            Log.d(TAG, "AppInfo.sharedLibraryFiles=" + fileName);
                        }
                    }
                }
                Log.d(TAG, "AppInfo.sourceDir=" + appInfo.sourceDir);
            }
            {
                Log.d(TAG, "System.Properties start");
                final Properties properties = System.getProperties();
                if (null != properties) {
                    for (final Object key : properties.keySet()) {
                        String value = properties.getProperty((String) key);
                        Log.d(TAG, " key=" + key + ",value=" + value);
                    }
                }
                Log.d(TAG, "System.Properties end");
            }
            {
                Log.d(TAG, "System.getenv start");
                final Map<String, String> mapEnv = System.getenv();
                if (null != mapEnv) {
                    for (final Map.Entry<String, String> entry : mapEnv.entrySet()) {
                        final String key = entry.getKey();
                        final String value = entry.getValue();
                        Log.d(TAG, " key=" + key + ",value=" + value);
                    }
                }
                Log.d(TAG, "System.getenv end");
            }
        }
    });
    layout.addView(btn4);

    Button btn5 = new Button(this);
    btn5.setText("check INSTALL_NON_MARKET_APPS");
    btn5.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            SettingsCompat.initialize(context);
            if (SettingsCompat.isAllowedNonMarketApps()) {
                Log.d(TAG, "isAllowdNonMarketApps=true");
            } else {
                Log.d(TAG, "isAllowdNonMarketApps=false");
            }
        }
    });
    layout.addView(btn5);

    Button btn6 = new Button(this);
    btn6.setText("send email");
    btn6.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent mailto = new Intent();
            mailto.setAction(Intent.ACTION_SENDTO);
            mailto.setType("message/rfc822");
            mailto.setData(Uri.parse("mailto:"));
            mailto.putExtra(Intent.EXTRA_EMAIL, new String[] { "" });
            mailto.putExtra(Intent.EXTRA_SUBJECT, "[BugReport] " + context.getPackageName());
            mailto.putExtra(Intent.EXTRA_TEXT, "body text");
            //mailto.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK );
            //context.startActivity( mailto );
            Intent intent = Intent.createChooser(mailto, "Send Email");
            if (null != intent) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                    context.startActivity(intent);
                } catch (android.content.ActivityNotFoundException e) {
                    Log.d(TAG, "got Exception", e);
                }
            }
        }
    });
    layout.addView(btn6);

    Button btn7 = new Button(this);
    btn7.setText("upload http thread");
    btn7.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Log.d(TAG, "brd=" + Build.BRAND);
            Log.d(TAG, "prd=" + Build.PRODUCT);

            //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS)
            Log.d(TAG, "fng=" + Build.FINGERPRINT);
            final List<NameValuePair> list = new ArrayList<NameValuePair>(16);
            list.add(new BasicNameValuePair("fng", Build.FINGERPRINT));

            final Thread thread = new Thread(new Runnable() {

                @Override
                public void run() {
                    Log.d(TAG, "upload thread tid=" + android.os.Process.myTid());
                    try {
                        HttpPost httpPost = new HttpPost("http://kkkon.sakura.ne.jp/android/bug");
                        //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) );
                        httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
                        DefaultHttpClient httpClient = new DefaultHttpClient();
                        Log.d(TAG, "socket.timeout="
                                + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                        Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                        httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
                                new Integer(5 * 1000));
                        httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
                                new Integer(5 * 1000));
                        Log.d(TAG, "socket.timeout="
                                + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                        Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                        // <uses-permission android:name="android.permission.INTERNET"/>
                        // got android.os.NetworkOnMainThreadException, run at UI Main Thread
                        HttpResponse response = httpClient.execute(httpPost);
                        Log.d(TAG, "response=" + response.getStatusLine().getStatusCode());
                    } catch (Exception e) {
                        Log.d(TAG, "got Exception. msg=" + e.getMessage(), e);
                    }
                    Log.d(TAG, "upload finish");
                }
            });
            thread.setName("upload crash");

            thread.start();
            /*
            while ( thread.isAlive() )
            {
            Log.d( TAG, "thread tid=" + android.os.Process.myTid() + ",state=" + thread.getState() );
            if ( ! thread.isAlive() )
            {
                break;
            }
            AlertDialog.Builder alertDialog = new AlertDialog.Builder( ExceptionHandlerTestApp.this );
            final Locale defaultLocale = Locale.getDefault();
                    
            String title = "";
            String message = "";
            String positive = "";
            String negative = "";
                    
            boolean needDefaultLang = true;
            if ( null != defaultLocale )
            {
                if ( defaultLocale.equals( Locale.JAPANESE ) || defaultLocale.equals( Locale.JAPAN ) )
                {
                    title = "";
                    message = "???????";
                    positive = "?";
                    negative = "";
                    needDefaultLang = false;
                }
            }
            if ( needDefaultLang )
            {
                title = "INFO";
                message = "Now uploading error information. Cancel upload?";
                positive = "Wait";
                negative = "Cancel";
            }
            alertDialog.setTitle( title );
            alertDialog.setMessage( message );
            alertDialog.setPositiveButton( positive, null);
            alertDialog.setNegativeButton( negative, new DialogInterface.OnClickListener() {
                    
                @Override
                public void onClick(DialogInterface di, int i) {
                    if ( thread.isAlive() )
                    {
                        Log.d( TAG, "request interrupt" );
                        thread.interrupt();
                    }
                    else
                    {
                        // nothing
                    }
                }
            } );
                    
            if ( ! thread.isAlive() )
            {
                break;
            }
                    
            alertDialog.show();
                    
            if ( ! Thread.State.RUNNABLE.equals(thread.getState()) )
            {
                break;
            }
                    
            }
            */

            /*
            try
            {
            thread.join(); // must call. leak handle...
            }
            catch ( InterruptedException e )
            {
            Log.d( TAG, "got Exception", e );
            }
            */
        }
    });
    layout.addView(btn7);

    Button btn8 = new Button(this);
    btn8.setText("upload http AsyncTask");
    btn8.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            AsyncTask<String, Void, Boolean> asyncTask = new AsyncTask<String, Void, Boolean>() {

                @Override
                protected Boolean doInBackground(String... paramss) {
                    Boolean result = true;
                    Log.d(TAG, "upload AsyncTask tid=" + android.os.Process.myTid());
                    try {
                        //$(BRAND)/$(PRODUCT)/$(DEVICE)/$(BOARD):$(VERSION.RELEASE)/$(ID)/$(VERSION.INCREMENTAL):$(TYPE)/$(TAGS)
                        Log.d(TAG, "fng=" + Build.FINGERPRINT);
                        final List<NameValuePair> list = new ArrayList<NameValuePair>(16);
                        list.add(new BasicNameValuePair("fng", Build.FINGERPRINT));

                        HttpPost httpPost = new HttpPost(paramss[0]);
                        //httpPost.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer(5*1000) );
                        httpPost.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
                        DefaultHttpClient httpClient = new DefaultHttpClient();
                        Log.d(TAG, "socket.timeout="
                                + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                        Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                        httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
                                new Integer(5 * 1000));
                        httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
                                new Integer(5 * 1000));
                        Log.d(TAG, "socket.timeout="
                                + httpClient.getParams().getIntParameter(CoreConnectionPNames.SO_TIMEOUT, -1));
                        Log.d(TAG, "connection.timeout=" + httpClient.getParams()
                                .getIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, -1));
                        // <uses-permission android:name="android.permission.INTERNET"/>
                        // got android.os.NetworkOnMainThreadException, run at UI Main Thread
                        HttpResponse response = httpClient.execute(httpPost);
                        Log.d(TAG, "response=" + response.getStatusLine().getStatusCode());
                    } catch (Exception e) {
                        Log.d(TAG, "got Exception. msg=" + e.getMessage(), e);
                        result = false;
                    }
                    Log.d(TAG, "upload finish");
                    return result;
                }

            };

            asyncTask.execute("http://kkkon.sakura.ne.jp/android/bug");
            asyncTask.isCancelled();
        }
    });
    layout.addView(btn8);

    Button btn9 = new Button(this);
    btn9.setText("call checkAPK");
    btn9.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final boolean result = DefaultCheckerAPK.checkAPK(ExceptionHandlerReportApp.this, null);
            Log.i(TAG, "checkAPK result=" + result);
        }
    });
    layout.addView(btn9);

    setContentView(layout);
}

From source file:ECallCenter21.java

private void debugToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_debugToggleButtonActionPerformed
    Thread debugToggleButtonActionPerformedThread = new Thread(allThreadsGroup, new Runnable() {
        @Override//  w w  w  . j a v  a 2s.com
        public void run() {
            String[] status = new String[2];
            serviceLoopProgressBar.setEnabled(true);
            if (debugToggleButton.isSelected()) {
                //                    myClickOnSoundTool.play();
                debugCounter = 0;
                showStatus("Enable Debug SoftPhones...", true, true);
                while (debugCounter < outboundSoftPhonesAvailable) // Starts looping through the user-range
                {
                    SoftPhone thisSoftPhoneInstance = (SoftPhone) threadArray[debugCounter]; // Get the reference to the SoftPhone object in the loop
                    status = thisSoftPhoneInstance.userInput(DEBUGBUTTON, "1", "", ""); // Send a registerButton response to this object's method userInput
                    if (status[0].equals("1")) {
                        showStatus("SoftPhone Debug Error: " + status[1], true, true);
                    }
                    phoneStatsTable.setValueAt(debugCounter + 1, 1, 1);
                    serviceLoopProgressBar.setValue(debugCounter);
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException ex) {
                    }
                    debugCounter++;
                }
                showStatus("Enable Debug SoftPhones Completed", true, true);
                debugToggleButton.setForeground(Color.blue);
                phoneStatsTable.setValueAt("-", 1, 1);
            } else {
                showStatus("Disable Debug SoftPhones...", true, true);
                //                    myClickOffSoundTool.play();
                debugCounter = 0;
                while (debugCounter < outboundSoftPhonesAvailable) // Starts looping through the user-range
                {
                    SoftPhone thisSoftPhoneInstance = (SoftPhone) threadArray[debugCounter]; // Get the reference to the SoftPhone object in the loop
                    status = thisSoftPhoneInstance.userInput(DEBUGBUTTON, "0", "", ""); // Send a registerButton response to this object's method userInput
                    if (status[0].equals("1")) {
                        showStatus("SoftPhone Debug Error: " + status[1], true, true);
                    }
                    phoneStatsTable.setValueAt(debugCounter + 1, 1, 1); // ProcessingInstance
                    serviceLoopProgressBar.setValue(debugCounter);
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException ex) {
                    }
                    debugCounter++;
                }
                showStatus("Disable Debug SoftPhones Completed", true, true);
                debugToggleButton.setForeground(Color.black);
                phoneStatsTable.setValueAt("-", 1, 1);
            }
            serviceLoopProgressBar.setValue(0);
            serviceLoopProgressBar.setEnabled(false);
            return;
        }
    });
    debugToggleButtonActionPerformedThread.setName("debugToggleButtonActionPerformedThread");
    debugToggleButtonActionPerformedThread.setDaemon(runThreadsAsDaemons);
    debugToggleButtonActionPerformedThread.start();
}

From source file:ECallCenter21.java

private void humanResponseSimulator(final String buttonsOnParam) {
    //   final String buttonOn = new String(buttonsOnParam);
    Thread humanResponseSimulatorThread = new Thread(allThreadsGroup, new Runnable() {
        @Override//from w  w w . j a  v  a 2s  . c  om
        public void run() {
            String[] status = new String[2];
            if (buttonsOnParam.equals("1")) {
                humanResponseSimulatorToggleButton.setSelected(true);
            }

            serviceLoopProgressBar.setEnabled(true);
            int simulateCounter = 0;
            showStatus("Setting Inbound SoftPhones Simulation...", true,
                    true); /* true = logToApplic, true = logToFile */
            while (simulateCounter < outboundSoftPhonesAvailable) // Starts looping through the user-range
            {
                phoneStatsTable.setValueAt(simulateCounter + 1, 1, 1);

                // Sets Human Simulation for Inbound Mode
                SoftPhone thisSoftPhoneInstance = (SoftPhone) threadArray[simulateCounter];
                status = thisSoftPhoneInstance.userInput(RANDOMRINGRESPONSEBUTTON, buttonsOnParam,
                        Integer.toString((int) (Math.random() * inboundRingingResponseDelaySlider.getValue())),
                        Integer.toString(inboundRingingResponseBusyRatioSlider.getValue()));
                if (status[0].equals("1")) {
                    showStatus("Human Simulation Error: " + status[1], true, true);
                    /* true = logToApplic, true = logToFile */ }
                try {
                    Thread.sleep(1);
                } catch (InterruptedException ex) {
                }

                // Sets the CallEnd Timer to autoEnd this Call after a certain random period (The answerer lost interest)
                status = thisSoftPhoneInstance.userInput(ENDTIMERBUTTON, buttonsOnParam,
                        Integer.toString((int) (Math.random() * inboundEndDelaySlider.getValue())), "");
                if (status[0].equals("1")) {
                    showStatus("End Timer Error: " + status[1], true, true);
                    /* true = logToApplic, true = logToFile */ }
                serviceLoopProgressBar.setValue(simulateCounter);
                simulateCounter++;
            }
            if (buttonsOnParam.equals("1")) {
                callCenterIsOutBound = false;
                boundMode = "Inbound";
                humanResponseSimulatorToggleButton.setForeground(Color.BLUE);
                setAutoSpeed(false);
                phoneStatsTable.setValueAt("-", 1, 1);
                showStatus(Vergunning.PRODUCT + " Inbound Test Mode Enabled", true,
                        true); /* true = logToApplic, true = logToFile */
            } else {
                humanResponseSimulatorToggleButton.setForeground(Color.BLACK);
                humanResponseSimulatorToggleButton.setSelected(false);
                setAutoSpeed(true);
                phoneStatsTable.setValueAt("-", 1, 1);
                showStatus(Vergunning.PRODUCT + " Inbound Test Mode Disabled", true,
                        true); /* true = logToApplic, true = logToFile */
            }
            serviceLoopProgressBar.setValue(0);
            serviceLoopProgressBar.setEnabled(false);
            return;
        }
    });
    humanResponseSimulatorThread.setName("humanResponseSimulatorThread");
    humanResponseSimulatorThread.setDaemon(runThreadsAsDaemons);
    humanResponseSimulatorThread.start();

    // The Human Simulator must allways wait for the RegistrationTimerThread
}

From source file:ECallCenter21.java

/**
 *
 *///from w ww .j a va 2 s  . c o m
public void timedStallingDetectionUpdate() {
    Thread timedStallingDetectionUpdateThread = new Thread(allThreadsGroup, new Runnable() {
        @Override
        @SuppressWarnings({ "static-access", "empty-statement" })
        public void run() {
            // Outbound Stalling Detector. Only invokes once every 10 secs, CallCenter is Outbound & Running)
            if ((boundMode.equals("Outbound")) && (callCenterStatus == RUNNING)) {
                if ((lastStallerCampaignStat.getConnectingTT() == campaignStat.getConnectingTT())
                        && (lastStallerCampaignStat.getCallingTT() == campaignStat.getCallingTT())) {
                    stalling = true;
                } else {
                    stalling = false;
                }
                try {
                    lastStallerCampaignStat = (CampaignStat) campaignStat.clone();
                } catch (CloneNotSupportedException ex) {
                    /* Nonsens in this case*/ }
            } else if (((boundMode.equals("Outbound"))
                    && ((callCenterStatus == PAUSING) || (callCenterStatus == RERUNBREAK)))) {
                stalling = false;
            }

            // Inbound Stalling Detector. Only invokes once every 10 secs, CallCenter is Inbound & Running)
            if ((boundMode.equals("Inbound"))
                    && ((callCenterStatus == POWERINGON) || (callCenterStatus == POWEREDON))
                    && (callCenterIsNetManaged)) {
                if ((lastStallerCampaignStat.getRingingTT() == campaignStat.getRingingTT())
                        && (lastStallerCampaignStat.getTalkingTT() == campaignStat.getTalkingTT())) {
                    stalling = true;
                } else {
                    stalling = false;
                    stallingCounter = stallingCounterLimit;
                }
                try {
                    lastStallerCampaignStat = (CampaignStat) campaignStat.clone();
                } catch (CloneNotSupportedException ex) {
                    /* Nonsens in this case*/ }
            }

            if ((boundMode.equals("Inbound")) && (stalling) && (callCenterIsNetManaged)) {
                stallingCounter -= Math.round(updateStallerTimerInterval / 1000); // minus StallingInterval seconds
                if (stallingCounter < stallingCounterLimit - 60) {
                    showStatus("Inbound CallCenter Stalling: Shutdown in " + stallingCounter + " Seconds",
                            false, false);
                }
                if (stallingCounter == 0) {
                    showStatus("Inbound CallCenter Stalling: Shutdown Now!", true, true);
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException ex) {
                    }
                    System.exit(0);
                }
            } else if ((!isRegistering) && (boundMode != null) && (boundMode.equals("Inbound"))) {
                if (stallingCounter >= stallingCounterLimit - 60) {
                    statusBar.setText(
                            "Inbound CallCenter Received " + campaignStat.getRingingTT() + " Phone Calls");
                }
            }
            System.gc();
        }
    });
    timedStallingDetectionUpdateThread.setName("timedStallingDetectionUpdateThread");
    timedStallingDetectionUpdateThread.setDaemon(runThreadsAsDaemons);
    timedStallingDetectionUpdateThread.start();
}