Example usage for java.util Vector remove

List of usage examples for java.util Vector remove

Introduction

In this page you can find the example usage for java.util Vector remove.

Prototype

public synchronized E remove(int index) 

Source Link

Document

Removes the element at the specified position in this Vector.

Usage

From source file:org.apache.oodt.cas.workflow.gui.model.repo.XmlWorkflowModelRepository.java

private void ensureUniqueIds(Set<ModelGraph> graphs) {
    for (ModelGraph graph : graphs) {
        HashSet<String> names = new HashSet<String>();
        Vector<ModelGraph> stack = new Vector<ModelGraph>();
        stack.add(graph);//from   w  ww  .  java 2 s  . c o  m
        while (!stack.isEmpty()) {
            ModelGraph currentGraph = stack.remove(0);
            String currentId = currentGraph.getId();
            for (int i = 1; names.contains(currentId); i++) {
                currentId = currentGraph.getId() + "-" + i;
            }
            names.add(currentId);
            if (!currentId.equals(currentGraph.getId())) {
                currentGraph.getModel().setModelId(currentId);
            }
            stack.addAll(currentGraph.getChildren());
        }
    }
}

From source file:com.concursive.connect.web.modules.common.social.images.jobs.ImageResizerJob.java

public void execute(JobExecutionContext context) throws JobExecutionException {
    LOG.debug("Starting...");
    SchedulerContext schedulerContext = null;
    Connection db = null;/*from  w w  w.  j a  va  2s .c  om*/

    // Initial setup
    try {
        schedulerContext = context.getScheduler().getContext();
    } catch (Exception e) {
        LOG.error("ImageResizerJob Exception due to scheduler", e);
        throw new JobExecutionException(e);
    }

    // Process the arrays
    Vector exportList = (Vector) schedulerContext.get(IMAGE_RESIZER_ARRAY);

    while (exportList.size() > 0) {

        // Holds the transactions to be threaded
        List<TransactionTask> renderTasks = new ArrayList<TransactionTask>();

        // Pre-process the files using a database connection
        try {
            db = SchedulerUtils.getConnection(schedulerContext);
            // The imageResizerBean contains the image handle to be processed
            ImageResizerBean bean = (ImageResizerBean) exportList.remove(0);

            LOG.debug("Preparing thumbnails for FileItem (" + bean.getFileItemId() + ")... " + bean.getWidth()
                    + "x" + bean.getHeight());
            // Load the fileItem
            FileItem fileItem = new FileItem(db, bean.getFileItemId());
            if (bean.getWidth() > 0 || bean.getHeight() > 0) {
                // A specific size needs to be rendered
                renderTasks.add(new TransactionTask(bean, fileItem, bean.getWidth(), bean.getHeight(), false));
            } else {
                // No specific size so for each fileItem, generate several sizes of the image
                renderTasks.add(new TransactionTask(bean, fileItem, 640, 480, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 210, 150, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 200, 200, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 133, 133, true));
                renderTasks.add(new TransactionTask(bean, fileItem, 100, 100, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 75, 75, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 50, 50, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 45, 45, false));
                renderTasks.add(new TransactionTask(bean, fileItem, 30, 30, false));
            }
        } catch (Exception e) {
            LOG.error("ImageResizerJob Exception", e);
            continue;
        } finally {
            SchedulerUtils.freeConnection(schedulerContext, db);
        }

        int threads = 2;
        // Process the files
        ExecutorService executor = null;
        List<Future<Thumbnail>> futures = null;
        try {
            executor = Executors.newFixedThreadPool(threads);
            // NOTE: this wrapper fix is for Java 1.5
            final Collection<Callable<Thumbnail>> wrapper = Collections
                    .<Callable<Thumbnail>>unmodifiableCollection(renderTasks);
            LOG.debug("Generating thumbnails... " + renderTasks.size());
            futures = executor.invokeAll(wrapper);
        } catch (InterruptedException e) {
            LOG.error("ImageResizerJob executor exception", e);
            if (executor != null) {
                executor.shutdown();
            }
            throw new JobExecutionException(e);
        }

        // Insert the thumbnails using the database connection
        try {
            db = SchedulerUtils.getConnection(schedulerContext);
            LOG.debug("Inserting thumbnails into database... " + futures.size());
            // Process the executor results
            for (Future<Thumbnail> f : futures) {
                Thumbnail thumbnail = f.get();
                thumbnail.insert(db);
            }
        } catch (Exception e) {
            LOG.error("ImageResizerJob insert thumbnails into database exception", e);
            throw new JobExecutionException(e);
        } finally {
            SchedulerUtils.freeConnection(schedulerContext, db);
            if (executor != null) {
                executor.shutdown();
            }
        }
    }
}

From source file:edu.duke.cabig.c3pr.domain.scheduler.runtime.job.CCTSNotificationMessageJob.java

/**
 * @param queue/*w  ww  .j  a v  a2 s  . c om*/
 */
private void process(final Vector<CCTSNotification> queue) {
    boolean done;
    do {
        done = true;
        CCTSNotification notification = null;
        try {
            notification = queue.firstElement();
        } catch (NoSuchElementException e) {
        }
        if (notification == null) {
            log.debug("CCTS notification queue is empty; messages, if any, have been processed.");
        } else
            try {
                process(notification);
                queue.remove(notification);
                done = false;
            } catch (ESBCommunicationException e) {
                log.error(ExceptionUtils.getFullStackTrace(e));
                log.error("Processing of a CCTS notification failed: " + notification);
                log.error("Failed notification will be put back into the queue for another re-try later.");
            } catch (Exception e) {
                log.error(ExceptionUtils.getFullStackTrace(e));
                log.error("Processing of a CCTS notification failed: " + notification);
                log.error(
                        "This error indicates a problem with the message itself. It will be removed from the queue. No further delivery attempts will be made.");
                queue.remove(notification);
                done = false;
            }
    } while (!done);
}

From source file:org.globus.ftp.test.GridFTPClientTest.java

private void testNList(int mode, int type) throws Exception {
    logger.info("show list output using GridFTPClient");

    GridFTPClient client = connect();/* ww  w .ja v  a2  s.  c o m*/
    client.setType(type);
    client.setMode(mode);
    client.changeDir(TestEnv.serverADir);
    Vector v = client.nlist();
    logger.debug("list received");
    while (!v.isEmpty()) {
        FileInfo f = (FileInfo) v.remove(0);
        logger.info(f.toString());
    }
    client.close();
}

From source file:org.globus.ftp.test.GridFTPClientTest.java

private void testMList(int mode, int type) throws Exception {
    logger.info("show list output using GridFTPClient");

    GridFTPClient client = connect();//from  ww w  . j av a  2  s.c  om
    client.setType(type);
    client.setMode(mode);
    client.changeDir(TestEnv.serverADir);
    Vector v = client.mlsd(null);
    logger.debug("list received");
    while (!v.isEmpty()) {
        MlsxEntry f = (MlsxEntry) v.remove(0);
        logger.info(f.toString());
    }
    client.close();
}

From source file:org.globus.ftp.test.GridFTPClientTest.java

private void testList(int mode, int type) throws Exception {
    logger.info("show list output using GridFTPClient");

    GridFTPClient client = connect();//www.  j a  va 2s .  c  om
    client.setType(type);
    client.setMode(mode);
    client.changeDir(TestEnv.serverADir);
    Vector v = client.list(null, null);
    logger.debug("list received");
    while (!v.isEmpty()) {
        FileInfo f = (FileInfo) v.remove(0);
        logger.info(f.toString());
    }
    client.close();
}

From source file:prodoc.DriverRemote.java

/**
 * Retrieves next record of cursor/*from w  w  w . j a  v  a2s. com*/
 * @param CursorIdent
 * @return OPD next Record
 * @throws PDException 
 */
@Override
public Record NextRec(Cursor CursorIdent) throws PDException {
    if (PDLog.isDebug())
        PDLog.Debug("DriverRemote.NextRec:" + CursorIdent);
    Vector rs = (Vector) CursorIdent.getResultSet();
    if (rs.isEmpty())
        return (null);
    Record Fields = CursorIdent.getFieldsCur();
    Fields.assignSimil((Record) rs.get(0)); // description and other elemens from atribute not transmitted by performance
    rs.remove(0);
    return (Fields.Copy());
}

From source file:org.globus.ftp.test.GridFTPClientTest.java

public void testList2() throws Exception {
    logger.info("test two consective list, using both list functions, using GridFTPClient");

    GridFTPClient client = connect();//from  ww  w. j  a  v  a  2  s . c om

    String output1 = null;
    String output2 = null;

    // using list()

    client.changeDir(TestEnv.serverADir);
    Vector v = client.list(null, null);
    logger.debug("list received");
    StringBuffer output1Buffer = new StringBuffer();
    while (!v.isEmpty()) {
        FileInfo f = (FileInfo) v.remove(0);
        output1Buffer.append(f.toString()).append("\n");

    }
    output1 = output1Buffer.toString();

    // using list(String,String, DataSink)

    HostPort hp2 = client.setPassive();
    client.setLocalActive();

    final ByteArrayOutputStream received2 = new ByteArrayOutputStream(1000);

    // unnamed DataSink subclass will write data channel content
    // to "received" stream.

    client.list(null, null, new DataSink() {
        public void write(Buffer buffer) throws IOException {
            logger.debug("received " + buffer.getLength() + " bytes of directory listing");
            received2.write(buffer.getBuffer(), 0, buffer.getLength());
        }

        public void close() throws IOException {
        };
    });

    // transfer done. Data is in received2 stream.

    output2 = received2.toString();
    logger.debug(output2);

    client.close();
}

From source file:com.concursive.connect.indexer.jobs.IndexerJob.java

public void execute(JobExecutionContext context) throws JobExecutionException {
    SchedulerContext schedulerContext = null;
    try {/* w  w w  . j  av  a2  s .  c o  m*/
        schedulerContext = context.getScheduler().getContext();
        // Determine the indexer service
        IIndexerService indexer = IndexerFactory.getInstance().getIndexerService();
        if (indexer == null) {
            throw (new JobExecutionException("Indexer Configuration error: No indexer defined."));
        }
        // Determine if the indexer job can run
        boolean canExecute = true;
        ServletContext servletContext = (ServletContext) schedulerContext.get("ServletContext");
        if (servletContext != null) {
            // If used in a servlet environment, make sure the indexer is initialized
            canExecute = "true".equals(servletContext.getAttribute(Constants.DIRECTORY_INDEX_INITIALIZED));
        }
        // Execute the indexer
        if (canExecute) {
            Vector eventList = (Vector) schedulerContext.get(INDEX_ARRAY);
            if (eventList.size() > 0) {
                LOG.debug("Indexing data... " + eventList.size());
                indexer.obtainWriterLock();
                try {
                    while (eventList.size() > 0) {
                        IndexEvent indexEvent = (IndexEvent) eventList.get(0);
                        if (indexEvent.getAction() == IndexEvent.ADD) {
                            // The object was either added or updated
                            indexer.indexAddItem(indexEvent.getItem());
                        } else if (indexEvent.getAction() == IndexEvent.DELETE) {
                            // Delete the item and related data
                            indexer.indexDeleteItem(indexEvent.getItem());
                        }
                        eventList.remove(0);
                    }
                } catch (Exception e) {
                    LOG.error("Indexing error", e);
                    throw new JobExecutionException(e.getMessage());
                } finally {
                    indexer.releaseWriterLock();
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Indexing job error", e);
        throw new JobExecutionException(e.getMessage());
    }
}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.MonitorServ.java

/** Disconnect the given monitor from the given session. This is called whenever a MonitorDisconnectedException
 *  is thrown, indicating the the server has lost connection with the given monitor */
private boolean disconnectMonitor(int sessionId, MonitorTransmitter ui) {
    Vector monitors = (Vector) sessionMonitors.get(new Integer(sessionId));
    if (monitors == null) {
        log.warn("Cannot disconnect a monitor in session " + sessionId
                + " -- that session has not been initialized");
        return false;
    }//from  ww  w . ja v a 2  s .  c o m

    try {
        ui.close();
    } catch (MonitorDisconnectedException e) {

    }

    return monitors.remove(ui);
}