Example usage for java.util NoSuchElementException printStackTrace

List of usage examples for java.util NoSuchElementException printStackTrace

Introduction

In this page you can find the example usage for java.util NoSuchElementException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.spring.springxdcloudInstaller.MainApp.java

private static void destroySecurityGroupKeyPairAndInstance(EC2Client client, String name) {
    try {// w w w .j  a  v a2 s .  c  om
        String id = findInstanceByKeyName(client, name).getId();
        System.out.printf("%d: %s terminating instance%n", System.currentTimeMillis(), id);
        client.getInstanceServices().terminateInstancesInRegion(null,
                findInstanceByKeyName(client, name).getId());
    } catch (NoSuchElementException e) {
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        System.out.printf("%d: %s deleting keypair%n", System.currentTimeMillis(), name);
        client.getKeyPairServices().deleteKeyPairInRegion(null, name);
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        System.out.printf("%d: %s deleting group%n", System.currentTimeMillis(), name);
        client.getSecurityGroupServices().deleteSecurityGroupInRegion(null, name);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.stainlesscode.mediapipeline.demux.EventAwareSimpleDemultiplexer.java

public void run() {
    while (!isMarkedForDeath()) {
        if (engineRuntime.isPaused())
            continue;
        try {/*ww w .  j av a  2  s.  co  m*/
            demultiplexerLoop();
        } catch (NoSuchElementException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    LogUtil.info("thread shutting down gracefully");
}

From source file:org.kalypso.ui.repository.RepositoryDumper.java

/**
 * Creates the dump structure in the file-system and into one structure file <br/>
 * REMARK: this uses the file format which is compatible to the Kalypso-PSICompact-Fake implementation. So exported
 * repositories can directly be included via that repository implementation.
 * //from  www. j  av a2s . co m
 * @param structureWriter
 * @param directory
 *          The choosen directory.
 * @param monitor
 *          A progress monitor.
 * @throws InterruptedException
 * @throws RepositoryException
 */
private void dumpExtendedRecursive(final Writer structureWriter, final File directory,
        final IRepositoryItem item, final IProgressMonitor monitor)
        throws InterruptedException, RepositoryException, IOException {
    /* If the user canceled the operation, abort. */
    if (monitor.isCanceled())
        throw new InterruptedException();

    try {
        /* Write entry for structure file */
        final String identifier = item.getIdentifier();
        monitor.subTask(identifier);

        /* The name will be used as filename. */
        final String name = FileUtilities.resolveValidFileName(item.getName());
        final File zmlFile = new File(directory, name + ".zml"); //$NON-NLS-1$

        dumpItem(structureWriter, zmlFile, item);

        /* This is the directory, where the children are placed. */
        final File newDirectory = new File(directory, name);
        FileUtils.forceMkdir(newDirectory);

        final IRepositoryItem[] items = item.getChildren();
        if (items != null) {
            for (final IRepositoryItem item2 : items)
                dumpExtendedRecursive(structureWriter, newDirectory, item2, monitor);
        }

        monitor.worked(1);
    } catch (final NoSuchElementException ex) {
        ex.printStackTrace();

        final String msg = String.format(Messages.getString("RepositoryDumper.3"), item.getName()); //$NON-NLS-1$
        m_stati.add(IStatus.ERROR, msg, ex);
    } finally {
        monitor.worked(1);
    }
}

From source file:VASSAL.chat.CgiServerStatus.java

private ServerStatus.ModuleSummary[] getHistory(long time) {
    if (time <= 0)
        return getStatus();

    final long now = System.currentTimeMillis();

    // start with new interval
    final LongRange req = new LongRange(now - time, now);
    final ArrayList<LongRange> toRequest = new ArrayList<LongRange>();
    toRequest.add(req);//from  www .java 2 s.  c  o  m

    // subtract each old interval from new interval
    for (LongRange y : requests) {
        for (ListIterator<LongRange> i = toRequest.listIterator(); i.hasNext();) {
            final LongRange x = i.next();

            if (!x.overlapsRange(y))
                continue; // no overlap, nothing to subtract

            // otherwise, remove x and add what remains after subtracting y
            i.remove();

            final long xl = x.getMinimumLong();
            final long xr = x.getMaximumLong();
            final long yl = y.getMinimumLong();
            final long yr = y.getMaximumLong();

            if (xl < yl && yl <= xr)
                i.add(new LongRange(xl, yl));
            if (xl <= yr && yr < xr)
                i.add(new LongRange(yr, xr));
        }
    }

    // now toRequest contains the intervals we are missing; request those
    for (LongRange i : toRequest) {
        for (String s : getInterval(i)) {
            final SequenceEncoder.Decoder st = new SequenceEncoder.Decoder(s, '\t');
            try {
                final String moduleName = st.nextToken();
                final String roomName = st.nextToken();
                final String playerName = st.nextToken();
                final Long when = Long.valueOf(st.nextToken());

                List<String[]> l = records.get(when);
                if (l == null) {
                    l = new ArrayList<String[]>();
                    records.put(when, l);
                }

                l.add(new String[] { moduleName, roomName, playerName });
            }
            // FIXME: review error message
            catch (NoSuchElementException e) {
                e.printStackTrace();
            }
            // FIXME: review error message
            catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }

        requests.add(i);
    }

    // Join intervals to minimize the number we store.
    // Note: This is simple, but quadratic in the number of intervals.
    // For large numbers of intervals, use an interval tree instead.
    for (int i = 0; i < requests.size(); i++) {
        final LongRange a = requests.get(i);
        for (int j = i + 1; j < requests.size(); j++) {
            final LongRange b = requests.get(j);
            if (a.overlapsRange(b)) {
                final long al = a.getMinimumLong();
                final long ar = a.getMaximumLong();
                final long bl = b.getMinimumLong();
                final long br = b.getMaximumLong();

                requests.set(i, new LongRange(Math.min(al, bl), Math.max(ar, br)));
                requests.remove(j--);
            }
        }
    }

    // pull what we need from the records
    final HashMap<String, ServerStatus.ModuleSummary> entries = new HashMap<String, ServerStatus.ModuleSummary>();

    for (List<String[]> l : records.subMap(req.getMinimumLong(), req.getMaximumLong()).values()) {
        for (String[] r : l) {
            final String moduleName = r[0];
            final String roomName = r[1];
            final String playerName = r[2];

            final ServerStatus.ModuleSummary entry = entries.get(moduleName);
            if (entry == null) {
                entries.put(moduleName, createEntry(moduleName, roomName, playerName));
            } else {
                updateEntry(entry, roomName, playerName);
            }
        }
    }

    return sortEntriesByModuleName(entries);
}

From source file:psidev.psi.mi.filemakers.xmlMaker.XmlMakerGui.java

private void load(File mappingFile) {
    try {/*from   www . jav  a 2  s.c om*/
        FileInputStream fin = new FileInputStream(mappingFile);

        Utils.lastVisitedDirectory = mappingFile.getPath();
        Utils.lastVisitedMappingDirectory = mappingFile.getPath();
        //Utils.lastMappingFile = mappingFile.getName();
        // Create XML encoder.
        XMLDecoder xdec = new XMLDecoder(fin);

        /* get mapping */
        Mapping mapping = (Mapping) xdec.readObject();

        /* flat files */
        flatFileTabbedPanel.flatFileContainer.flatFiles = new ArrayList();

        for (int i = 0; i < mapping.flatFiles.size(); i++) {
            FlatFileMapping ffm = (FlatFileMapping) mapping.flatFiles.get(i);
            FlatFile f = new FlatFile();
            if (ffm != null) {
                f.lineSeparator = ffm.lineSeparator;
                f.firstLineForTitles = ffm.fisrtLineForTitle;
                f.setSeparators(ffm.getSeparators());

                try {
                    URL url = new File(ffm.getFileURL()).toURL();
                    if (url != null)
                        f.load(url);
                } catch (FileNotFoundException fe) {
                    JOptionPane.showMessageDialog(new JFrame(), "Unable to load file" + ffm.getFileURL(),
                            "[PSI makers: PSI maker] load flat file", JOptionPane.ERROR_MESSAGE);
                }
            }
            treePanel.flatFileTabbedPanel.flatFileContainer.addFlatFile(f);
        }
        treePanel.flatFileTabbedPanel.reload();

        /* dictionaries */
        dictionnaryLists.dictionaries.dictionaries = new ArrayList();

        for (int i = 0; i < mapping.getDictionaries().size(); i++) {
            DictionaryMapping dm = (DictionaryMapping) mapping.getDictionaries().get(i);
            Dictionary d = new Dictionary();

            try {
                URL url = null;
                if (dm.getFileURL() != null)
                    url = new File(dm.getFileURL()).toURL();
                if (url != null)
                    d = new Dictionary(url, dm.getSeparator(), dm.caseSensitive);
                else
                    d = new Dictionary();
            } catch (FileNotFoundException fe) {
                JOptionPane.showMessageDialog(new JFrame(), "Unable to load file" + dm.getFileURL(),
                        "[PSI makers: PSI maker] load dictionnary", JOptionPane.ERROR_MESSAGE);
                d = new Dictionary();
            }
            treePanel.dictionaryPanel.dictionaries.addDictionary(d);
        }
        treePanel.dictionaryPanel.reload();

        /* tree */
        TreeMapping treeMapping = mapping.getTree();

        File schema = new File(treeMapping.getSchemaURL());
        try {
            treePanel.loadSchema(schema);
            ((XsdTreeStructImpl) treePanel.xsdTree).loadMapping(treeMapping);

            treePanel.xsdTree.check();
            treePanel.reload();

            /* set titles for flat files */
            for (int i = 0; i < mapping.flatFiles.size(); i++) {
                try {
                    flatFileTabbedPanel.tabbedPane.setTitleAt(i,
                            ((XsdNode) xsdTree.getAssociatedFlatFiles().get(i)).toString());
                } catch (IndexOutOfBoundsException e) {
                    /** TODO: manage exception */
                }
            }

        } catch (FileNotFoundException fe) {
            JOptionPane.showMessageDialog(new JFrame(), "File not found: " + schema.getName(), "[PSI makers]",
                    JOptionPane.ERROR_MESSAGE);
        } catch (IOException ioe) {
            JOptionPane.showMessageDialog(new JFrame(), "Unable to load file" + ioe.toString(), "[PSI makers]",
                    JOptionPane.ERROR_MESSAGE);
        }
        xdec.close();
        fin.close();
    } catch (FileNotFoundException fe) {
        JOptionPane.showMessageDialog(new JFrame(), "Unable to load mapping" + mappingFile.getName(),
                "[PSI makers: PSI maker] load mapping", JOptionPane.ERROR_MESSAGE);
    } catch (IOException ioe) {
        JOptionPane.showMessageDialog(new JFrame(), "IO error, unable to load mapping",
                "[PSI makers: PSI maker] load mapping", JOptionPane.ERROR_MESSAGE);
    } catch (NoSuchElementException nsee) {
        nsee.printStackTrace();
        JOptionPane.showMessageDialog(new JFrame(), "Unable to load file", "[PSI makers]",
                JOptionPane.ERROR_MESSAGE);
    }

}

From source file:podd.resources.util.RemoteFileHelper.java

/**
 * Borrow or create a new SSH Client//  w w w  .j av a  2  s .  c o m
 * @param datastore
 * @return
 * @throws IOException
 */
private SSHClient borrowSSHClient(Datastore datastore) throws IOException {
    LOGGER.info("borrowing ssh client");
    try {
        SSHClient sshClient = (SSHClient) sshClientPool.borrowObject(datastore);
        return sshClient;
    } catch (NoSuchElementException e) {
        LOGGER.error("Found exception", e);
        e.printStackTrace();
        throw new IOException(e);
    } catch (IllegalStateException e) {
        LOGGER.error("Found exception", e);
        e.printStackTrace();
        throw new IOException(e);
    } catch (Exception e) {
        LOGGER.error("Found exception", e);
        e.printStackTrace();
        throw new IOException(e);
    }
    /*
    final SSHClient ssh = new SSHClient();
     ssh.loadKnownHosts();
     // Accept all hosts
     ssh.addHostKeyVerifier(
        new HostKeyVerifier() {
      public boolean verify(String arg0, int arg1, PublicKey arg2) {
         return true; // don't bother verifying
      }
     });        
                
     ssh.connect(datastore.getIp(), datastore.getPort());           
     ssh.authPublickey(datastore.getLoginId());           
     //ssh.authPublickey(datastore.getLoginId(), privateKey.getAbsolutePath());
            
     return ssh;*/
}

From source file:org.mobicents.servlet.sip.example.SimpleSipServlet.java

/**
 * {@inheritDoc}/* w  ww  .  j a v a2 s.c o m*/
 */
protected void doNotify(SipServletRequest request) throws ServletException, IOException {

    Channel channel = null;
    String routingKey = "";

    //a trick to change routingKey value.
    //routingKey = getBindingKey();

    try {

        channel = pool.borrowObject();
        String message = request.getCallId();

        channel.exchangeDeclare(EXCHANGE_NAME, "topic", true);
        channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes());
        logger.info("PUBLISH A MESSAGE : " + message);

        logger.info("*************************************");
        logger.info("**" + "Number active : " + pool.getNumActive() + " ***");
        logger.info("**" + "Number idle  : " + pool.getNumIdle() + " ***");
        logger.info("*************************************");

    } catch (NoSuchElementException e) {

        logger.error(e.getMessage());
        throw new ServletException(e);

    } catch (IllegalStateException e) {

        logger.error(e.getMessage());
        throw new ServletException(e);
    } catch (Exception e) {

        logger.error(e.getMessage());
        throw new ServletException(e);
    } finally {
        if (channel != null) {
            try {
                pool.returnObject(channel);
            } catch (Exception e) {
                e.printStackTrace();
                logger.error("Failed to return channel back to pool. Exception message: " + e.getMessage());
            }
            //logger.info("RETURN CHANNEL TO THE POOL");
        }

    }
    SipServletResponse sipServletResponse = request.createResponse(SipServletResponse.SC_OK);
    sipServletResponse.send();

}

From source file:com.att.cspd.SimpleSipServlet.java

/**
 * {@inheritDoc}//from w w  w  .  jav a  2 s .  c om
 */
protected void doNotify(SipServletRequest request) throws ServletException, IOException {

    Channel channel = null;
    String routingKey = "";

    //a trick to change routingKey value.
    //routingKey = getBindingKey();

    try {

        channel = pool.borrowObject();
        String message = request.getCallId();
        logger.info("doNotify method: Request dump: " + request.toString());
        Iterator itr = request.getHeaderNames();
        while (itr.hasNext()) {
            logger.info("Header Name : " + itr.next() + "\n");
        }
        String toHdr = request.getHeader("To");

        Matcher matcher = Pattern.compile("sip:(.*)@.+").matcher(toHdr);
        if (matcher.find()) {
            String userpart = matcher.group(1);
            logger.info("user part of the sip url : " + userpart);
            routingKey = userpart;
        }

        channel.exchangeDeclare(EXCHANGE_NAME, "topic", true);
        channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes());
        logger.info("PUBLISH A MESSAGE : " + message);

        logger.info("*************************************");
        logger.info("**" + "Number active : " + pool.getNumActive() + " ***");
        logger.info("**" + "Number idle  : " + pool.getNumIdle() + " ***");
        logger.info("*************************************");

    } catch (NoSuchElementException e) {

        logger.error(e.getMessage());
        throw new ServletException(e);

    } catch (IllegalStateException e) {

        logger.error(e.getMessage());
        throw new ServletException(e);
    } catch (Exception e) {

        logger.error(e.getMessage());
        throw new ServletException(e);
    } finally {
        if (channel != null) {
            try {
                pool.returnObject(channel);
            } catch (Exception e) {
                e.printStackTrace();
                logger.error("Failed to return channel back to pool. Exception message: " + e.getMessage());
            }
            //logger.info("RETURN CHANNEL TO THE POOL");
        }

    }
    SipServletResponse sipServletResponse = request.createResponse(SipServletResponse.SC_OK);
    sipServletResponse.send();

}

From source file:org.lobid.lodmill.RdfModelFileWriter.java

@Override
public void process(final Model model) {
    String identifier = null;//  w w w.j  a  va 2  s. co m
    try {
        identifier = model.listObjectsOfProperty(model.createProperty(filenameUtil.property)).next().asLiteral()
                .toString();
        LOG.debug("Going to store identifier=" + identifier);
    } catch (NoSuchElementException e) {
        LOG.warn("No identifier => cannot derive a filename for " + model.toString(), e);
        return;
    } catch (LiteralRequiredException e) {
        LOG.warn("Identifier is a URI. Derive filename from that URI ... " + model.toString(), e);
        identifier = model.listObjectsOfProperty(model.createProperty(filenameUtil.property)).next().toString();
    }

    String directory = identifier;
    if (directory.length() >= filenameUtil.endIndex) {
        directory = directory.substring(filenameUtil.startIndex, filenameUtil.endIndex);
    }
    final String file = FilenameUtils.concat(filenameUtil.target,
            FilenameUtils.concat(directory + File.separator, identifier + "." + filenameUtil.fileSuffix));

    LOG.info("Write to " + file);
    ensurePathExists(file);

    try {
        final Writer writer = new OutputStreamWriter(new FileOutputStream(file), filenameUtil.encoding);
        final StringWriter tripleWriter = new StringWriter();
        RDFDataMgr.write(tripleWriter, model, this.serialization);
        tripleWriter.toString();
        IOUtils.write(tripleWriter.toString(), writer);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
        throw new MetafactureException(e);
    }
}

From source file:com.metaparadigm.jsonrpc.JSONRPCBridge.java

public JSONRPCResult call(Object context[], JSONObject jsonReq) {
    JSONRPCResult result = null;//  www.ja va 2  s .c  o  m
    String encodedMethod = null;
    Object requestId = null;
    JSONArray arguments = null;

    try {
        // Get method name, arguments and request id
        encodedMethod = jsonReq.getString("method");
        arguments = jsonReq.getJSONArray("params");
        requestId = jsonReq.opt("id");
    } catch (NoSuchElementException e) {
        log.severe("no method or parameters in request");
        return new JSONRPCResult(JSONRPCResult.CODE_ERR_NOMETHOD, null, JSONRPCResult.MSG_ERR_NOMETHOD);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if (isDebug())
        log.fine("call " + encodedMethod + "(" + arguments + ")" + ", requestId=" + requestId);

    String className = null;
    String methodName = null;
    int objectID = 0;

    // Parse the class and methodName
    StringTokenizer t = new StringTokenizer(encodedMethod, ".");
    if (t.hasMoreElements())
        className = t.nextToken();
    if (t.hasMoreElements())
        methodName = t.nextToken();

    // See if we have an object method in the format ".obj#<objectID>"
    if (encodedMethod.startsWith(".obj#")) {
        t = new StringTokenizer(className, "#");
        t.nextToken();
        objectID = Integer.parseInt(t.nextToken());
    }

    ObjectInstance oi = null;
    ClassData cd = null;
    HashMap methodMap = null;
    Method method = null;
    Object itsThis = null;

    if (objectID == 0) {
        // Handle "system.listMethods"
        if (encodedMethod.equals("system.listMethods")) {
            HashSet m = new HashSet();
            globalBridge.allInstanceMethods(m);
            if (globalBridge != this) {
                globalBridge.allStaticMethods(m);
                globalBridge.allInstanceMethods(m);
            }
            allStaticMethods(m);
            allInstanceMethods(m);
            JSONArray methods = new JSONArray();
            Iterator i = m.iterator();
            while (i.hasNext())
                methods.put(i.next());
            return new JSONRPCResult(JSONRPCResult.CODE_SUCCESS, requestId, methods);
        }
        // Look up the class, object instance and method objects
        if (className == null || methodName == null
                || ((oi = resolveObject(className)) == null && (cd = resolveClass(className)) == null))
            return new JSONRPCResult(JSONRPCResult.CODE_ERR_NOMETHOD, requestId,
                    JSONRPCResult.MSG_ERR_NOMETHOD);
        if (oi != null) {
            itsThis = oi.o;
            methodMap = oi.classData().methodMap;
        } else {
            methodMap = cd.staticMethodMap;
        }
    } else {
        if ((oi = resolveObject(new Integer(objectID))) == null)
            return new JSONRPCResult(JSONRPCResult.CODE_ERR_NOMETHOD, requestId,
                    JSONRPCResult.MSG_ERR_NOMETHOD);
        itsThis = oi.o;
        methodMap = oi.classData().methodMap;
        // Handle "system.listMethods"
        if (methodName.equals("listMethods")) {
            HashSet m = new HashSet();
            uniqueMethods(m, "", oi.classData().staticMethodMap);
            uniqueMethods(m, "", oi.classData().methodMap);
            JSONArray methods = new JSONArray();
            Iterator i = m.iterator();
            while (i.hasNext())
                methods.put(i.next());
            return new JSONRPCResult(JSONRPCResult.CODE_SUCCESS, requestId, methods);
        }
    }

    if ((method = resolveMethod(methodMap, methodName, arguments)) == null)
        return new JSONRPCResult(JSONRPCResult.CODE_ERR_NOMETHOD, requestId, JSONRPCResult.MSG_ERR_NOMETHOD);
    // Call the method
    try {
        if (debug)
            log.fine("invoking " + method.getReturnType().getName() + " " + method.getName() + "("
                    + argSignature(method) + ")");
        Object javaArgs[] = unmarshallArgs(context, method, arguments);
        for (int i = 0; i < context.length; i++)
            preInvokeCallback(context[i], itsThis, method, javaArgs);
        Object o = method.invoke(itsThis, javaArgs);
        for (int i = 0; i < context.length; i++)
            postInvokeCallback(context[i], itsThis, method, o);
        SerializerState state = new SerializerState();
        result = new JSONRPCResult(JSONRPCResult.CODE_SUCCESS, requestId, ser.marshall(state, o));
    } catch (UnmarshallException e) {
        for (int i = 0; i < context.length; i++)
            errorCallback(context[i], itsThis, method, e);
        result = new JSONRPCResult(JSONRPCResult.CODE_ERR_UNMARSHALL, requestId, e.getMessage());
    } catch (MarshallException e) {
        for (int i = 0; i < context.length; i++)
            errorCallback(context[i], itsThis, method, e);
        result = new JSONRPCResult(JSONRPCResult.CODE_ERR_MARSHALL, requestId, e.getMessage());
    } catch (Throwable e) {
        if (e instanceof InvocationTargetException)
            e = ((InvocationTargetException) e).getTargetException();
        for (int i = 0; i < context.length; i++)
            errorCallback(context[i], itsThis, method, e);
        result = new JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, requestId, e);
    }

    // Return the results
    return result;
}