Example usage for java.util.logging Level FINER

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

Introduction

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

Prototype

Level FINER

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

Click Source Link

Document

FINER indicates a fairly detailed tracing message.

Usage

From source file:com.ibm.jaggr.service.impl.AggregatorImpl.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
    if (log.isLoggable(Level.FINEST))
        log.finest("doGet: URL=" + req.getRequestURI()); //$NON-NLS-1$

    req.setAttribute(AGGREGATOR_REQATTRNAME, this);
    ConcurrentMap<String, Object> concurrentMap = new ConcurrentHashMap<String, Object>();
    req.setAttribute(CONCURRENTMAP_REQATTRNAME, concurrentMap);

    try {/*from w w  w.  j  av  a  2s .  co m*/
        // Validate config last-modified if development mode is enabled
        if (getOptions().isDevelopmentMode()) {
            long lastModified = -1;
            URI configUri = getConfig().getConfigUri();
            if (configUri != null) {
                lastModified = configUri.toURL().openConnection().getLastModified();
            }
            if (lastModified > getConfig().lastModified()) {
                if (reloadConfig()) {
                    // If the config has been modified, then dependencies will be revalidated
                    // asynchronously.  Rather than forcing the current request to wait, return
                    // a response that will display an alert informing the user of what is 
                    // happening and asking them to reload the page.
                    String content = "alert('" + //$NON-NLS-1$ 
                            StringUtil.escapeForJavaScript(Messages.ConfigModified) + "');"; //$NON-NLS-1$
                    resp.addHeader("Cache-control", "no-store"); //$NON-NLS-1$ //$NON-NLS-2$
                    CopyUtil.copy(new StringReader(content), resp.getOutputStream());
                    return;
                }
            }
        }

        getTransport().decorateRequest(req);
        notifyRequestListeners(RequestNotifierAction.start, req, resp);

        ILayer layer = getLayer(req);
        long modifiedSince = req.getDateHeader("If-Modified-Since"); //$NON-NLS-1$
        long lastModified = (Math.max(getCacheManager().getCache().getCreated(), layer.getLastModified(req))
                / 1000) * 1000;
        if (modifiedSince >= lastModified) {
            if (log.isLoggable(Level.FINER)) {
                log.finer("Returning Not Modified response for layer in servlet" + //$NON-NLS-1$
                        getName() + ":" //$NON-NLS-1$
                        + req.getAttribute(IHttpTransport.REQUESTEDMODULES_REQATTRNAME).toString());
            }
            resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        } else {
            // Get the InputStream for the response.  This call sets the Content-Type,
            // Content-Length and Content-Encoding headers in the response.
            InputStream in = layer.getInputStream(req, resp);
            // if any of the readers included an error response, then don't cache the layer.
            if (req.getAttribute(ILayer.NOCACHE_RESPONSE_REQATTRNAME) != null) {
                resp.addHeader("Cache-Control", "no-store"); //$NON-NLS-1$ //$NON-NLS-2$
            } else {
                resp.setDateHeader("Last-Modified", lastModified); //$NON-NLS-1$
                int expires = getConfig().getExpires();
                if (expires > 0) {
                    resp.addHeader("Cache-Control", "max-age=" + expires); //$NON-NLS-1$ //$NON-NLS-2$
                }
            }
            CopyUtil.copy(in, resp.getOutputStream());
        }
        notifyRequestListeners(RequestNotifierAction.end, req, resp);
    } catch (DependencyVerificationException e) {
        // clear the cache now even though it will be cleared when validateDeps has 
        // finished (asynchronously) so that any new requests will be forced to wait
        // until dependencies have been validated.
        getCacheManager().clearCache();
        getDependencies().validateDeps(false);

        resp.addHeader("Cache-control", "no-store"); //$NON-NLS-1$ //$NON-NLS-2$
        if (getOptions().isDevelopmentMode()) {
            String msg = StringUtil.escapeForJavaScript(MessageFormat.format(Messages.DepVerificationFailed,
                    new Object[] { e.getMessage(), AggregatorCommandProvider.EYECATCHER + " " + //$NON-NLS-1$
                            AggregatorCommandProvider.CMD_VALIDATEDEPS + " " + //$NON-NLS-1$
                            getName() + " " + //$NON-NLS-1$
                            AggregatorCommandProvider.PARAM_CLEAN,
                            getWorkingDirectory().toString().replace("\\", "\\\\") //$NON-NLS-1$ //$NON-NLS-2$
                    }));
            String content = "alert('" + msg + "');"; //$NON-NLS-1$ //$NON-NLS-2$
            try {
                CopyUtil.copy(new StringReader(content), resp.getOutputStream());
            } catch (IOException e1) {
                if (log.isLoggable(Level.SEVERE)) {
                    log.log(Level.SEVERE, e1.getMessage(), e1);
                }
                resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            }
        } else {
            resp.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        }
    } catch (ProcessingDependenciesException e) {
        resp.addHeader("Cache-control", "no-store"); //$NON-NLS-1$ //$NON-NLS-2$
        if (getOptions().isDevelopmentMode()) {
            String content = "alert('" + StringUtil.escapeForJavaScript(Messages.Busy) + "');"; //$NON-NLS-1$ //$NON-NLS-2$
            try {
                CopyUtil.copy(new StringReader(content), resp.getOutputStream());
            } catch (IOException e1) {
                if (log.isLoggable(Level.SEVERE)) {
                    log.log(Level.SEVERE, e1.getMessage(), e1);
                }
                resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            }
        } else {
            resp.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        }
    } catch (BadRequestException e) {
        exceptionResponse(req, resp, e, HttpServletResponse.SC_BAD_REQUEST);
    } catch (NotFoundException e) {
        exceptionResponse(req, resp, e, HttpServletResponse.SC_NOT_FOUND);
    } catch (Exception e) {
        exceptionResponse(req, resp, e, HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } finally {
        concurrentMap.clear();
    }
}

From source file:diet.gridr.g5k.gui.ClusterInfoPanel.java

/**
 * This method initializes jPanel1/*w w  w  .j a  v a2  s .  com*/
 *
 * @return javax.swing.JPanel
 */
private JPanel getJPanel1() {
    if (jPanel1 == null) {
        jPanel1 = new JPanel();
        jPanel1.setLayout(new BoxLayout(jPanel1, BoxLayout.X_AXIS));
        jPanel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        JPanel intermediaryPanel = new JPanel();
        intermediaryPanel.setLayout(new BoxLayout(intermediaryPanel, BoxLayout.Y_AXIS));
        nodesTable = new JTable();
        nodesModel = new ClusterNodesSummaryModel();
        nodesTable.setModel(nodesModel);
        JLabel nodesTableTitle = new JLabel("Nodes status");
        nodesTableTitle.setAlignmentX(JLabel.CENTER_ALIGNMENT);
        nodesTableTitle.setFont(new Font("Dialog", Font.BOLD, 14));
        intermediaryPanel.add(Box.createVerticalStrut(5));
        intermediaryPanel.add(nodesTableTitle);
        intermediaryPanel.add(Box.createVerticalStrut(10));
        intermediaryPanel.add(nodesTable.getTableHeader());
        intermediaryPanel.add(nodesTable);
        intermediaryPanel.add(Box.createVerticalStrut(10));
        intermediaryPanel.add(new JSeparator(JSeparator.HORIZONTAL));
        jPanel1.add(Box.createHorizontalGlue());
        jPanel1.add(intermediaryPanel);
        jPanel1.add(Box.createHorizontalGlue());
        LoggingManager.log(Level.FINER, LoggingManager.RESOURCESTOOL, this.getClass().getName(), "getJPanel1",
                "Cluster nodes summary table added");
    }
    return jPanel1;
}

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

/**
 * The main loop of the engine./*from  w ww. j  a v a 2s . com*/
 * Removes the old views
 */
@Override
public void executeStep() {

    //if for some reason you start getting views before you are done changing things, then you will need to deprecate them again

    //Run the Actions
    //This is based on 3 factors: the last state, spaces/resources/nodes with pending actions that are not known to be failures, and spaces/resources/nodes that are known to be failures

    //The basic procedure is (list and set are used colloquially, and may be implemented as other things):
    //if compound, check if you can do the action in the last state, recalculate if needed
    //if it is the last one in a compound,
    //check if you can do the action in general/based on last state
    //if you can't, put yourself on a fail list and stop processing this action
    //if you are a durative action that won't complete this step, put yourself on the successful list then stop processing this action
    //check if what you would effect is in the list of those with known problematic claims
    //if it is problematic, then put yourself on the fail list and stop processing this action
    //add your effect to the claims list
    //check if the claims including yourself will now cause a problem
    //if it will, mark yourself and all others claiming it on the failed list (removing them from the successful list too), and remove it from the claims list and put it on the known problematic list
    //if it will not cause a problem, mark yourself on the successful list and stop processing this action
    //after all actions have been checked and claimed
    //execute and log all actions remaining in the successful list
    //log all failed actions, and remove them from the queue

    //interpret coordinates as integers
    Map<Integer, ActionQueue> claimedspaces = new HashMap<Integer, ActionQueue>(); //merge the boolean for whether it has claimed with the set of actions that claimed it, and since one is known to be enough, don't need a set
    Set<Integer> problemspaces = new HashSet<Integer>();//places that you know are problems
    Map<Integer, Integer> claimedgathering = new HashMap<Integer, Integer>();//<nodeid,amountclaimed>
    Map<Integer, Set<ActionQueue>> claimedgatheringactions = new HashMap<Integer, Set<ActionQueue>>();//<nodeid,claimingactions>
    Set<Integer> problemgatherings = new HashSet<Integer>();//<problemnodeids>
    Map<Integer, Map<ResourceType, Integer>> claimedcosts = new HashMap<Integer, Map<ResourceType, Integer>>();//<player,<resourcetype,amountclaimed>>
    Map<Integer, Map<ResourceType, Set<ActionQueue>>> claimedcostactions = new HashMap<Integer, Map<ResourceType, Set<ActionQueue>>>();//<player,<resourcetypes,claimingactions>>
    Map<Integer, Set<ResourceType>> problemcosts = new HashMap<Integer, Set<ResourceType>>();//<player, problemresourcetypes>
    Map<Integer, Integer> claimedfoodcosts = new HashMap<Integer, Integer>();//<player,amountclaimed>
    Map<Integer, Set<ActionQueue>> claimedfoodcostactions = new HashMap<Integer, Set<ActionQueue>>();//<player,claimingactions>
    Set<Integer> problemfoodcosts = new HashSet<Integer>();//<problemplayer>
    Set<ActionQueue> failed = new HashSet<ActionQueue>();
    Set<ActionQueue> successfulsofar = new HashSet<ActionQueue>();
    /** Track all units of active players, to reset their progress if they failed or weren't moved*/
    Set<Integer> unsuccessfulUnits = new HashSet<Integer>();
    Set<ActionQueue> productionsuccessfulsofar = new HashSet<ActionQueue>();
    for (Integer player : queuedActions.keySet()) {
        if (turnTracker == null || turnTracker.isPlayersTurn(player)) {
            //Gather all units of that player, so that we can remove the ones that were successful later
            for (Integer id : state.getUnits(player).keySet()) {
                unsuccessfulUnits.add(id);
            }
            Iterator<Entry<Integer, ActionQueue>> playerActions = queuedActions.get(player).entrySet()
                    .iterator();
            while (playerActions.hasNext()) {
                Entry<Integer, ActionQueue> entry = playerActions.next();
                ;
                ActionQueue aq = entry.getValue();
                //            if (a==null) //Then it failed to calculate primitives, so it fails
                int uid = entry.getKey();
                Unit u = state.getUnit(uid);
                if (u == null || uid != aq.getFullAction().getUnitId()) {
                    //unit is dead or never existed
                    playerActions.remove();
                    history.recordCommandFeedback(player, state.getTurnNumber(),
                            new ActionResult(aq.getFullAction(), ActionResultType.INVALIDUNIT));

                } else {
                    aq.resetPrimitives(calculatePrimitives(aq.getFullAction()));
                    Action a = aq.peekPrimitive();
                    if (a == null) //This happens when you try to compound move to where you are, not sure about other cases
                    {
                        playerActions.remove();
                        history.recordCommandFeedback(player, state.getTurnNumber(),
                                new ActionResult(aq.getFullAction(), ActionResultType.COMPLETED));
                    } else if (!ActionType.isPrimitive(a.getType())) {
                        throw new RuntimeException(
                                "This should never happen, all subactions should be primitives");
                    } else if (a.getType() == ActionType.PRIMITIVEATTACK && !(a instanceof TargetedAction)
                            || a.getType() == ActionType.PRIMITIVEGATHER && !(a instanceof DirectedAction)
                            || a.getType() == ActionType.PRIMITIVEDEPOSIT && !(a instanceof DirectedAction)
                            || a.getType() == ActionType.PRIMITIVEPRODUCE && !(a instanceof ProductionAction)
                            || a.getType() == ActionType.PRIMITIVEBUILD && !(a instanceof ProductionAction)
                            || a.getType() == ActionType.PRIMITIVEMOVE && !(a instanceof DirectedAction)) {//shouldn't have to do this, should make actions so it is never possible to have the types not match
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   //log a wrong type thing
                        history.recordCommandFeedback(player, state.getTurnNumber(),
                                new ActionResult(aq.getFullAction(), ActionResultType.INVALIDTYPE));
                        //remove it from the queues
                        playerActions.remove();
                    } else {

                        if (a.getType() == ActionType.FAILED || a.getType() == ActionType.FAILEDPERMANENTLY) {
                            failed.add(aq);
                            //recalcAndStuff();//This marks a place where recalculation would be called for
                        }
                        //check if it is a move
                        if (a.getType() == ActionType.PRIMITIVEMOVE) {
                            //if it can't move, that is a problem
                            if (!u.canMove()) {
                                logger.log(Level.FINER,
                                        "Unit " + u + " unable to move, action " + a + " failed");
                                failed.add(aq);
                                //recalcAndStuff();//This marks a place where recalculation would be called for
                            } else //hasn't failed yet
                            {
                                //find out where it will be next

                                DirectedAction da = (DirectedAction) a;
                                Direction d = da.getDirection();
                                int xdest = u.getXPosition() + d.xComponent();
                                int ydest = u.getYPosition() + d.yComponent();

                                //if it is not empty there is a problem
                                if (!accessible(u, xdest, ydest)) {
                                    failed.add(aq);
                                    //recalcAndStuff();//This marks a place where recalculation would be called for
                                } else //hasn't failed yet
                                {
                                    int newdurativeamount;
                                    if (da.equals(u.getActionProgressPrimitive())) {
                                        newdurativeamount = u.getActionProgressAmount() + 1;
                                    } else {
                                        newdurativeamount = 1;
                                    }
                                    boolean willcompletethisturn = newdurativeamount == DurativePlanner
                                            .calculateMoveDuration(u, u.getXPosition(), u.getYPosition(), d,
                                                    state);
                                    //if it will finish, then verify claim stuff
                                    if (willcompletethisturn) {
                                        Integer dest = getCoordInt(xdest, ydest);
                                        //check if the space is a problem
                                        if (problemspaces.contains(dest)) {
                                            failed.add(aq);
                                        } else //not a problem space
                                        {
                                            //check if it is claimed
                                            ActionQueue priorclaimant = claimedspaces.get(dest);
                                            if (priorclaimant != null) {//it is claimed
                                                successfulsofar.remove(priorclaimant);
                                                failed.add(priorclaimant);
                                                failed.add(aq);
                                                problemspaces.add(dest);
                                                claimedspaces.remove(dest); //remove all claims, as it is now a problem, not a claim, may be pointless
                                            } else {//it is not claimed
                                                    //so claim it
                                                claimedspaces.put(dest, aq);
                                                successfulsofar.add(aq);
                                            }
                                        }
                                    } else //won't complete, so passes all claims
                                    {
                                        successfulsofar.add(aq);
                                    }
                                }
                            }
                        }

                        else if (a.getType() == ActionType.PRIMITIVEDEPOSIT) {
                            if (!u.canGather() || u.getCurrentCargoAmount() <= 0) {//if can't gather or isn't carrying anything, then this isn't an acceptible action
                                failed.add(aq);
                                //recalcAndStuff();//This marks a place where recalculation would be called for
                            } else {
                                DirectedAction da = (DirectedAction) a;
                                Direction d = da.getDirection();
                                int xdest = u.getXPosition() + d.xComponent();
                                int ydest = u.getYPosition() + d.yComponent();
                                Unit townHall = state.unitAt(xdest, ydest);
                                if (townHall == null || townHall.getPlayer() != u.getPlayer()) {//no unit there on your team
                                    failed.add(aq);
                                    //recalcAndStuff();//This marks a place where recalculation would be called for
                                } else //there is a unit on your team
                                {
                                    //check if the unit can accept the kind of resources that you have
                                    boolean canAccept = townHall.getTemplate()
                                            .canAccept(u.getCurrentCargoType());
                                    if (!canAccept) {//then it isn't a town hall of the right type
                                        failed.add(aq);
                                        //recalcAndStuff();//This marks a place where recalculation would be called for
                                    } else //there is an appropriate town hall there
                                    {
                                        //deposit has no chance of conflicts, so this works
                                        successfulsofar.add(aq);
                                    }
                                }
                            }
                        } else if (a.getType() == ActionType.PRIMITIVEATTACK) {
                            //make sure you can attack and the target exists and is in range in the last state
                            if (!u.canAttack()) {
                                failed.add(aq);
                                //recalcAndStuff();//This marks a place where recalculation would be called for
                            } else {
                                TargetedAction ta = (TargetedAction) a;
                                Unit target = state.getUnit(ta.getTargetId());
                                if (target == null || target.getCurrentHealth() <= 0 || !inRange(u, target)) {
                                    failed.add(aq);
                                    //recalcAndStuff();//This marks a place where recalculation would be called for
                                } else //target exists and is in range
                                {
                                    //no possibility for conflict, so this succeeds
                                    successfulsofar.add(aq);
                                }
                            }
                        } else if (a.getType() == ActionType.PRIMITIVEPRODUCE
                                || a.getType() == ActionType.PRIMITIVEBUILD) {//currently, this adds to productionsuccessfulsofar because they are not processed consistantly
                                                                                                                                    //consistancy could be restored by making unit production and building actions require a place or direction for the new unit to go, and then processing it as a move

                            //last state check:
                            ProductionAction pa = (ProductionAction) a;
                            Template<?> t = state.getTemplate(pa.getTemplateId());
                            if (a.getType() == ActionType.PRIMITIVEPRODUCE && u.canBuild()
                                    || a.getType() == ActionType.PRIMITIVEBUILD && !u.canBuild()) {//if it should build and is trying to produce or should produce and is trying to build
                                failed.add(aq);
                                //recalcAndStuff();//This marks a place where recalculation would be called for
                            } else if (t == null || !u.getTemplate().canProduce(t)
                                    || !(prerequisitesMet(t, u.getPlayer()))) {//if the template does not exist or the unit cannot make the template or the template's prerequisites are not met
                                failed.add(aq);
                                //recalcAndStuff();//This marks a place where recalculation would be called for
                            } else //template exists, is producable by the unit, and has it's tech-tree prerequisites met
                            {
                                int newdurativeamount;
                                if (pa.equals(u.getActionProgressPrimitive())) {
                                    newdurativeamount = u.getActionProgressAmount() + 1;
                                } else {
                                    newdurativeamount = 1;
                                }
                                boolean willcompletethisturn = newdurativeamount == DurativePlanner
                                        .calculateProductionDuration(u, t);
                                if (willcompletethisturn) {
                                    if (!problemcosts.containsKey(player))
                                        problemcosts.put(player, new HashSet<ResourceType>());
                                    if (!claimedcosts.containsKey(player))
                                        claimedcosts.put(player, new HashMap<ResourceType, Integer>());
                                    if (!claimedcostactions.containsKey(player))
                                        claimedcostactions.put(player,
                                                new HashMap<ResourceType, Set<ActionQueue>>());
                                    boolean failedaclaim = false;

                                    //check all the resources, including supply for problems and claims
                                    //note that if you don't need any, it doesn't matter if it is overdrawn
                                    //do all even if one fails, because if you stop checking when you fail one resource and don't claim the others, then another production that should conflict will not be detected as such
                                    {
                                        int goldneeded = t.getGoldCost();
                                        //if you have a cost, then check the claims
                                        if (goldneeded > 0) {
                                            //check if it is a problem
                                            if (problemcosts.get(player).contains(ResourceType.GOLD)) {
                                                failedaclaim = true;
                                            } else {//not a problem already, check claims
                                                    //get the amount of the resource that you had before
                                                int previousamount = state.getResourceAmount(player,
                                                        ResourceType.GOLD);
                                                // get the previous claim (if there is none, that is zero)
                                                Integer previousclaim = claimedcosts.get(player)
                                                        .get(ResourceType.GOLD);
                                                if (previousclaim == null)
                                                    previousclaim = 0;
                                                int updatedclaim = previousclaim + goldneeded;

                                                //check if the total claim is more than the amount the player has
                                                if (updatedclaim > previousamount) {
                                                    //if the claim is more, then this and all others with claims on this resource fail
                                                    Set<ActionQueue> otherclaimants = claimedcostactions
                                                            .get(player).get(ResourceType.GOLD);
                                                    if (otherclaimants != null) {
                                                        for (ActionQueue otherclaimant : otherclaimants) {
                                                            productionsuccessfulsofar.remove(otherclaimant);
                                                            failed.add(otherclaimant);
                                                        }
                                                        //since we are marking this as a problem, don't need the claim anymore
                                                        claimedcostactions.get(player)
                                                                .remove(ResourceType.GOLD);
                                                    }
                                                    failedaclaim = true;
                                                    problemcosts.get(player).add(ResourceType.GOLD);
                                                } else {//not too much, so claim it
                                                    claimedcosts.get(player).put(ResourceType.GOLD,
                                                            updatedclaim);
                                                    if (!claimedcostactions.get(player)
                                                            .containsKey(ResourceType.GOLD)) {
                                                        claimedcostactions.get(player).put(ResourceType.GOLD,
                                                                new HashSet<ActionQueue>());
                                                    }
                                                    claimedcostactions.get(player).get(ResourceType.GOLD)
                                                            .add(aq);
                                                }
                                            }
                                        }
                                    }
                                    {
                                        int woodneeded = t.getWoodCost();
                                        //if you have a cost, then check the claims
                                        if (woodneeded > 0) {
                                            //check if it is a problem
                                            if (problemcosts.get(player).contains(ResourceType.WOOD)) {
                                                failedaclaim = true;
                                            } else {//not a problem already, check claims
                                                    //get the amount of the resource that you had before
                                                int previousamount = state.getResourceAmount(player,
                                                        ResourceType.WOOD);
                                                // get the previous claim (if there is none, that is zero)
                                                Integer previousclaim = claimedcosts.get(player)
                                                        .get(ResourceType.WOOD);
                                                if (previousclaim == null)
                                                    previousclaim = 0;
                                                int updatedclaim = previousclaim + woodneeded;

                                                //check if the total claim is more than the amount the player has
                                                if (updatedclaim > previousamount) {
                                                    //if the claim is more, then this and all others with claims on this resource fail
                                                    Set<ActionQueue> otherclaimants = claimedcostactions
                                                            .get(player).get(ResourceType.WOOD);
                                                    if (otherclaimants != null) {
                                                        for (ActionQueue otherclaimant : otherclaimants) {
                                                            productionsuccessfulsofar.remove(otherclaimant);
                                                            failed.add(otherclaimant);
                                                        }
                                                        //since we are marking this as a problem, don't need the claim anymore
                                                        claimedcostactions.get(player)
                                                                .remove(ResourceType.WOOD);
                                                    }
                                                    failedaclaim = true;
                                                    problemcosts.get(player).add(ResourceType.WOOD);
                                                } else {//not too much, so claim it
                                                    claimedcosts.get(player).put(ResourceType.WOOD,
                                                            updatedclaim);
                                                    if (!claimedcostactions.get(player)
                                                            .containsKey(ResourceType.WOOD)) {
                                                        claimedcostactions.get(player).put(ResourceType.WOOD,
                                                                new HashSet<ActionQueue>());
                                                    }
                                                    claimedcostactions.get(player).get(ResourceType.WOOD)
                                                            .add(aq);
                                                }
                                            }
                                        }
                                    }
                                    {
                                        int foodneeded = t.getFoodCost();
                                        //if you have a cost, then check the claims
                                        if (foodneeded > 0) {
                                            //check if it is a problem
                                            if (problemfoodcosts.contains(player)) {
                                                failedaclaim = true;
                                            } else {//not a problem already, check claims
                                                    //get the amount of the resource that you had before
                                                int previousamount = state.getSupplyCap(player)
                                                        - state.getSupplyAmount(player);
                                                // get the previous claim (if there is none, that is zero)
                                                Integer previousclaim = claimedfoodcosts.get(player);
                                                if (previousclaim == null)
                                                    previousclaim = 0;
                                                int updatedclaim = previousclaim + foodneeded;

                                                //check if the total claim is more than the amount the player has
                                                if (updatedclaim > previousamount) {
                                                    //if the claim is more, then this and all others with claims on this resource fail
                                                    Set<ActionQueue> otherclaimants = claimedfoodcostactions
                                                            .get(player);
                                                    if (otherclaimants != null) {
                                                        for (ActionQueue otherclaimant : otherclaimants) {
                                                            productionsuccessfulsofar.remove(otherclaimant);
                                                            failed.add(otherclaimant);
                                                        }
                                                        //since we are marking this as a problem, don't need the claim anymore
                                                        claimedfoodcostactions.remove(player);
                                                    }
                                                    failedaclaim = true;
                                                    problemfoodcosts.add(player);
                                                } else {//not too much, so claim it
                                                    claimedfoodcosts.put(player, updatedclaim);
                                                    if (!claimedfoodcostactions.containsKey(player)) {
                                                        claimedfoodcostactions.put(player,
                                                                new HashSet<ActionQueue>());
                                                    }
                                                    claimedfoodcostactions.get(player).add(aq);
                                                }
                                            }
                                        }
                                    }

                                    if (failedaclaim) {
                                        failed.add(aq);
                                    } else {
                                        productionsuccessfulsofar.add(aq);
                                    }

                                } else //won't complete, so passes all claims
                                {
                                    successfulsofar.add(aq);
                                }
                            }

                        } else if (a.getType() == ActionType.PRIMITIVEGATHER) {
                            //check if it can gather at all
                            if (!u.canGather()) {
                                failed.add(aq);
                                //recalcAndStuff();//This marks a place where recalculation would be called for
                            } else //it can gather
                            {
                                //find the node you want to gather from, and make sure it exists
                                DirectedAction da = (DirectedAction) a;
                                Direction d = da.getDirection();
                                int xdest = u.getXPosition() + d.xComponent();
                                int ydest = u.getYPosition() + d.yComponent();
                                ResourceNode rn = state.resourceAt(xdest, ydest);
                                //check if the node exists and was not exhausted last turn
                                if (rn == null || rn.getAmountRemaining() <= 0) {
                                    failed.add(aq);
                                    //recalcAndStuff();//This marks a place where recalculation would be called for
                                } else //there is a node and it has resources
                                {
                                    int newdurativeamount;
                                    if (da.equals(u.getActionProgressPrimitive())) {
                                        newdurativeamount = u.getActionProgressAmount() + 1;
                                    } else {
                                        newdurativeamount = 1;
                                    }
                                    boolean willcompletethisturn = newdurativeamount == DurativePlanner
                                            .calculateGatherDuration(u, rn);
                                    if (willcompletethisturn) {

                                        //then check if the node will be a problem
                                        if (problemgatherings.contains(rn.id)) {
                                            failed.add(aq);
                                        } else //no problem yet
                                        {

                                            //so test out the new claim
                                            int previousamount = rn.getAmountRemaining();
                                            boolean isotherclaimant = true;
                                            Integer otherclaims = claimedgathering.get(rn.id);
                                            //if there is no other claim, then the other claim is 0, and it should be noted that noone else is claiming it
                                            if (otherclaims == null) {
                                                isotherclaimant = false;
                                                otherclaims = 0;
                                            }
                                            int updatedclaim = otherclaims
                                                    + u.getTemplate().getGatherRate(rn.getType().getResource());
                                            //if the claim is too much, then the node has a problem
                                            //but don't fail if this is the only claimant
                                            //in that case, the result should be that this mines out the resource
                                            if (updatedclaim > previousamount && isotherclaimant) {
                                                //the node is a problem, so make all claimants fail and mark it as such
                                                problemgatherings.add(rn.id);
                                                for (ActionQueue otherclaimant : claimedgatheringactions
                                                        .get(rn.id)) {
                                                    successfulsofar.remove(otherclaimant);
                                                    failed.add(otherclaimant);
                                                }
                                                failed.add(aq);
                                                claimedgatheringactions.remove(rn.id);
                                            } else //the state isn't a problem
                                            {
                                                //so make the claim and succeed
                                                claimedgathering.put(rn.id, updatedclaim);
                                                //make sure the set is initialized
                                                if (!claimedgatheringactions.containsKey(rn.id))
                                                    claimedgatheringactions.put(rn.id,
                                                            new HashSet<ActionQueue>());
                                                claimedgatheringactions.get(rn.id).add(aq);
                                                successfulsofar.add(aq);
                                            }
                                        }

                                    } else //won't complete, so passes all claims
                                    {
                                        successfulsofar.add(aq);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    //to make production spawning as consistant yet sequential as possible, find positions that weren't occupied before and which weren't claimed by moves or other production actions
    //need to avoid claimed spaces so that the inconsistancy doesn't break move's consistancy
    //so calculate now and use later
    Map<ActionQueue, int[]> productionplaces = new HashMap<ActionQueue, int[]>();

    {
        Set<Integer> productionclaimedspaces = new HashSet<Integer>();
        boolean nomorespaces = false;//once you run out of spaces, no further productions that make units will succeed
        Set<Integer> moveclaimedspaces = claimedspaces.keySet(); //grab the spaces claimed by move, it shouldn't change during this
        for (ActionQueue aq : productionsuccessfulsofar) {
            //only production actions that will complete should be in productionsuccessfulsofar
            ProductionAction a = (ProductionAction) aq.peekPrimitive();
            Unit u = state.getUnit(a.getUnitId());
            Template<?> producedTemplate = state.getTemplate(a.getTemplateId());
            //check if it is an upgrade and thus doesn't risk failure and can just succeed
            if (producedTemplate instanceof UpgradeTemplate) {
                successfulsofar.add(aq);
            } else //will be a unit/building, needs to reserve a space
            {
                if (nomorespaces) {//if you ran out of spaces before, then there is no point trying again, as it will be no better
                    failed.add(aq);
                } else {
                    //find the nearest open position, which will be null if there is none
                    int[] newposition = getClosestEmptyUnclaimedPosition((UnitTemplate) producedTemplate,
                            u.getXPosition(), u.getYPosition(), moveclaimedspaces, productionclaimedspaces);
                    if (newposition == null) {//if no place for new unit
                                              //then this fails
                        failed.add(aq);
                        nomorespaces = true;
                    } else //there is a place for the new unit
                    {
                        //so reserve the new position and mark as successful
                        productionplaces.put(aq, newposition);
                        productionclaimedspaces.add(getCoordInt(newposition[0], newposition[1]));
                        successfulsofar.add(aq);
                    }
                }

            }
        }
    }

    //Take all of the actions that haven't failed yet and execute them
    for (ActionQueue aq : successfulsofar) {
        //Mark it's unit as having moved successfully
        unsuccessfulUnits.remove(aq.getFullAction().getUnitId());

        //execute it without further checking, logging it
        Action a = aq.popPrimitive();
        int uid = a.getUnitId();
        Unit u = state.getUnit(uid);
        boolean willcompletethisturn = true;
        {
            //check if it is a move
            if (a.getType() == ActionType.PRIMITIVEMOVE) {
                //if it can't move, that is a problem
                {
                    //find out where it will be next

                    DirectedAction da = (DirectedAction) a;
                    Direction d = da.getDirection();
                    //calculate the amount of duration
                    int newdurativeamount;
                    if (da.equals(u.getActionProgressPrimitive())) {
                        newdurativeamount = u.getActionProgressAmount() + 1;
                    } else {
                        newdurativeamount = 1;
                    }
                    willcompletethisturn = newdurativeamount == DurativePlanner.calculateMoveDuration(u,
                            u.getXPosition(), u.getYPosition(), d, state);
                    //if it will finish, then execute the atomic action
                    if (willcompletethisturn) {
                        //do the atomic action
                        state.moveUnit(u, d);
                        //you did the action, so reset the progress
                        u.resetDurative();
                    } else {
                        //increment the duration
                        u.setDurativeStatus(da, newdurativeamount);
                    }
                }
            }

            if (a.getType() == ActionType.PRIMITIVEDEPOSIT) {
                DirectedAction da = (DirectedAction) a;
                Direction d = da.getDirection();
                int xdest = u.getXPosition() + d.xComponent();
                int ydest = u.getYPosition() + d.yComponent();
                Unit townHall = state.unitAt(xdest, ydest);

                //calculate the amount of duration
                int newdurativeamount;
                if (da.equals(u.getActionProgressPrimitive())) {
                    newdurativeamount = u.getActionProgressAmount() + 1;
                } else {
                    newdurativeamount = 1;
                }
                willcompletethisturn = newdurativeamount == DurativePlanner.calculateDepositDuration(u,
                        townHall);
                //if it will finish, then execute the atomic action
                if (willcompletethisturn) {
                    //do the atomic action
                    int player = townHall.getPlayer();
                    history.recordResourceDropoff(u, townHall, state);
                    state.addResourceAmount(player, u.getCurrentCargoType(), u.getCurrentCargoAmount());
                    u.clearCargo();
                    //you completed the action, so reset the durative progress
                    u.resetDurative();
                } else {
                    //increment the duration
                    u.setDurativeStatus(da, newdurativeamount);
                }
            }
            if (a.getType() == ActionType.PRIMITIVEATTACK) {
                //make sure you can attack and the target exists and is in range in the last state
                TargetedAction ta = (TargetedAction) a;
                Unit target = state.getUnit(ta.getTargetId());
                int newdurativeamount;
                if (ta.equals(u.getActionProgressPrimitive())) {
                    newdurativeamount = u.getActionProgressAmount() + 1;
                } else {
                    newdurativeamount = 1;
                }
                willcompletethisturn = newdurativeamount == DurativePlanner.calculateAttackDuration(u, target);
                //if it will finish, then execute the atomic action
                if (willcompletethisturn) {
                    //do the atomic action
                    int damage = calculateDamage(u, target);
                    history.recordDamage(u, target, damage, state);
                    target.setHP(Math.max(target.getCurrentHealth() - damage, 0));
                    //you have finished the primitive, so progress resets
                    u.resetDurative();
                } else {
                    //increment the duration
                    u.setDurativeStatus(ta, newdurativeamount);
                }
            }
            if (a.getType() == ActionType.PRIMITIVEPRODUCE || a.getType() == ActionType.PRIMITIVEBUILD) {
                //last state check:
                ProductionAction pa = (ProductionAction) a;
                @SuppressWarnings("rawtypes")
                Template t = state.getTemplate(pa.getTemplateId());
                //the willcomplete is somewhat related to the production amount
                int newdurativeamount;
                if (pa.equals(u.getActionProgressPrimitive())) {
                    newdurativeamount = u.getActionProgressAmount() + 1;
                } else {
                    newdurativeamount = 1;
                }
                willcompletethisturn = newdurativeamount == DurativePlanner.calculateProductionDuration(u, t);
                //if it will finish, then execute the atomic action
                if (willcompletethisturn) {
                    //do the atomic action
                    if (t instanceof UnitTemplate) {
                        Unit produced = ((UnitTemplate) t).produceInstance(state);
                        int[] newxy = productionplaces.get(aq);
                        if (u.canBuild()) {
                            int oldx = u.getXPosition();
                            int oldy = u.getYPosition();
                            state.transportUnit(u, newxy[0], newxy[1]);
                            if (state.tryProduceUnit(produced, oldx, oldy)) {
                                history.recordBirth(produced, u, state);
                            }
                        } else {
                            if (state.tryProduceUnit(produced, newxy[0], newxy[1])) {
                                history.recordBirth(produced, u, state);
                            }
                        }
                    } else if (t instanceof UpgradeTemplate) {
                        UpgradeTemplate upgradetemplate = ((UpgradeTemplate) t);
                        if (state.tryProduceUpgrade(upgradetemplate.produceInstance(state))) {
                            history.recordUpgrade(upgradetemplate, u, state);
                        }
                    }
                    //you have finished the primitive, so progress resets
                    u.resetDurative();
                } else {
                    //increment the duration
                    u.setDurativeStatus(pa, newdurativeamount);
                }
            }
            if (a.getType() == ActionType.PRIMITIVEGATHER) {
                //check if it can gather at all
                //find the right node
                DirectedAction da = (DirectedAction) a;
                Direction d = da.getDirection();
                int xdest = u.getXPosition() + d.xComponent();
                int ydest = u.getYPosition() + d.yComponent();
                ResourceNode rn = state.resourceAt(xdest, ydest);
                int newdurativeamount;
                if (da.equals(u.getActionProgressPrimitive())) {
                    newdurativeamount = u.getActionProgressAmount() + 1;
                } else {
                    newdurativeamount = 1;
                }
                willcompletethisturn = newdurativeamount == DurativePlanner.calculateGatherDuration(u, rn);
                //if it will finish, then execute the atomic action
                if (willcompletethisturn) {
                    //do the atomic action
                    int amountPickedUp = rn
                            .reduceAmountRemaining(u.getTemplate().getGatherRate(rn.getType().getResource()));
                    u.setCargo(rn.getResourceType(), amountPickedUp);
                    history.recordResourcePickup(u, rn, amountPickedUp, state);
                    //you have finished the primitive, so progress resets
                    u.resetDurative();
                } else {
                    //increment the duration
                    u.setDurativeStatus(da, newdurativeamount);
                }

            }
        }

        ActionResultType compoundFeedback;
        ActionResultType primitiveFeedback = willcompletethisturn ? ActionResultType.COMPLETED
                : ActionResultType.INCOMPLETE;
        if (!aq.hasNext()) {
            if (willcompletethisturn) {
                queuedActions.get(u.getPlayer()).remove(aq.getFullAction().getUnitId());
                compoundFeedback = ActionResultType.COMPLETED;
            } else {
                compoundFeedback = ActionResultType.INCOMPLETE;
            }

        } else {
            compoundFeedback = ActionResultType.INCOMPLETE;
        }
        history.recordCommandFeedback(state.getUnit(aq.getFullAction().getUnitId()).getPlayer(),
                state.getTurnNumber(), new ActionResult(aq.getFullAction(), compoundFeedback));
        history.recordPrimitiveFeedback(state.getUnit(aq.getFullAction().getUnitId()).getPlayer(),
                state.getTurnNumber(), new ActionResult(a, primitiveFeedback));
    }
    for (ActionQueue aq : failed) {
        //should be safe to get the unitid, as it should have not been put into failed if the player was bad
        history.recordCommandFeedback(state.getUnit(aq.getFullAction().getUnitId()).getPlayer(),
                state.getTurnNumber(), new ActionResult(aq.getFullAction(), ActionResultType.FAILED));
        history.recordPrimitiveFeedback(state.getUnit(aq.getFullAction().getUnitId()).getPlayer(),
                state.getTurnNumber(), new ActionResult(aq.peekPrimitive(), ActionResultType.FAILED));
        queuedActions.get(state.getUnit(aq.getFullAction().getUnitId()).getPlayer())
                .remove(aq.getFullAction().getUnitId());
    }

    //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);
    }

    //Reset the progress of any unit of an active player that was unable to successfully move
    for (Integer id : unsuccessfulUnits) {
        //Grab the unsuccessful unit
        Unit slacker = state.getUnit(id);
        //Reset the progress of the unsuccessful unit if it didn't die or something
        if (slacker != null) {
            slacker.resetDurative();
        }
    }

    state.incrementTurn();
    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();
}

From source file:core.module.codec.EncodeDecodeOtaMessage.java

public static InboundMessage decodeOtaMessage(GlucoMon glucoMon, Date messageSubmitDate, InputStream is)
        throws IOException, InvalidKeyException {
    InputStream clearTextInputStream;
    boolean is19BitDateFormat = false;//remove dependency on /etc/opt/diabetech/...  these are not in production any more and this is safest way to modify code (e.g. don't modify it much) GlucoMonTimeStampFormatUtil.is19BitDateFormat( glucoMon );
    //2A 11 81 FF4EB3AD 54A5E14A ECB2108B 0E0A6580

    int messageId = is19BitDateFormat ? 0 : is.read();
    logger.finer("messageId=" + messageId);

    if (glucoMon.isEncrypted()) {
        logger.finer("Decrypt message");
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int b = 0;
        while ((b = is.read()) != -1) {
            baos.write(b);/*from ww w  . jav  a  2s .  c  om*/
        }
        byte[] cipherText = baos.toByteArray();

        if (isEncryptedInboundMessage(cipherText)) {
            byte command = cipherText[0];
            byte length = cipherText[1];
            byte parameter = cipherText[2];

            // based on which command and parameter combination; set offset to 2 or 3.
            int offset = 0;
            switch (command) {
            case (byte) RETRIEVE_COMMAND_RESPONSE:
            case (byte) SEND_READING_NORMAL_RESPONSE:
            case (byte) SEND_READING_ALARM_RESPONSE:
                // subtract message id for new format
                offset = is19BitDateFormat ? 2 : 1;
                break;
            case (byte) GET_PARAMETER_ACK:
                // subtract message id for new format
                // parms all working ok w/ 3 offset
                // offset = is19BitDateFormat ? 3 : 2;
                offset = 3;
                break;
            default:
                throw new IllegalArgumentException("Incorrectly set offset in decryption routine");
            }

            byte[] payload = new byte[cipherText.length - offset];
            System.arraycopy(cipherText, offset, payload, 0, payload.length);

            // put together in cleartext message array
            Crypt crypt = new Crypt();
            byte[] plainTextPayload = crypt.decrypt(payload, glucoMon.getSecretKey());

            logger.log(Level.FINER, "plainTextPayload={0}\npayload={1}\ncipherText={2}",
                    new Object[] { plainTextPayload.length, payload.length, cipherText.length });
            // copy plaintext payload back in to payload array.
            System.arraycopy(plainTextPayload, 0, cipherText, offset, plainTextPayload.length);

            clearTextInputStream = new ByteArrayInputStream(cipherText);
        } else {
            logger.finer("Encrypted glucoMon, message type is cleartext");
            clearTextInputStream = new ByteArrayInputStream(cipherText);
        }
    } else {
        logger.finer("glucoMon is NOT encrypted");
        clearTextInputStream = is;
    }

    // once it is decrypted, decode as normal.
    return decode(messageSubmitDate, clearTextInputStream, is19BitDateFormat);
}

From source file:fungus.HyphaLink.java

public void transferNeighbor(MycoNode neighbor, MycoNode target) {
    if (neighbor != null && target != null) {
        if (neighbor == target) {
            log.log(Level.FINER, myNode + " TRIED TO TRANSFER " + neighbor + " TO ITSELF.",
                    new Object[] { myNode, neighbor });
            return;
        }/* w  ww. j a  va 2 s  .  c om*/
        neighbors.remove(neighbor);
        fireLinkRemoved(neighbor);
        HyphaLink neighborLink = ((HyphaLink) neighbor.getProtocol(hyphaLinkPid));
        neighborLink.pruneNeighbor(myNode);

        if (areNeighbors(neighbor, target)) {
            log.log(Level.FINER, myNode + " TRIED TO TRANSFER " + target + " TO " + neighbor
                    + " BUT ARE ALREADY " + "CONNECTED", new Object[] { myNode, neighbor, target });
            return;
        }
        log.log(Level.FINER, myNode + " TRANSFERS " + neighbor + " TO " + target,
                new Object[] { myNode, neighbor, target });
        HyphaLink targetLink = target.getHyphaLink();
        targetLink.addNeighbor(neighbor);
    } else {
        log.log(Level.WARNING, "BAD TRANSFER attempted from " + myNode + " TO " + target,
                new Object[] { myNode, neighbor, target });
        (new Throwable()).printStackTrace();
        //FIXME: Warning
    }
}

From source file:com.granule.json.utils.XML.java

/**
 * Method to do the transform from an JSON input stream to a XML stream.
 * Neither input nor output streams are closed.  Closure is left up to the caller.  Same as calling toXml(inStream, outStream, false);  (Default is compact form)
 *
 * @param JSONStream The JSON stream to convert to XML
 * @param XMLStream The stream to write out XML to.  The contents written to this stream are always in UTF-8 format.
 * //from   w ww  . j  a va 2  s . c  om
 * @throws IOException Thrown if an IO error occurs.
 */
public static void toXml(InputStream JSONStream, OutputStream XMLStream) throws IOException {
    if (logger.isLoggable(Level.FINER)) {
        logger.entering(className, "toXml(InputStream, OutputStream)");
    }
    toXml(JSONStream, XMLStream, false);

    if (logger.isLoggable(Level.FINER)) {
        logger.entering(className, "toXml(InputStream, OutputStream)");
    }
}

From source file:com.ibm.jaggr.core.impl.transport.AbstractHttpTransport.java

/**
 * Returns the requested locales as a collection of locale strings
 *
 * @param request the request object//ww  w  .ja  v a 2 s  . com
 * @return the locale strings
 */
protected Collection<String> getRequestedLocales(HttpServletRequest request) {
    final String sourceMethod = "getRequestedLocales"; //$NON-NLS-1$
    boolean isTraceLogging = log.isLoggable(Level.FINER);
    if (isTraceLogging) {
        log.entering(AbstractHttpTransport.class.getName(), sourceMethod,
                new Object[] { request.getQueryString() });
    }
    String[] locales;
    String sLocales = getParameter(request, REQUESTEDLOCALES_REQPARAMS);
    if (sLocales != null) {
        locales = sLocales.split(","); //$NON-NLS-1$
    } else {
        locales = new String[0];
    }
    Collection<String> result = Collections.unmodifiableCollection(Arrays.asList(locales));
    if (isTraceLogging) {
        log.exiting(AbstractHttpTransport.class.getName(), sourceMethod, result);
    }
    return result;
}

From source file:org.b3log.latke.repository.jdbc.JdbcRepository.java

@Override
public JSONObject get(final String id) throws RepositoryException {
    JSONObject ret = null;// ww  w . j a  v  a2  s  .  c  o m

    if (cacheEnabled) {
        final String cacheKey = CACHE_KEY_PREFIX + id;

        ret = (JSONObject) CACHE.get(cacheKey);
        if (null != ret) {
            LOGGER.log(Level.FINER, "Got an object[cacheKey={0}] from repository cache[name={1}]",
                    new Object[] { cacheKey, getName() });
            return ret;
        }
    }

    final StringBuilder sql = new StringBuilder();
    final Connection connection = getConnection();

    try {
        get(sql);
        final ArrayList<Object> paramList = new ArrayList<Object>();

        paramList.add(id);
        ret = JdbcUtil.queryJsonObject(sql.toString(), paramList, connection, getName());

        if (cacheEnabled) {
            final String cacheKey = CACHE_KEY_PREFIX + id;

            CACHE.putAsync(cacheKey, ret);
            LOGGER.log(Level.FINER, "Added an object[cacheKey={0}] in repository cache[{1}]",
                    new Object[] { cacheKey, getName() });
        }

    } catch (final SQLException e) {
        throw new JDBCRepositoryException(e);
    } catch (final Exception e) {
        LOGGER.log(Level.SEVERE, "get:" + e.getMessage(), e);
        throw new RepositoryException(e);
    } finally {
        closeQueryConnection(connection);
    }

    return ret;
}

From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java

private List<String> loadLevels() {
    List<String> logLevels = Arrays.asList(Level.OFF.getName(), Level.SEVERE.getName(), Level.WARNING.getName(),
            Level.CONFIG.getName(), Level.INFO.getName(), Level.FINE.getName(), Level.FINER.getName(),
            Level.FINEST.getName(), Level.ALL.getName());
    return logLevels;
}

From source file:com.archivas.clienttools.arcutils.utils.net.GetCertsX509TrustManager.java

public void checkServerTrusted1(X509Certificate[] certificates, String authType) throws CertificateException {
    SSLCertChain certChain = new SSLCertChain(authType, certificates);

    // Try the in-memory, session only trust manager first
    try {/*w w w .  j av a 2  s. co m*/
        LOG.log(Level.FINEST, "About to have MemoryTrustManager Test cert: " + certChain);
        memoryTrustManager.checkServerTrusted(certificates, authType);
        LOG.log(Level.FINEST, "MemoryTrustManager Approves of cert: " + certChain);
        if (sslExceptionCallback != null) {
            sslExceptionCallback.validCertCallback(profile, certChain);
        }
        return;
    } catch (Exception certException) {
        // Log it and fall through to the next trust mgr.
        LOG.log(Level.FINE,
                "Error checking Server Trust via MemoryTrustManager: " + certException.getMessage());
        LOG.log(Level.FINER, "Error checking Server Trust via MemoryTrustManager", certException);
    }

    // Try the persisted to disk trust manager next
    try {
        LOG.log(Level.FINEST, "About to have PersistedTrustManager Test cert: " + certChain);
        persistedTrustManager.checkServerTrusted(certificates, authType);
        LOG.log(Level.FINEST, "PersistedTrustManager Approves of cert: " + certChain);
        if (sslExceptionCallback != null) {
            sslExceptionCallback.validCertCallback(profile, certChain);
        }
        return;
    } catch (Exception certException) {
        // Log it and fall through to the next trust mgr.
        LOG.log(Level.FINE,
                "Error checking Server Trust via PersistedTrustManager: " + certException.getMessage());
        LOG.log(Level.FINER, "Error checking Server Trust via PersistedTrustManager", certException);
    }

    // Try the default JDK trust manager last. (This has the default JDK root certs + any the
    // user has added)
    try {
        LOG.log(Level.FINEST, "About to have standardTrustManager Test cert: " + certChain);
        standardTrustManager.checkServerTrusted(certificates, authType);
        LOG.log(Level.FINEST, "standardTrustManager Approves of cert: " + certChain);
        /*
         * if ((certificates != null) && (certificates.length == 1)) {
         * certificates[0].checkValidity(); } else {
         * standardTrustManager.checkServerTrusted(certificates,authType); }
         */
        if (sslExceptionCallback != null) {
            sslExceptionCallback.validCertCallback(profile, certChain);
        }
    } catch (CertificateException certException) {
        LOG.log(Level.FINE,
                "Error checking Server Trust via standardTrustManager: " + certException.getMessage());
        LOG.log(Level.FINER, "Error checking Server Trust via standardTrustManager", certException);
        handleCertFailureCallback(certChain, certException);
    }
}