Example usage for java.util.logging Level FINE

List of usage examples for java.util.logging Level FINE

Introduction

In this page you can find the example usage for java.util.logging Level FINE.

Prototype

Level FINE

To view the source code for java.util.logging Level FINE.

Click Source Link

Document

FINE is a message level providing tracing information.

Usage

From source file:com.cyberway.issue.crawler.deciderules.ExternalGeoLocationDecideRule.java

protected boolean evaluate(Object obj) {
    ExternalGeoLookupInterface impl = getConfiguredImplementation(obj);
    if (impl == null) {
        return false;
    }/*from   w  w w. java2 s . co m*/
    CrawlHost crawlHost = null;
    String host;
    InetAddress address;
    try {
        if (obj instanceof CandidateURI) {
            host = ((CandidateURI) obj).getUURI().getHost();
            crawlHost = getSettingsHandler().getOrder().getController().getServerCache().getHostFor(host);
            if (crawlHost.getCountryCode() != null) {
                return (crawlHost.getCountryCode().equals(countryCode)) ? true : false;
            }
            address = crawlHost.getIP();
            if (address == null) {
                address = Address.getByName(host);
            }
            crawlHost.setCountryCode((String) impl.lookup(address));
            if (crawlHost.getCountryCode().equals(countryCode)) {
                LOGGER.fine("Country Code Lookup: " + " " + host + crawlHost.getCountryCode());
                return true;
            }
        }
    } catch (UnknownHostException e) {
        LOGGER.log(Level.FINE, "Failed dns lookup " + obj, e);
        if (crawlHost != null) {
            crawlHost.setCountryCode(DEFAULT_COUNTRY_CODE);
        }
    } catch (URIException e) {
        LOGGER.log(Level.FINE, "Failed to parse hostname " + obj, e);
    }

    return false;
}

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.RequestAttributeResolver.java

private Set<String> getAttributesFromClassLoader(String clazzname) {
    final Set<String> ret = new LinkedHashSet<>();
    try {/*from  w  w  w  .  j av a  2  s  .  c o  m*/
        Class clazz = classPath.getClassLoader(true).loadClass(clazzname);
        for (Method method : clazz.getDeclaredMethods()) {
            for (Annotation annotation : method.getAnnotations()) {
                if (annotation.annotationType().getName().equals(REQUEST_ATTRIBUTE_CLASSNAME)) {
                    ret.add(method.getName());
                }
            }
        }
        for (Field field : clazz.getDeclaredFields()) {
            for (Annotation annotation : field.getAnnotations()) {
                if (annotation.annotationType().getName().equals(REQUEST_ATTRIBUTE_CLASSNAME)) {
                    ret.add(field.getName());
                }
            }
        }
    } catch (ClassNotFoundException cnfe) {
        LOGGER.log(Level.FINE, "Could not resolve class " + clazzname, cnfe);
    }
    return ret;
}

From source file:edu.emory.cci.aiw.umls.UMLSDatabaseConnection.java

private void setupConn() throws UMLSQueryException {
    log(Level.FINE, "Attempting to establish database connection...");
    try {//from   w w  w  . j av  a2s .c o  m
        conn = api.newConnectionSpecInstance(url, user, password).getOrCreate();
        log(Level.FINE, "Connection established with " + url);
    } catch (SQLException sqle) {
        throw new UMLSQueryException(sqle);
    } catch (InvalidConnectionSpecArguments icsa) {
        throw new UMLSQueryException(icsa);
    }
}

From source file:hudson.console.ConsoleAnnotationOutputStream.java

/**
 * Called after we read the whole line of plain text, which is stored in {@link #buf}.
 * This method performs annotations and send the result to {@link #out}.
 */// www .  j  a va2  s  .  c o m
protected void eol(byte[] in, int sz) throws IOException {
    line.reset();
    final StringBuffer strBuf = line.getStringBuffer();

    int next = ConsoleNote.findPreamble(in, 0, sz);

    List<ConsoleAnnotator<T>> annotators = null;

    {// perform byte[]->char[] while figuring out the char positions of the BLOBs
        int written = 0;
        while (next >= 0) {
            if (next > written) {
                lineOut.write(in, written, next - written);
                lineOut.flush();
                written = next;
            } else {
                assert next == written;
            }

            // character position of this annotation in this line
            final int charPos = strBuf.length();

            int rest = sz - next;
            ByteArrayInputStream b = new ByteArrayInputStream(in, next, rest);

            try {
                final ConsoleNote a = ConsoleNote.readFrom(new DataInputStream(b));
                if (a != null) {
                    if (annotators == null)
                        annotators = new ArrayList<ConsoleAnnotator<T>>();
                    annotators.add(new ConsoleAnnotator<T>() {
                        public ConsoleAnnotator annotate(T context, MarkupText text) {
                            return a.annotate(context, text, charPos);
                        }
                    });
                }
            } catch (IOException e) {
                // if we failed to resurrect an annotation, ignore it.
                LOGGER.log(Level.FINE, "Failed to resurrect annotation", e);
            } catch (ClassNotFoundException e) {
                LOGGER.log(Level.FINE, "Failed to resurrect annotation", e);
            }

            int bytesUsed = rest - b.available(); // bytes consumed by annotations
            written += bytesUsed;

            next = ConsoleNote.findPreamble(in, written, sz - written);
        }
        // finish the remaining bytes->chars conversion
        lineOut.write(in, written, sz - written);

        if (annotators != null) {
            // aggregate newly retrieved ConsoleAnnotators into the current one.
            if (ann != null)
                annotators.add(ann);
            ann = ConsoleAnnotator.combine(annotators);
        }
    }

    lineOut.flush();
    MarkupText mt = new MarkupText(strBuf.toString());
    if (ann != null)
        ann = ann.annotate(context, mt);
    out.write(mt.toString(true)); // this perform escapes
}

From source file:ffx.HeadlessMain.java

/**
 * Complete initializations.//w  w w .  j a v  a2s  . c  o  m
 *
 * @param commandLineFile a {@link java.io.File} object.
 * @param argList a {@link java.util.List} object.
 * @param logHandler a {@link ffx.ui.LogHandler} object.
 */
public HeadlessMain(File commandLineFile, List<String> argList, LogHandler logHandler) {
    // Start a timer.
    stopWatch.start();

    // Construct the MainPanel, set it's LogHandler, and initialize then it.
    mainPanel = new MainPanel();
    logHandler.setMainPanel(mainPanel);
    mainPanel.initialize();

    // Open the supplied script file.
    if (commandLineFile != null) {
        if (!commandLineFile.exists()) {
            /**
             * See if the commandLineFile is an embedded script.
             */
            String name = commandLineFile.getName();
            name = name.replace('.', '/');
            String pathName = "ffx/scripts/" + name;
            ClassLoader loader = getClass().getClassLoader();
            URL embeddedScript = loader.getResource(pathName + ".ffx");
            if (embeddedScript == null) {
                embeddedScript = loader.getResource(pathName + ".groovy");
            }
            if (embeddedScript != null) {
                try {
                    commandLineFile = new File(FFXClassLoader.copyInputStreamToTmpFile(
                            embeddedScript.openStream(), commandLineFile.getName(), ".ffx"));
                } catch (Exception e) {
                    logger.warning("Exception extracting embedded script " + embeddedScript.toString() + "\n"
                            + e.toString());
                }
            }
        }
        if (commandLineFile.exists()) {
            mainPanel.getModelingShell().setArgList(argList);
            mainPanel.open(commandLineFile, null);
        } else {
            logger.warning(format("%s was not found.", commandLineFile.toString()));
        }
    }

    /**
     * Print start-up information.
     */
    if (logger.isLoggable(Level.FINE)) {
        StringBuilder sb = new StringBuilder();
        sb.append(format("\n Start-up Time (msec): %s.", stopWatch.getTime()));
        Runtime runtime = Runtime.getRuntime();
        runtime.runFinalization();
        runtime.gc();
        long occupiedMemory = runtime.totalMemory() - runtime.freeMemory();
        long KB = 1024;
        sb.append(format("\n In-Use Memory   (Kb): %d", occupiedMemory / KB));
        sb.append(format("\n Free Memory     (Kb): %d", runtime.freeMemory() / KB));
        sb.append(format("\n Total Memory    (Kb): %d", runtime.totalMemory() / KB));
        logger.fine(sb.toString());
    }
}

From source file:net.sf.mpaxs.spi.computeHost.Host.java

/**
 * Meldet diesen Host beim Masterserver an. Nach erfolgreicher Anmeldung
 * kann der Masterserver Jobs an diesen Host vergeben.
 *///from w  w  w .j  av  a 2 s .com
private void connectToMasterServer() {
    final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();
    final long startUpAt = System.currentTimeMillis();
    final long failAfter = 5000;
    ses.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            Logger.getLogger(Host.class.getName()).log(Level.FINE,
                    "Trying to connect to MasterServer from IP " + settings.getLocalIp());
            long currentTime = System.currentTimeMillis();
            if (currentTime - startUpAt >= failAfter) {
                Logger.getLogger(Host.class.getName()).log(Level.WARNING,
                        "Waited {0} seconds for MasterServer, shutting down ComputeHost", (failAfter / 1000));
                System.exit(1);
            }
            try {
                Logger.getLogger(Host.class.getName()).log(Level.FINE,
                        "Trying to bind to MasterServer at " + settings.getMasterServerIP() + ":"
                                + settings.getMasterServerPort() + " with name: "
                                + settings.getMasterServerName());
                IRemoteServer remRef = (IRemoteServer) Naming.lookup("//" + settings.getMasterServerIP() + ":"
                        + settings.getMasterServerPort() + "/" + settings.getMasterServerName());
                settings.setRemoteReference(remRef);
                UUID hostID = remRef.addHost(authToken, settings.getName(), settings.getLocalIp(),
                        settings.getCores());
                settings.setHostID(hostID);
                Logger.getLogger(Host.class.getName()).log(Level.FINE, "Connection to server established!");
                ses.shutdown();
                try {
                    ses.awaitTermination(5, TimeUnit.SECONDS);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Host.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (NotBoundException ex) {
                Logger.getLogger(Host.class.getName()).log(Level.INFO,
                        "Master server not found, waiting for connection!");
                //Logger.getLogger(Host.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MalformedURLException ex) {
                Logger.getLogger(Host.class.getName()).log(Level.SEVERE, null, ex);
                System.exit(1);
            } catch (RemoteException ex) {
                Logger.getLogger(Host.class.getName()).log(Level.SEVERE, null, ex);
                System.exit(1);
            }
        }
    }, 1, settings.getMasterServerTimeout(), TimeUnit.SECONDS);

}

From source file:edu.cwru.sepia.model.BestEffortModel.java

@SuppressWarnings("incomplete-switch")
@Override/* w  w  w.  ja v  a  2s  .c  om*/
public void executeStep() {

    // Set each agent to have no task
    for (Unit u : state.getUnits().values()) {
        u.deprecateOldView();
    }
    // Set each template to not keep the old view
    for (Integer player : state.getPlayers())
        for (@SuppressWarnings("rawtypes")
        Template t : state.getTemplates(player).values())
            t.deprecateOldView();

    // Run the Action
    for (Integer player : state.getPlayers()) {
        // hedge against players entering the state for some reason
        if (!queuedActions.containsKey(player)) {
            queuedActions.put(player, new HashMap<Integer, ActionQueue>());
        }
        if (turnTracker == null || turnTracker.isPlayersTurn(player)) {
            Iterator<ActionQueue> queuedActItr = queuedActions.get(player).values().iterator();
            while (queuedActItr.hasNext()) {
                ActionQueue queuedAct = queuedActItr.next();
                if (logger.isLoggable(Level.FINE))
                    logger.fine("Doing full action: " + queuedAct.getFullAction());
                // Pull out the primitive
                if (!queuedAct.hasNext())
                    continue;
                Action a = queuedAct.popPrimitive();
                if (logger.isLoggable(Level.FINE))
                    logger.fine("Doing primitive action: " + a);
                // Execute it
                Unit u = state.getUnit(a.getUnitId());
                if (u == null)
                    continue;
                // Set the tasks and grab the common features
                int x = u.getXPosition();
                int y = u.getYPosition();
                int xPrime = 0;
                int yPrime = 0;
                if (a instanceof DirectedAction) {
                    Direction d = ((DirectedAction) a).getDirection();
                    xPrime = x + d.xComponent();
                    yPrime = y + d.yComponent();
                } else if (a instanceof LocatedAction) {
                    xPrime = x + ((LocatedAction) a).getX();
                    yPrime = y + ((LocatedAction) a).getY();
                }

                // Gather the last of the information and actually execute
                // the actions
                int timesTried = 0;
                boolean failedTry = true;
                boolean wrongType = false;
                boolean fullIsPrimitive = ActionType.isPrimitive(a.getType());
                boolean incompletePrimitive;
                /*
                 * recalculate and try again once if it has failed, so long
                 * as the full action is not primitive (since primitives
                 * will recalculate to the same as before) and not the wrong
                 * type (since something is wrong if it is the wrong type)
                 */
                do {
                    timesTried++;
                    failedTry = false;
                    incompletePrimitive = false;
                    switch (a.getType()) {
                    case PRIMITIVEMOVE:
                        if (!(a instanceof DirectedAction)) {
                            wrongType = true;
                            break;
                        }
                        if (accessible(u, xPrime, yPrime)) {
                            int newdurativeamount;
                            if (a.equals(u.getActionProgressPrimitive())) {
                                newdurativeamount = u.getActionProgressAmount() + 1;
                            } else {
                                newdurativeamount = 1;
                            }
                            Direction d = ((DirectedAction) a).getDirection();
                            boolean willcompletethisturn = newdurativeamount == DurativePlanner
                                    .calculateMoveDuration(u, u.getXPosition(), u.getYPosition(), d, state);
                            // if it will finish, then execute the atomic
                            // action
                            if (willcompletethisturn) {
                                state.moveUnit(u, d);
                                u.resetDurative();
                            } else {
                                incompletePrimitive = true;
                                u.setDurativeStatus(a, newdurativeamount);
                            }
                        } else {
                            failedTry = true;
                            queuedAct.resetPrimitives(calculatePrimitives(queuedAct.getFullAction()));
                        }
                        break;
                    case PRIMITIVEGATHER:
                        if (!(a instanceof DirectedAction)) {
                            wrongType = true;
                            break;
                        }
                        boolean failed = false;
                        ResourceNode resource = state.resourceAt(xPrime, yPrime);
                        if (resource == null) {
                            failed = true;
                        } else if (!u.canGather()) {
                            failed = true;
                        } else {
                            int newdurativeamount;
                            if (a.equals(u.getActionProgressPrimitive())) {
                                newdurativeamount = u.getActionProgressAmount() + 1;
                            } else {
                                newdurativeamount = 1;
                            }
                            boolean willcompletethisturn = newdurativeamount == DurativePlanner
                                    .calculateGatherDuration(u, resource);
                            // if it will finish, then execute the atomic
                            // action
                            if (willcompletethisturn) {
                                int amountPickedUp = resource.reduceAmountRemaining(
                                        u.getTemplate().getGatherRate(resource.getType().getResource()));
                                u.setCargo(resource.getResourceType(), amountPickedUp);
                                history.recordResourcePickup(u, resource, amountPickedUp, state);
                                u.resetDurative();
                            } else {
                                incompletePrimitive = true;
                                u.setDurativeStatus(a, newdurativeamount);
                            }
                        }
                        if (failed) {
                            failedTry = true;
                            queuedAct.resetPrimitives(calculatePrimitives(queuedAct.getFullAction()));
                        }
                        break;
                    case PRIMITIVEDEPOSIT:
                        if (!(a instanceof DirectedAction)) {
                            wrongType = true;
                            break;
                        }
                        // only can do a primitive if you are in the right
                        // position
                        Unit townHall = state.unitAt(xPrime, yPrime);
                        boolean canAccept = false;
                        if (townHall != null && townHall.getPlayer() == u.getPlayer()) {
                            if (townHall.getTemplate().canAccept(u.getCurrentCargoType()))
                                canAccept = true;
                        }
                        if (!canAccept) {
                            failedTry = true;
                            queuedAct.resetPrimitives(calculatePrimitives(queuedAct.getFullAction()));
                            break;
                        } else {
                            int newdurativeamount;
                            if (a.equals(u.getActionProgressPrimitive())) {
                                newdurativeamount = u.getActionProgressAmount() + 1;
                            } else {
                                newdurativeamount = 1;
                            }
                            boolean willcompletethisturn = newdurativeamount == DurativePlanner
                                    .calculateDepositDuration(u, townHall);
                            // if it will finish, then execute the atomic
                            // action
                            if (willcompletethisturn) {
                                int agent = u.getPlayer();
                                history.recordResourceDropoff(u, townHall, state);
                                state.addResourceAmount(agent, u.getCurrentCargoType(),
                                        u.getCurrentCargoAmount());
                                u.clearCargo();
                                u.resetDurative();
                            } else {
                                incompletePrimitive = true;
                                u.setDurativeStatus(a, newdurativeamount);
                            }
                            break;
                        }
                    case PRIMITIVEATTACK:
                        if (!(a instanceof TargetedAction)) {
                            wrongType = true;
                            break;
                        }
                        Unit target = state.getUnit(((TargetedAction) a).getTargetId());
                        if (target != null) {
                            if (u.getTemplate().getRange() >= u.getBounds().distanceTo(target.getBounds())) {
                                int newdurativeamount;
                                if (a.equals(u.getActionProgressPrimitive())) {
                                    newdurativeamount = u.getActionProgressAmount() + 1;
                                } else {
                                    newdurativeamount = 1;
                                }
                                boolean willcompletethisturn = newdurativeamount == DurativePlanner
                                        .calculateAttackDuration(u, target);
                                // if it will finish, then execute the
                                // atomic action
                                if (willcompletethisturn) {
                                    int damage = calculateDamage(u, target);
                                    history.recordDamage(u, target, damage, state);
                                    target.setHP(Math.max(target.getCurrentHealth() - damage, 0));
                                    u.resetDurative();
                                } else {
                                    incompletePrimitive = true;
                                    u.setDurativeStatus(a, newdurativeamount);
                                }
                            } else // out of range
                            {
                                failedTry = true;
                                queuedAct.resetPrimitives(calculatePrimitives(queuedAct.getFullAction()));
                            }
                        } else {
                            failedTry = true;
                            queuedAct.resetPrimitives(calculatePrimitives(queuedAct.getFullAction()));
                        }
                        break;
                    case PRIMITIVEBUILD: {
                        if (!(a instanceof ProductionAction)) {
                            wrongType = true;
                            break;
                        }
                        if (queuedAct.getFullAction().getType() == ActionType.COMPOUNDBUILD
                                && queuedAct.getFullAction() instanceof LocatedProductionAction) {
                            LocatedProductionAction fullbuild = (LocatedProductionAction) queuedAct
                                    .getFullAction();
                            if (fullbuild.getX() != u.getXPosition() || fullbuild.getY() != u.getYPosition()) {
                                failedTry = true;
                                queuedAct.resetPrimitives(calculatePrimitives(queuedAct.getFullAction()));
                                break;
                            }
                        }
                        UnitTemplate template = (UnitTemplate) state
                                .getTemplate(((ProductionAction) a).getTemplateId());
                        if (u.getTemplate().canProduce(template)) {
                            boolean prerequisitesMet = true;
                            // check if the prerequisites for the template's
                            // production are met
                            for (String templateName : template.getBuildPrerequisites()) {
                                if (!state.hasUnit(u.getPlayer(), templateName)) {
                                    prerequisitesMet = false;
                                    break;
                                }
                            }
                            if (prerequisitesMet) {
                                for (String templateName : template.getUpgradePrerequisites()) {
                                    if (!state.hasUpgrade(u.getPlayer(), templateName)) {
                                        prerequisitesMet = false;
                                        break;
                                    }
                                }
                            }
                            if (prerequisitesMet) {
                                int newdurativeamount = a.equals(u.getActionProgressPrimitive())
                                        ? u.getActionProgressAmount() + 1
                                        : 1;
                                boolean willcompletethisturn = newdurativeamount == DurativePlanner
                                        .calculateProductionDuration(u, template);
                                // if it will finish, then execute the
                                // atomic action
                                if (willcompletethisturn) {
                                    Unit building = template.produceInstance(state);
                                    int[] newxy = state.getClosestPosition(x, y);
                                    if (state.tryProduceUnit(building, newxy[0], newxy[1])) {
                                        history.recordBirth(building, u, state);
                                    }
                                    u.resetDurative();
                                } else {
                                    incompletePrimitive = true;
                                    u.setDurativeStatus(a, newdurativeamount);
                                }
                            } else // didn't meet prerequisites
                            {
                                failedTry = true;
                            }
                        } else // it can't produce the appropriate thing
                        {
                            failedTry = true;
                        }

                        break;
                    }
                    case PRIMITIVEPRODUCE: {
                        if (!(a instanceof ProductionAction)) {
                            wrongType = true;
                            break;
                        }
                        Template<?> template = state.getTemplate(((ProductionAction) a).getTemplateId());
                        // check if it is even capable of producing the
                        // template
                        if (u.getTemplate().canProduce(template)) {
                            boolean prerequisitesMet = true;
                            // check if the prerequisites for the template's
                            // production are met
                            for (String templateName : template.getBuildPrerequisites()) {
                                if (!state.hasUnit(u.getPlayer(), templateName)) {
                                    prerequisitesMet = false;
                                    break;
                                }
                            }
                            if (prerequisitesMet) {
                                for (String templateName : template.getUpgradePrerequisites()) {
                                    if (!state.hasUpgrade(u.getPlayer(), templateName)) {
                                        prerequisitesMet = false;
                                        break;
                                    }
                                }
                            }
                            if (prerequisitesMet) {
                                int newdurativeamount = a.equals(u.getActionProgressPrimitive())
                                        ? u.getActionProgressAmount() + 1
                                        : 1;
                                boolean willcompletethisturn = newdurativeamount == DurativePlanner
                                        .calculateProductionDuration(u, template);
                                // if it will finish, then execute the
                                // atomic action
                                if (willcompletethisturn) {
                                    if (template instanceof UnitTemplate) {
                                        Unit produced = ((UnitTemplate) template).produceInstance(state);
                                        int[] newxy = state.getClosestPosition(x, y);
                                        if (state.tryProduceUnit(produced, newxy[0], newxy[1])) {
                                            history.recordBirth(produced, u, state);
                                        }
                                    } else if (template instanceof UpgradeTemplate) {
                                        UpgradeTemplate upgradetemplate = ((UpgradeTemplate) template);
                                        if (state.tryProduceUpgrade(upgradetemplate.produceInstance(state))) {
                                            history.recordUpgrade(upgradetemplate, u, state);
                                        }
                                    }
                                } else {
                                    incompletePrimitive = true;
                                    u.setDurativeStatus(a, newdurativeamount);
                                }
                            } else { // prerequisites not met
                                failedTry = true;
                            }
                        } else// can't produce it
                        {
                            failedTry = true;
                        }
                        break;
                    }
                    case FAILED: {
                        failedTry = true;
                        queuedAct.resetPrimitives(calculatePrimitives(queuedAct.getFullAction()));
                        break;
                    }
                    case FAILEDPERMANENTLY: {
                        break;
                    }
                    }

                    // Record results

                    ActionResultType primitiveFeedback = null;
                    ActionResultType compoundFeedback = null;
                    boolean removeAction = false;
                    if (wrongType) {
                        // if it had the wrong type, then either the planner
                        // is bugged (unlikely) or the user provided a bad
                        // primitive action
                        // either way, record it as failed and toss it
                        compoundFeedback = ActionResultType.INVALIDTYPE;
                        removeAction = true;
                    } else if (!failedTry && a.getType() != ActionType.FAILEDPERMANENTLY) {
                        primitiveFeedback = incompletePrimitive ? ActionResultType.INCOMPLETE
                                : ActionResultType.COMPLETED;
                        if (!incompletePrimitive && !queuedAct.hasNext()) {
                            compoundFeedback = ActionResultType.COMPLETED;
                            removeAction = true;
                        } else {
                            compoundFeedback = ActionResultType.INCOMPLETE;
                        }
                    } else if (a.getType() == ActionType.FAILEDPERMANENTLY || failedTry && fullIsPrimitive) {
                        compoundFeedback = ActionResultType.FAILED;
                        primitiveFeedback = ActionResultType.FAILED;
                        removeAction = true;

                    } else {
                        compoundFeedback = ActionResultType.INCOMPLETEMAYBESTUCK;
                        primitiveFeedback = ActionResultType.FAILED;
                    }
                    if (compoundFeedback != null) {
                        history.recordCommandFeedback(u.getPlayer(), state.getTurnNumber(),
                                new ActionResult(queuedAct.getFullAction(), compoundFeedback));
                    }
                    if (primitiveFeedback != null) {
                        history.recordPrimitiveFeedback(u.getPlayer(), state.getTurnNumber(),
                                new ActionResult(a, primitiveFeedback));
                    }
                    if (removeAction) {
                        queuedActItr.remove();
                    }
                } while (timesTried < numAttempts && failedTry && !fullIsPrimitive && !wrongType);
            }
        } // end if it is the player's turn
    }

    // Take all the dead units and clear them
    // Find the dead units
    Map<Integer, Unit> allunits = state.getUnits();
    List<Integer> dead = new ArrayList<Integer>(allunits.size());
    for (Unit u : allunits.values()) {
        if (u.getCurrentHealth() <= 0) {
            history.recordDeath(u, state);
            dead.add(u.id);
        }
    }
    // Remove them
    for (int uid : dead) {
        state.removeUnit(uid);
    }
    // Take all of the used up resources and get rid of them
    List<ResourceNode> allnodes = state.getResources();
    List<Integer> usedup = new ArrayList<Integer>(allnodes.size());
    for (ResourceNode r : allnodes) {
        if (r.getAmountRemaining() <= 0) {
            history.recordResourceNodeExhaustion(r, state);
            usedup.add(r.id);
        }
    }
    // Remove the used up resource nodes
    for (int rid : usedup) {

        state.removeResourceNode(rid);
    }

    state.incrementTurn();
}

From source file:com.treasuredata.jdbc.TDResultSet.java

/**
 * Moves the cursor down one row from its current position.
 *
 * @throws SQLException if a database access error occurs.
 * @see java.sql.ResultSet#next()/*from   www.j  av  a2  s  . com*/
 */
public boolean next() throws SQLException {
    try {
        if (fetchedRows == null) {
            fetchedRows = fetchRows();
            fetchedRowsItr = fetchedRows.getUnpacker().iterator();
        }

        if (!fetchedRowsItr.hasNext()) {
            return false;
        }

        ArrayValue vs = (ArrayValue) fetchedRowsItr.next();
        row = new ArrayList<Object>(vs.size());
        for (int i = 0; i < vs.size(); i++) {
            row.add(i, vs.get(i));
        }
        rowsFetched++;

        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine(String.format("fetched row(%d): %s", rowsFetched, row));
        }
    } catch (Exception e) {
        if (e instanceof SQLException) {
            throw (SQLException) e;
        } else {
            throw new SQLException("Error retrieving next row", e);
        }
    }
    // NOTE: fetchOne dosn't throw new SQLException("Method not supported").
    return true;
}

From source file:alien4cloud.paas.cloudify2.rest.external.RestClientExecutor.java

/**
 * Executes HTTP post over REST on the given (relative) URL with the given postBody.
 *
 * @param url/* w ww.  jav a  2  s .  c om*/
 *            The URL to post to.
 * @param postBody
 *            The content of the post.
 * @param responseTypeReference
 *            The type reference of the response.
 * @param <T> The type of the response.
 * @return The response object from the REST server.
 * @throws org.cloudifysource.restclient.exceptions.RestClientException
 *             Reporting failure to post the file.
 */
public <T> T postObject(final String url, final Object postBody,
        final TypeReference<Response<T>> responseTypeReference) throws RestClientException {
    final HttpEntity stringEntity;
    String jsonStr;
    try {
        jsonStr = new ObjectMapper().writeValueAsString(postBody);
        stringEntity = new StringEntity(jsonStr, "UTF-8");
    } catch (final IOException e) {
        throw MessagesUtils.createRestClientIOException(RestClientMessageKeys.SERIALIZATION_ERROR.getName(), e,
                url);
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "executing post request to " + url + ", tring to post object " + jsonStr);
    }
    return post(url, responseTypeReference, stringEntity);
}

From source file:org.glassfish.jersey.server.spring.SpringComponentProvider.java

@Override
public void initialize(ServiceLocator locator) {
    this.locator = locator;

    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.fine(LocalizationMessages.CTX_LOOKUP_STARTED());
    }/*www. j  a  va 2 s .  c  om*/

    ServletContext sc = locator.getService(ServletContext.class);

    if (sc != null) {
        // servlet container
        ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
    } else {
        // non-servlet container
        ApplicationHandler applicationHandler = locator.getService(ApplicationHandler.class);
        ApplicationContext springContext = (ApplicationContext) applicationHandler.getConfiguration()
                .getProperty(PARAM_SPRING_CONTEXT);
        if (springContext != null) {
            ctx = springContext;
        } else {
            String contextConfigLocation = (String) applicationHandler.getConfiguration()
                    .getProperty(PARAM_CONTEXT_CONFIG_LOCATION);
            ctx = createXmlSpringConfiguration(contextConfigLocation);
        }
    }
    if (ctx == null) {
        LOGGER.severe(LocalizationMessages.CTX_LOOKUP_FAILED());
        return;
    }
    LOGGER.config(LocalizationMessages.CTX_LOOKUP_SUCESSFUL());

    // initialize HK2 spring-bridge
    SpringBridge.getSpringBridge().initializeSpringBridge(locator);
    SpringIntoHK2Bridge springBridge = locator.getService(SpringIntoHK2Bridge.class);
    springBridge.bridgeSpringBeanFactory(ctx);

    // register Spring @Autowired annotation handler with HK2 ServiceLocator
    ServiceLocatorUtilities.addOneConstant(locator, new AutowiredInjectResolver(ctx));
    ServiceLocatorUtilities.addOneConstant(locator, ctx, "SpringContext", ApplicationContext.class);
    LOGGER.config(LocalizationMessages.SPRING_COMPONENT_PROVIDER_INITIALIZED());
}