Example usage for java.lang Thread MIN_PRIORITY

List of usage examples for java.lang Thread MIN_PRIORITY

Introduction

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

Prototype

int MIN_PRIORITY

To view the source code for java.lang Thread MIN_PRIORITY.

Click Source Link

Document

The minimum priority that a thread can have.

Usage

From source file:org.geowebcache.diskquota.DiskQuotaMonitor.java

private ScheduledExecutorService createCleanUpExecutor() {

    final int numCleaningThreads = quotaConfig.getMaxConcurrentCleanUps();
    log.info("Setting up disk quota periodic enforcement task");
    CustomizableThreadFactory tf = new CustomizableThreadFactory("GWC DiskQuota clean up thread-");
    tf.setThreadPriority(1 + (Thread.MAX_PRIORITY - Thread.MIN_PRIORITY) / 5);

    ScheduledExecutorService executorService = Executors.newScheduledThreadPool(numCleaningThreads, tf);

    return executorService;
}

From source file:org.opendedup.collections.ShardedProgressiveFileBasedCSMap.java

@Override
public synchronized long claimRecords(SDFSEvent evt) throws IOException {
    if (this.isClosed())
        throw new IOException("Hashtable " + this.fileName + " is close");
    executor = new ThreadPoolExecutor(Main.writeThreads + 1, Main.writeThreads + 1, 10, TimeUnit.SECONDS,
            worksQueue, new ProcessPriorityThreadFactory(Thread.MIN_PRIORITY), executionHandler);
    csz = new AtomicLong(0);

    try {/*www  .j  a v a  2s.c  o  m*/
        Lock l = this.gcLock.writeLock();
        l.lock();
        this.runningGC = true;
        try {
            File _fs = new File(fileName);
            lbf = null;
            lbf = new LargeBloomFilter(_fs.getParentFile(), maxSz, .001, true, true, false);
        } finally {
            l.unlock();
        }

        SDFSLogger.getLog().info("Claiming Records [" + this.getSize() + "] from [" + this.fileName + "]");
        SDFSEvent tEvt = SDFSEvent
                .claimInfoEvent("Claiming Records [" + this.getSize() + "] from [" + this.fileName + "]", evt);
        tEvt.maxCt = this.maps.size();
        Iterator<AbstractShard> iter = maps.iterator();
        ArrayList<ClaimShard> excs = new ArrayList<ClaimShard>();
        while (iter.hasNext()) {
            tEvt.curCt++;
            AbstractShard m = null;
            try {
                m = iter.next();
                ClaimShard cms = new ClaimShard(m, csz, lbf);
                excs.add(cms);
                executor.execute(cms);
            } catch (Exception e) {
                tEvt.endEvent("Unable to claim records for " + m + " because : [" + e.toString() + "]",
                        SDFSEvent.ERROR);
                SDFSLogger.getLog().error("Unable to claim records for " + m, e);
                throw new IOException(e);
            }
        }
        executor.shutdown();
        try {
            while (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
                SDFSLogger.getLog().debug("Awaiting fdisk completion of threads.");
            }
        } catch (InterruptedException e) {
            throw new IOException(e);
        }
        for (ClaimShard cms : excs) {
            if (cms.ex != null)
                throw new IOException(cms.ex);
        }
        this.kSz.getAndAdd(-1 * csz.get());
        tEvt.endEvent("removed [" + csz.get() + "] records");
        SDFSLogger.getLog().info("removed [" + csz.get() + "] records");
        iter = maps.iterator();
        while (iter.hasNext()) {
            AbstractShard m = null;
            try {
                m = iter.next();
                if (!m.isFull() && !m.isActive()) {

                    // SDFSLogger.getLog().info("deleting " +
                    // m.toString());
                    m.iterInit();
                    KVPair p = m.nextKeyValue();
                    while (p != null) {
                        AbstractShard _m = this.getWriteMap();
                        try {
                            _m.put(p.key, p.value, p.loc);
                            this.keyLookup.invalidate(new ByteArrayWrapper(p.key));
                            this.lbf.put(p.key);
                            p = m.nextKeyValue();
                        } catch (HashtableFullException e) {

                        }

                    }
                    int mapsz = maps.size();
                    l = this.gcLock.writeLock();
                    l.lock();
                    try {
                        maps.remove(m);
                    } finally {
                        l.unlock();
                    }
                    mapsz = mapsz - maps.size();
                    SDFSLogger.getLog()
                            .info("removing map " + m.toString() + " sz=" + maps.size() + " rm=" + mapsz);
                    m.vanish();

                    m = null;
                } else if (m.isMaxed()) {
                    SDFSLogger.getLog().info("deleting maxed " + m.toString());
                    m.iterInit();
                    KVPair p = m.nextKeyValue();
                    while (p != null) {
                        ShardedFileByteArrayLongMap _m = this.getWriteMap();
                        try {
                            _m.put(p.key, p.value, p.loc);
                            p = m.nextKeyValue();
                        } catch (HashtableFullException e) {

                        }

                    }
                    int mapsz = maps.size();
                    l = this.gcLock.writeLock();
                    l.lock();
                    try {
                        maps.remove(m);
                    } finally {
                        l.unlock();
                    }
                    mapsz = mapsz - maps.size();
                    SDFSLogger.getLog()
                            .info("removing map " + m.toString() + " sz=" + maps.size() + " rm=" + mapsz);
                    m.vanish();

                    m = null;
                }
            } catch (Exception e) {
                tEvt.endEvent("Unable to compact " + m + " because : [" + e.toString() + "]", SDFSEvent.ERROR);
                SDFSLogger.getLog().error("to compact " + m, e);
                throw new IOException(e);
            }
        }
        l.lock();
        this.runningGC = false;
        l.unlock();
        return csz.get();
    } finally {
        executor = null;
    }
}

From source file:WorkThreadPool.java

public WorkThread(WorkThreadPool pool, ThreadGroup group, String name) {
    super(group, name);
    // so that jEdit doesn't exit with no views open automatically
    // setDaemon(true);
    setPriority(Thread.MIN_PRIORITY);

    this.pool = pool;
}

From source file:gate.corpora.CSVImporter.java

@Override
protected List<Action> buildActions(final NameBearerHandle handle) {
    List<Action> actions = new ArrayList<Action>();

    if (!(handle.getTarget() instanceof Corpus))
        return actions;

    actions.add(new AbstractAction("Populate from CSV File") {
        @Override/*ww w .j a  va  2s.  c o  m*/
        public void actionPerformed(ActionEvent e) {

            // display the populater dialog and return if it is cancelled
            if (JOptionPane.showConfirmDialog(null, dialog, "Populate From CSV File",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) != JOptionPane.OK_OPTION)
                return;

            // we want to run the population in a separate thread so we don't lock
            // up the GUI
            Thread thread = new Thread(Thread.currentThread().getThreadGroup(), "CSV Corpus Populater") {

                public void run() {
                    try {

                        // unescape the strings that define the format of the file and
                        // get the actual chars
                        char separator = StringEscapeUtils.unescapeJava(txtSeparator.getText()).charAt(0);
                        char quote = StringEscapeUtils.unescapeJava(txtQuoteChar.getText()).charAt(0);

                        // see if we can convert the URL to a File instance
                        File file = null;
                        try {
                            file = Files.fileFromURL(new URL(txtURL.getText()));
                        } catch (IllegalArgumentException iae) {
                            // this will happen if someone enters an actual URL, but we
                            // handle that later so we can just ignore the exception for
                            // now and keep going
                        }

                        if (file != null && file.isDirectory()) {
                            // if we have a File instance and that points at a directory
                            // then....

                            // get all the CSV files in the directory structure
                            File[] files = Files.listFilesRecursively(file, CSV_FILE_FILTER);

                            for (File f : files) {
                                // for each file...

                                // skip directories as we don't want to handle those
                                if (f.isDirectory())
                                    continue;

                                if (cboDocuments.isSelected()) {
                                    // if we are creating lots of documents from a single
                                    // file
                                    // then call the populate method passing through all the
                                    // options from the GUI
                                    populate((Corpus) handle.getTarget(), f.toURI().toURL(),
                                            txtEncoding.getText(), (Integer) textColModel.getValue(),
                                            cboFeatures.isSelected(), separator, quote);
                                } else {
                                    // if we are creating a single document from a single
                                    // file
                                    // then call the createDoc method passing through all
                                    // the
                                    // options from the GUI
                                    createDoc((Corpus) handle.getTarget(), f.toURI().toURL(),
                                            txtEncoding.getText(), (Integer) textColModel.getValue(),
                                            cboFeatures.isSelected(), separator, quote);
                                }
                            }
                        } else {
                            // we have a single URL to process so...

                            if (cboDocuments.isSelected()) {
                                // if we are creating lots of documents from a single file
                                // then call the populate method passing through all the
                                // options from the GUI
                                populate((Corpus) handle.getTarget(), new URL(txtURL.getText()),
                                        txtEncoding.getText(), (Integer) textColModel.getValue(),
                                        cboFeatures.isSelected(), separator, quote);
                            } else {
                                // if we are creating a single document from a single file
                                // then call the createDoc method passing through all the
                                // options from the GUI
                                createDoc((Corpus) handle.getTarget(), new URL(txtURL.getText()),
                                        txtEncoding.getText(), (Integer) textColModel.getValue(),
                                        cboFeatures.isSelected(), separator, quote);
                            }
                        }
                    } catch (Exception e) {
                        // TODO give a sensible error message
                        e.printStackTrace();
                    }
                }
            };

            // let's leave the GUI nice and responsive
            thread.setPriority(Thread.MIN_PRIORITY);

            // lets get to it and do some actual work!
            thread.start();

        }
    });

    return actions;
}

From source file:com.brsanthu.googleanalytics.GoogleAnalytics.java

public Thread newThread(Runnable r) {
    Thread thread = new Thread(Thread.currentThread().getThreadGroup(), r,
            MessageFormat.format(threadNameFormat, threadNumber.getAndIncrement()), 0);
    thread.setDaemon(true);//  ww w  . j  a v a 2  s.  co  m
    thread.setPriority(Thread.MIN_PRIORITY);
    return thread;
}

From source file:org.apache.jackrabbit.core.RepositoryImpl.java

/**
 * private constructor// ww  w .j  a va2 s .  co m
 *
 * @param repConfig
 */
protected RepositoryImpl(RepositoryConfig repConfig) throws RepositoryException {

    log.info("Starting repository...");

    boolean succeeded = false;
    try {
        this.repConfig = repConfig;

        // Acquire a lock on the repository home
        repLock = new RepositoryLock(repConfig.getHomeDir());
        repLock.acquire();

        // setup file systems
        repStore = repConfig.getFileSystemConfig().createFileSystem();
        String fsRootPath = "/meta";
        try {
            if (!repStore.exists(fsRootPath) || !repStore.isFolder(fsRootPath)) {
                repStore.createFolder(fsRootPath);
            }
        } catch (FileSystemException fse) {
            String msg = "failed to create folder for repository meta data";
            log.error(msg, fse);
            throw new RepositoryException(msg, fse);
        }
        metaDataStore = new BasedFileSystem(repStore, fsRootPath);

        // init root node uuid
        rootNodeId = loadRootNodeId(metaDataStore);

        // load repository properties
        repProps = loadRepProps();
        nodesCount = Long.parseLong(repProps.getProperty(STATS_NODE_COUNT_PROPERTY, "0"));
        propsCount = Long.parseLong(repProps.getProperty(STATS_PROP_COUNT_PROPERTY, "0"));

        // create registries
        nsReg = createNamespaceRegistry(new BasedFileSystem(repStore, "/namespaces"));
        ntReg = createNodeTypeRegistry(nsReg, new BasedFileSystem(repStore, "/nodetypes"));

        if (repConfig.getDataStoreConfig() != null) {
            assert InternalValue.USE_DATA_STORE;
            dataStore = createDataStore();
        } else {
            dataStore = null;
        }

        // init workspace configs
        Iterator iter = repConfig.getWorkspaceConfigs().iterator();
        while (iter.hasNext()) {
            WorkspaceConfig config = (WorkspaceConfig) iter.next();
            WorkspaceInfo info = createWorkspaceInfo(config);
            wspInfos.put(config.getName(), info);
        }

        // initialize optional clustering
        // put here before setting up any other external event source that a cluster node
        // will be interested in
        if (repConfig.getClusterConfig() != null) {
            clusterNode = createClusterNode();
            nsReg.setEventChannel(clusterNode);
            ntReg.setEventChannel(clusterNode);
        }

        // init version manager
        vMgr = createVersionManager(repConfig.getVersioningConfig(), delegatingDispatcher);
        if (clusterNode != null) {
            vMgr.setEventChannel(clusterNode.createUpdateChannel(null));
        }

        // init virtual node type manager
        virtNTMgr = new VirtualNodeTypeStateManager(getNodeTypeRegistry(), delegatingDispatcher,
                NODETYPES_NODE_ID, SYSTEM_ROOT_NODE_ID);

        // initialize startup workspaces
        initStartupWorkspaces();

        // initialize system search manager
        getSystemSearchManager(repConfig.getDefaultWorkspaceName());

        // after the workspace is initialized we pass a system session to
        // the virtual node type manager

        // todo FIXME the *global* virtual node type manager is using a session that is bound to a single specific workspace...
        virtNTMgr.setSession(getSystemSession(repConfig.getDefaultWorkspaceName()));

        // now start cluster node as last step
        if (clusterNode != null) {
            try {
                clusterNode.start();
            } catch (ClusterException e) {
                String msg = "Unable to start clustered node, forcing shutdown...";
                log.error(msg, e);
                shutdown();
                throw new RepositoryException(msg, e);
            }
        }

        // amount of time in seconds before an idle workspace is automatically
        // shut down
        int maxIdleTime = repConfig.getWorkspaceMaxIdleTime();
        if (maxIdleTime != 0) {
            // start workspace janitor thread
            Thread wspJanitor = new Thread(new WorkspaceJanitor(maxIdleTime * 1000));
            wspJanitor.setName("WorkspaceJanitor");
            wspJanitor.setPriority(Thread.MIN_PRIORITY);
            wspJanitor.setDaemon(true);
            wspJanitor.start();
        }

        succeeded = true;
        log.info("Repository started");
    } catch (RepositoryException e) {
        log.error("failed to start Repository: " + e.getMessage(), e);
        throw e;
    } finally {
        if (!succeeded) {
            // repository startup failed, clean up...
            shutdown();
        }
    }
}

From source file:tvbrowser.extras.reminderplugin.ReminderSettingsTab.java

/**
 * Creates the settings panel for this tab.
 *//*from w w  w .  j  a  v a  2  s . c o  m*/
public JPanel createSettingsPanel() {
    FormLayout layout = new FormLayout("5dlu,pref,5dlu,pref,pref:grow,3dlu,pref,3dlu,pref,5dlu",
            "pref,5dlu,pref,1dlu,pref,1dlu,pref,1dlu,pref,10dlu,pref,5dlu,"
                    + "pref,10dlu,pref,5dlu,pref,10dlu,pref,5dlu,pref,10dlu,"
                    + "pref,5dlu,pref,3dlu,pref,10dlu,pref,5dlu,pref");
    layout.setColumnGroups(new int[][] { { 7, 9 } });
    PanelBuilder pb = new PanelBuilder(layout, new ScrollableJPanel());
    pb.setDefaultDialogBorder();

    CellConstraints cc = new CellConstraints();

    final String[] extArr = { ".wav", ".aif", ".rmf", ".au", ".mid" };
    String soundFName = mSettings.getProperty("soundfile", "/");
    String msg = mLocalizer.msg("soundFileFilter", "Sound file ({0})", "*" + StringUtils.join(extArr, ", *"));

    mReminderWindowChB = new JCheckBox(mLocalizer.msg("reminderWindow", "Reminder window"),
            mSettings.getProperty("usemsgbox", "false").equalsIgnoreCase("true"));

    mShowAlwaysOnTop = new JCheckBox(mLocalizer.msg("alwaysOnTop", "Show always on top"),
            mSettings.getProperty("alwaysOnTop", "true").equalsIgnoreCase("true"));
    mShowAlwaysOnTop.setEnabled(mReminderWindowChB.isSelected());

    JPanel reminderWindowCfg = new JPanel(new FormLayout("12dlu,default:grow", "pref,1dlu,pref"));
    reminderWindowCfg.add(mReminderWindowChB, cc.xyw(1, 1, 2));
    reminderWindowCfg.add(mShowAlwaysOnTop, cc.xy(2, 3));

    mSoundFileChB = new FileCheckBox(mLocalizer.msg("playlingSound", "Play sound"), new File(soundFName), 0,
            false);

    JFileChooser soundChooser = new JFileChooser((String) null);
    soundChooser.setFileFilter(new ExtensionFileFilter(extArr, msg));

    mSoundFileChB.setFileChooser(soundChooser);

    mSoundFileChB.setSelected(mSettings.getProperty("usesound", "false").equals("true"));

    mBeep = new JCheckBox(mLocalizer.msg("beep", "Speaker sound"),
            mSettings.getProperty("usebeep", "true").equalsIgnoreCase("true"));

    mExecFileStr = mSettings.getProperty("execfile", "");
    mExecParamStr = mSettings.getProperty("execparam", "");

    final JButton soundTestBt = new JButton(mLocalizer.msg("test", "Test"));

    mExecChB = new JCheckBox(mLocalizer.msg("executeProgram", "Execute program"));
    mExecChB.setSelected(mSettings.getProperty("useexec", "false").equals("true"));

    mExecFileDialogBtn = new JButton(mLocalizer.msg("executeConfig", "Configure"));
    mExecFileDialogBtn.setEnabled(mExecChB.isSelected());

    mPluginLabel = new JLabel();
    JButton choose = new JButton(mLocalizer.msg("selectPlugins", "Choose Plugins"));

    mClientPluginTargets = ReminderPlugin.getInstance().getClientPluginsTargets();

    handlePluginSelection();

    choose.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Window parent = UiUtilities.getLastModalChildOf(MainFrame.getInstance());
                PluginChooserDlg chooser = null;
                chooser = new PluginChooserDlg(parent, mClientPluginTargets, null,
                        ReminderPluginProxy.getInstance());

                chooser.setLocationRelativeTo(parent);
                chooser.setVisible(true);

                if (chooser.getReceiveTargets() != null) {
                    mClientPluginTargets = chooser.getReceiveTargets();
                }

                handlePluginSelection();
            } catch (Exception ee) {
                ee.printStackTrace();
            }
        }
    });

    int autoCloseReminderTime = 10;
    try {
        String asString = mSettings.getProperty("autoCloseReminderTime", "10");
        autoCloseReminderTime = Integer.parseInt(asString);

        if (autoCloseReminderTime == 0) {
            autoCloseReminderTime = 10;
        }
    } catch (Exception exc) {
        // ignore
    }

    mCloseOnEnd = new JRadioButton(mLocalizer.msg("autoCloseReminderAtProgramEnd", "Program end"),
            mSettings.getProperty("autoCloseBehaviour", "onEnd").equals("onEnd"));
    mCloseOnEnd.setEnabled(mReminderWindowChB.isSelected());

    mCloseNever = new JRadioButton(mLocalizer.msg("autoCloseNever", "Never close"),
            mSettings.getProperty("autoCloseBehaviour", "onEnd").equals("never"));
    mCloseNever.setEnabled(mReminderWindowChB.isSelected());

    mCloseOnTime = new JRadioButton(mLocalizer.ellipsisMsg("autoCloseAfterTime", "After time"),
            mSettings.getProperty("autoCloseBehaviour", "onEnd").equals("onTime"));
    mCloseOnTime.setEnabled(mReminderWindowChB.isSelected());

    ButtonGroup bg = new ButtonGroup();

    bg.add(mCloseOnEnd);
    bg.add(mCloseNever);
    bg.add(mCloseOnTime);

    mAutoCloseReminderTimeSp = new JSpinner(
            new SpinnerNumberModel(autoCloseReminderTime, autoCloseReminderTime < 5 ? 1 : 5, 600, 1));
    mAutoCloseReminderTimeSp.setEnabled(mCloseOnTime.isSelected() && mReminderWindowChB.isSelected());

    mShowTimeCounter = new JCheckBox(mLocalizer.msg("showTimeCounter", "Show time counter"),
            mSettings.getProperty("showTimeCounter", "false").compareTo("true") == 0);
    mShowTimeCounter.setEnabled(!mCloseNever.isSelected() && mReminderWindowChB.isSelected());

    PanelBuilder autoClosePanel = new PanelBuilder(
            new FormLayout("12dlu,default,2dlu,default:grow", "pref,2dlu,pref,2dlu,pref,2dlu,pref,10dlu,pref"));
    autoClosePanel.add(mCloseOnEnd, cc.xyw(1, 1, 4));
    autoClosePanel.add(mCloseNever, cc.xyw(1, 3, 4));
    autoClosePanel.add(mCloseOnTime, cc.xyw(1, 5, 4));
    autoClosePanel.add(mAutoCloseReminderTimeSp, cc.xy(2, 7));

    final JLabel secondsLabel = autoClosePanel.addLabel(mLocalizer.msg("seconds", "seconds (0 = off)"),
            cc.xy(4, 7));

    autoClosePanel.add(mShowTimeCounter, cc.xyw(1, 9, 4));

    secondsLabel.setEnabled(mCloseOnTime.isSelected() && mReminderWindowChB.isSelected());

    String defaultReminderEntryStr = (String) mSettings.get("defaultReminderEntry");
    mDefaultReminderEntryList = new JComboBox(ReminderDialog.SMALL_REMIND_MSG_ARR);
    if (defaultReminderEntryStr != null) {
        try {
            int inx = Integer.parseInt(defaultReminderEntryStr);
            if (inx < ReminderDialog.SMALL_REMIND_MSG_ARR.length) {
                mDefaultReminderEntryList.setSelectedIndex(inx);
            }
        } catch (NumberFormatException e) {
            // ignore
        }
    }

    mShowTimeSelectionDlg = new JCheckBox(
            mLocalizer.msg("showTimeSelectionDialog", "Show time selection dialog"));
    mShowTimeSelectionDlg
            .setSelected(mSettings.getProperty("showTimeSelectionDialog", "true").compareTo("true") == 0);
    mShowRemovedDlg = new JCheckBox(
            mLocalizer.msg("showRemovedDialog", "Show removed reminders after data update"));
    mShowRemovedDlg.setSelected(mSettings.getProperty("showRemovedDialog", "true").compareTo("true") == 0);

    pb.addSeparator(mLocalizer.msg("remindBy", "Remind me by"), cc.xyw(1, 1, 10));

    pb.add(reminderWindowCfg, cc.xyw(2, 3, 4));
    pb.add(mSoundFileChB, cc.xyw(2, 5, 4));
    pb.add(mSoundFileChB.getButton(), cc.xy(7, 5));
    pb.add(soundTestBt, cc.xy(9, 5));
    pb.add(mBeep, cc.xy(2, 7));
    pb.add(mExecChB, cc.xyw(2, 9, 4));
    pb.add(mExecFileDialogBtn, cc.xyw(7, 9, 3));

    pb.addSeparator(mLocalizer.msg("sendToPlugin", "Send reminded program to"), cc.xyw(1, 11, 10));

    pb.add(mPluginLabel, cc.xyw(2, 13, 4));
    pb.add(choose, cc.xyw(7, 13, 3));

    final JLabel c = (JLabel) pb
            .addSeparator(mLocalizer.msg("autoCloseReminder", "Automatically close reminder"),
                    cc.xyw(1, 15, 10))
            .getComponent(0);
    c.setEnabled(mReminderWindowChB.isSelected());

    pb.add(autoClosePanel.getPanel(), cc.xyw(2, 17, 5));

    JPanel reminderEntry = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    reminderEntry.add(mDefaultReminderEntryList);

    pb.addSeparator(mLocalizer.msg("defaltReminderEntry", "Default reminder time"), cc.xyw(1, 19, 10));
    pb.add(reminderEntry, cc.xyw(2, 21, 4));

    pb.addSeparator(mLocalizer.msg("miscSettings", "Misc settings"), cc.xyw(1, 23, 10));
    pb.add(mShowTimeSelectionDlg, cc.xyw(2, 25, 7));
    pb.add(mShowRemovedDlg, cc.xyw(2, 27, 7));

    pb.addSeparator(DefaultMarkingPrioritySelectionPanel.getTitle(), cc.xyw(1, 29, 10));
    pb.add(mMarkingsPanel = DefaultMarkingPrioritySelectionPanel
            .createPanel(ReminderPlugin.getInstance().getMarkPriority(), false, false), cc.xyw(2, 31, 9));

    mReminderWindowChB.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            mShowAlwaysOnTop.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
            c.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
            secondsLabel.setEnabled(e.getStateChange() == ItemEvent.SELECTED && mCloseOnTime.isSelected());
            mCloseOnEnd.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
            mCloseNever.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
            mCloseOnTime.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
            mShowTimeCounter.setEnabled(e.getStateChange() == ItemEvent.SELECTED && !mCloseNever.isSelected());
            mAutoCloseReminderTimeSp
                    .setEnabled(e.getStateChange() == ItemEvent.SELECTED && mCloseOnTime.isSelected());
        }
    });

    soundTestBt.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (evt.getActionCommand().compareTo(mLocalizer.msg("test", "Test")) == 0) {
                mTestSound = ReminderPlugin.playSound(mSoundFileChB.getTextField().getText());
                if (mTestSound != null) {
                    soundTestBt.setText(mLocalizer.msg("stop", "Stop"));
                }
                if (mTestSound != null) {
                    if (mTestSound instanceof SourceDataLine) {
                        ((SourceDataLine) mTestSound).addLineListener(new LineListener() {
                            public void update(LineEvent event) {
                                if (event.getType() == Type.CLOSE) {
                                    soundTestBt.setText(mLocalizer.msg("test", "Test"));
                                }
                            }
                        });
                    } else if (mTestSound instanceof Sequencer) {
                        new Thread("Test MIDI sound") {
                            public void run() {
                                setPriority(Thread.MIN_PRIORITY);
                                while (((Sequencer) mTestSound).isRunning()) {
                                    try {
                                        Thread.sleep(100);
                                    } catch (Exception ee) {
                                    }
                                }

                                soundTestBt.setText(mLocalizer.msg("test", "Test"));
                            }
                        }.start();
                    }
                }
            } else if (mTestSound != null) {
                if (mTestSound instanceof SourceDataLine && ((SourceDataLine) mTestSound).isRunning()) {
                    ((SourceDataLine) mTestSound).stop();
                } else if (mTestSound instanceof Sequencer && ((Sequencer) mTestSound).isRunning()) {
                    ((Sequencer) mTestSound).stop();
                }
            }
        }
    });

    mSoundFileChB.getCheckBox().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            soundTestBt.setEnabled(mSoundFileChB.isSelected());
        }
    });

    mSoundFileChB.getTextField().addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            String text = mSoundFileChB.getTextField().getText();
            if ((new File(text)).isFile()) {
                boolean notFound = true;
                for (String extension : extArr) {
                    if (StringUtils.endsWithIgnoreCase(text, extension)) {
                        notFound = false;
                        break;
                    }
                }

                if (notFound) {
                    soundTestBt.setEnabled(false);
                } else {
                    soundTestBt.setEnabled(true);
                }
            } else {
                soundTestBt.setEnabled(false);
            }
        }
    });
    mSoundFileChB.getTextField().getKeyListeners()[0].keyReleased(null);

    mExecChB.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            mExecFileDialogBtn.setEnabled(mExecChB.isSelected());
            if (mExecFileDialogBtn.isEnabled()) {
                showFileSettingsDialog();
            }
        }
    });

    mExecFileDialogBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showFileSettingsDialog();
        }
    });

    ItemListener autoCloseListener = new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            mAutoCloseReminderTimeSp.setEnabled(mCloseOnTime.isSelected());
            secondsLabel.setEnabled(mCloseOnTime.isSelected());
            mShowTimeCounter.setEnabled(mCloseOnTime.isSelected() || mCloseOnEnd.isSelected());
        }
    };

    mCloseOnEnd.addItemListener(autoCloseListener);
    mCloseOnTime.addItemListener(autoCloseListener);

    mCloseOnTime.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            mShowTimeCounter.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    JScrollPane scrollPane = new JScrollPane(pb.getPanel());
    scrollPane.setBorder(null);
    scrollPane.setViewportBorder(null);

    JPanel scrollPanel = new JPanel(new FormLayout("default:grow", "default"));
    scrollPanel.add(scrollPane, cc.xy(1, 1));

    return scrollPanel;
}

From source file:org.apache.jackrabbit.core.RepositoryImpl.java

/**
 * private constructor/*w w  w. j a v a  2 s . com*/
 *
 * @param repConfig
 */
protected RepositoryImpl(RepositoryConfig repConfig) throws RepositoryException {

    log.info("Starting repository...");

    boolean succeeded = false;
    try {
        this.repConfig = repConfig;

        // Acquire a lock on the repository home
        repLock = new RepositoryLock(repConfig.getHomeDir());
        repLock.acquire();

        // setup file systems
        repStore = repConfig.getFileSystem();
        String fsRootPath = "/meta";
        try {
            if (!repStore.exists(fsRootPath) || !repStore.isFolder(fsRootPath)) {
                repStore.createFolder(fsRootPath);
            }
        } catch (FileSystemException fse) {
            String msg = "failed to create folder for repository meta data";
            log.error(msg, fse);
            throw new RepositoryException(msg, fse);
        }
        metaDataStore = new BasedFileSystem(repStore, fsRootPath);

        // init root node uuid
        rootNodeId = loadRootNodeId(metaDataStore);

        // load repository properties
        repProps = loadRepProps();
        nodesCount = Long.parseLong(repProps.getProperty(STATS_NODE_COUNT_PROPERTY, "0"));
        propsCount = Long.parseLong(repProps.getProperty(STATS_PROP_COUNT_PROPERTY, "0"));

        // create registries
        nsReg = createNamespaceRegistry(new BasedFileSystem(repStore, "/namespaces"));
        ntReg = createNodeTypeRegistry(nsReg, new BasedFileSystem(repStore, "/nodetypes"));

        dataStore = repConfig.getDataStore();
        if (dataStore != null) {
            assert InternalValue.USE_DATA_STORE;
        }

        // init workspace configs
        Iterator iter = repConfig.getWorkspaceConfigs().iterator();
        while (iter.hasNext()) {
            WorkspaceConfig config = (WorkspaceConfig) iter.next();
            WorkspaceInfo info = createWorkspaceInfo(config);
            wspInfos.put(config.getName(), info);
        }

        // initialize optional clustering
        // put here before setting up any other external event source that a cluster node
        // will be interested in
        if (repConfig.getClusterConfig() != null) {
            clusterNode = createClusterNode();
            nsReg.setEventChannel(clusterNode);
            ntReg.setEventChannel(clusterNode);

            createWorkspaceEventChannel = clusterNode;
            clusterNode.setListener(this);
        }

        // init version manager
        vMgr = createVersionManager(repConfig.getVersioningConfig(), delegatingDispatcher);
        if (clusterNode != null) {
            vMgr.setEventChannel(clusterNode.createUpdateChannel(null));
        }

        // init virtual node type manager
        virtNTMgr = new VirtualNodeTypeStateManager(getNodeTypeRegistry(), delegatingDispatcher,
                NODETYPES_NODE_ID, SYSTEM_ROOT_NODE_ID);

        // initialize startup workspaces
        initStartupWorkspaces();

        // initialize system search manager
        getSystemSearchManager(repConfig.getDefaultWorkspaceName());

        // after the workspace is initialized we pass a system session to
        // the virtual node type manager

        // todo FIXME the *global* virtual node type manager is using a session that is bound to a single specific workspace...
        virtNTMgr.setSession(getSystemSession(repConfig.getDefaultWorkspaceName()));

        // now start cluster node as last step
        if (clusterNode != null) {
            try {
                clusterNode.start();
            } catch (ClusterException e) {
                String msg = "Unable to start clustered node, forcing shutdown...";
                log.error(msg, e);
                shutdown();
                throw new RepositoryException(msg, e);
            }
        }

        // amount of time in seconds before an idle workspace is automatically
        // shut down
        int maxIdleTime = repConfig.getWorkspaceMaxIdleTime();
        if (maxIdleTime != 0) {
            // start workspace janitor thread
            Thread wspJanitor = new Thread(new WorkspaceJanitor(maxIdleTime * 1000));
            wspJanitor.setName("WorkspaceJanitor");
            wspJanitor.setPriority(Thread.MIN_PRIORITY);
            wspJanitor.setDaemon(true);
            wspJanitor.start();
        }

        succeeded = true;
        log.info("Repository started");
    } catch (RepositoryException e) {
        log.error("failed to start Repository: " + e.getMessage(), e);
        throw e;
    } finally {
        if (!succeeded) {
            // repository startup failed, clean up...
            shutdown();
        }
    }
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProviderService.java

private ExecutorService createExecutor() {
    ThreadPoolExecutor executor = new ThreadPoolExecutor(0, 5, 60L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
                private final AtomicInteger counter = new AtomicInteger();
                private final Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
                    @Override/*from   w ww .ja va 2s  . c om*/
                    public void uncaughtException(Thread t, Throwable e) {
                        log.warn("Error occurred in asynchronous processing ", e);
                    }
                };

                @Override
                public Thread newThread(@Nonnull Runnable r) {
                    Thread thread = new Thread(r, createName());
                    thread.setDaemon(true);
                    thread.setPriority(Thread.MIN_PRIORITY);
                    thread.setUncaughtExceptionHandler(handler);
                    return thread;
                }

                private String createName() {
                    return "oak-lucene-" + counter.getAndIncrement();
                }
            });
    executor.setKeepAliveTime(1, TimeUnit.MINUTES);
    executor.allowCoreThreadTimeOut(true);
    return executor;
}

From source file:biz.gabrys.maven.plugins.lesscss.CompileMojo.java

private void runWatchMode() throws MojoFailureException {
    getLog().info("Starts watch mode on the " + sourceDirectory);
    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    final long interval = watchInterval * 1000L;
    while (true) {
        runCompilation();/*from  w  w w. java2  s  .c om*/
        try {
            Thread.sleep(interval);
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
            return;
        }
    }
}