Search in sources :

Example 91 with LinkedList

use of java.util.LinkedList in project jna by java-native-access.

the class PsapiTest method testEnumProcessModules.

@Test
public void testEnumProcessModules() {
    HANDLE me = null;
    Win32Exception we = null;
    try {
        me = Kernel32.INSTANCE.OpenProcess(WinNT.PROCESS_ALL_ACCESS, false, Kernel32.INSTANCE.GetCurrentProcessId());
        assertTrue("Handle to my process should not be null", me != null);
        List<HMODULE> list = new LinkedList<HMODULE>();
        HMODULE[] lphModule = new HMODULE[100 * 4];
        IntByReference lpcbNeeded = new IntByReference();
        if (!Psapi.INSTANCE.EnumProcessModules(me, lphModule, lphModule.length, lpcbNeeded)) {
            throw new Win32Exception(Native.getLastError());
        }
        for (int i = 0; i < lpcbNeeded.getValue() / 4; i++) {
            list.add(lphModule[i]);
        }
        assertTrue("List should have at least 1 item in it.", list.size() > 0);
    } catch (Win32Exception e) {
        we = e;
        // re-throw to invoke finally block
        throw we;
    } finally {
        try {
            Kernel32Util.closeHandle(me);
        } catch (Win32Exception e) {
            if (we == null) {
                we = e;
            } else {
                we.addSuppressed(e);
            }
        }
        if (we != null) {
            throw we;
        }
    }
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) HMODULE(com.sun.jna.platform.win32.WinDef.HMODULE) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 92 with LinkedList

use of java.util.LinkedList in project jna by java-native-access.

the class W32ServiceTest method testSetAndGetFailureActions.

public void testSetAndGetFailureActions() {
    final String svcId = "w32time";
    final String rebootMsg = "Restarting " + svcId + " due to service failure";
    final String command = "echo " + svcId + " failure";
    final int resetPeriod = 5000;
    W32Service service = _serviceManager.openService(svcId, Winsvc.SC_MANAGER_ALL_ACCESS);
    SERVICE_FAILURE_ACTIONS prevActions = service.getFailureActions();
    List<SC_ACTION> actions = new LinkedList<SC_ACTION>();
    SC_ACTION action = new SC_ACTION();
    action.type = Winsvc.SC_ACTION_RESTART;
    action.delay = 1000;
    actions.add(action);
    action = new SC_ACTION();
    action.type = Winsvc.SC_ACTION_REBOOT;
    action.delay = 2000;
    actions.add(action);
    action = new SC_ACTION();
    action.type = Winsvc.SC_ACTION_RUN_COMMAND;
    action.delay = 3000;
    actions.add(action);
    action = new SC_ACTION();
    action.type = Winsvc.SC_ACTION_NONE;
    action.delay = 4000;
    actions.add(action);
    service.setFailureActions(actions, resetPeriod, rebootMsg, command);
    SERVICE_FAILURE_ACTIONS changedActions = service.getFailureActions();
    assertEquals(changedActions.lpRebootMsg, rebootMsg);
    assertEquals(changedActions.lpCommand, command);
    assertEquals(changedActions.dwResetPeriod, resetPeriod);
    assertEquals(changedActions.cActions, 4);
    SC_ACTION[] actionArray = (SC_ACTION[]) changedActions.lpsaActions.toArray(changedActions.cActions);
    assertEquals(actionArray[0].type, Winsvc.SC_ACTION_RESTART);
    assertEquals(actionArray[0].delay, 1000);
    assertEquals(actionArray[1].type, Winsvc.SC_ACTION_REBOOT);
    assertEquals(actionArray[1].delay, 2000);
    assertEquals(actionArray[2].type, Winsvc.SC_ACTION_RUN_COMMAND);
    assertEquals(actionArray[2].delay, 3000);
    assertEquals(actionArray[3].type, Winsvc.SC_ACTION_NONE);
    assertEquals(actionArray[3].delay, 4000);
    // restore old settings
    Advapi32.INSTANCE.ChangeServiceConfig2(service._handle, Winsvc.SERVICE_CONFIG_FAILURE_ACTIONS, prevActions);
    service.close();
}
Also used : SC_ACTION(com.sun.jna.platform.win32.Winsvc.SC_ACTION) SERVICE_FAILURE_ACTIONS(com.sun.jna.platform.win32.Winsvc.SERVICE_FAILURE_ACTIONS) LinkedList(java.util.LinkedList)

Example 93 with LinkedList

use of java.util.LinkedList in project killbill by killbill.

the class DefaultSubscriptionDao method buildBundleSubscriptions.

private List<SubscriptionBase> buildBundleSubscriptions(final List<SubscriptionBase> input, @Nullable final Multimap<UUID, SubscriptionBaseEvent> eventsForSubscription, @Nullable final Collection<SubscriptionBaseEvent> dryRunEvents, final InternalTenantContext context) throws CatalogApiException {
    if (input == null || input.isEmpty()) {
        return Collections.emptyList();
    }
    // Make sure BasePlan -- if exists-- is first
    Collections.sort(input, DefaultSubscriptionInternalApi.SUBSCRIPTIONS_COMPARATOR);
    final Collection<ApiEventChange> baseChangeEvents = new LinkedList<ApiEventChange>();
    ApiEventCancel baseCancellationEvent = null;
    final List<SubscriptionBase> result = new ArrayList<SubscriptionBase>(input.size());
    for (final SubscriptionBase cur : input) {
        final List<SubscriptionBaseEvent> events = eventsForSubscription != null ? (List<SubscriptionBaseEvent>) eventsForSubscription.get(cur.getId()) : getEventsForSubscription(cur.getId(), context);
        mergeDryRunEvents(cur.getId(), events, dryRunEvents);
        SubscriptionBase reloaded = createSubscriptionForInternalUse(cur, events, context);
        switch(cur.getCategory()) {
            case BASE:
                for (final SubscriptionBaseEvent event : events) {
                    if (!event.isActive()) {
                        continue;
                    } else if (event instanceof ApiEventCancel) {
                        baseCancellationEvent = (ApiEventCancel) event;
                        break;
                    } else if (event instanceof ApiEventChange) {
                        // Need to track all changes, see https://github.com/killbill/killbill/issues/268
                        baseChangeEvents.add((ApiEventChange) event);
                    }
                }
                break;
            case ADD_ON:
                final Plan targetAddOnPlan = reloaded.getCurrentPlan();
                if (targetAddOnPlan == null || reloaded.getFutureEndDate() != null) {
                    // triggers another cancellation before?
                    break;
                }
                SubscriptionBaseEvent baseTriggerEventForAddOnCancellation = baseCancellationEvent;
                for (final ApiEventChange baseChangeEvent : baseChangeEvents) {
                    final String baseProductName = baseChangeEvent.getEventPlan();
                    if ((!addonUtils.isAddonAvailableFromPlanName(baseProductName, targetAddOnPlan, baseChangeEvent.getEffectiveDate(), context)) || (addonUtils.isAddonIncludedFromPlanName(baseProductName, targetAddOnPlan, baseChangeEvent.getEffectiveDate(), context))) {
                        if (baseTriggerEventForAddOnCancellation != null) {
                            if (baseTriggerEventForAddOnCancellation.getEffectiveDate().isAfter(baseChangeEvent.getEffectiveDate())) {
                                baseTriggerEventForAddOnCancellation = baseChangeEvent;
                            }
                        } else {
                            baseTriggerEventForAddOnCancellation = baseChangeEvent;
                        }
                    }
                }
                if (baseTriggerEventForAddOnCancellation != null) {
                    final DateTime now = clock.getUTCNow();
                    final SubscriptionBaseEvent addOnCancelEvent = new ApiEventCancel(new ApiEventBuilder().setSubscriptionId(reloaded.getId()).setEffectiveDate(baseTriggerEventForAddOnCancellation.getEffectiveDate()).setCreatedDate(baseTriggerEventForAddOnCancellation.getCreatedDate()).setFromDisk(false));
                    events.add(addOnCancelEvent);
                    // Finally reload subscription with full set of events
                    reloaded = createSubscriptionForInternalUse(cur, events, context);
                }
                break;
            default:
                break;
        }
        result.add(reloaded);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ApiEventCancel(org.killbill.billing.subscription.events.user.ApiEventCancel) Plan(org.killbill.billing.catalog.api.Plan) LinkedList(java.util.LinkedList) DateTime(org.joda.time.DateTime) SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) ApiEventBuilder(org.killbill.billing.subscription.events.user.ApiEventBuilder) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) ApiEventChange(org.killbill.billing.subscription.events.user.ApiEventChange)

Example 94 with LinkedList

use of java.util.LinkedList in project killbill by killbill.

the class DefaultSubscriptionDao method createSubscriptionWithNewEvent.

//
// Creates a copy of the existing subscriptions whose 'transitions' will reflect the new event
//
private DefaultSubscriptionBase createSubscriptionWithNewEvent(final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent newEvent, final InternalTenantContext context) throws CatalogApiException {
    final DefaultSubscriptionBase subscriptionWithNewEvent = new DefaultSubscriptionBase(subscription, null, clock);
    final List<SubscriptionBaseEvent> allEvents = new LinkedList<SubscriptionBaseEvent>();
    if (subscriptionWithNewEvent.getEvents() != null) {
        allEvents.addAll(subscriptionWithNewEvent.getEvents());
    }
    allEvents.add(newEvent);
    subscriptionWithNewEvent.rebuildTransitions(allEvents, catalogService.getFullCatalog(true, true, context));
    return subscriptionWithNewEvent;
}
Also used : DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) LinkedList(java.util.LinkedList)

Example 95 with LinkedList

use of java.util.LinkedList in project jersey by jersey.

the class WadlBuilder method generateRequest.

private Request generateRequest(org.glassfish.jersey.server.model.Resource parentResource, final org.glassfish.jersey.server.model.ResourceMethod resourceMethod, Map<String, Param> wadlResourceParams) {
    try {
        final List<Parameter> requestParams = new LinkedList<>(resourceMethod.getInvocable().getParameters());
        // Adding handler instance parameters to the list of potential request parameters.
        requestParams.addAll(resourceMethod.getInvocable().getHandler().getParameters());
        if (requestParams.isEmpty()) {
            return null;
        }
        Request wadlRequest = _wadlGenerator.createRequest(parentResource, resourceMethod);
        processRequestParameters(parentResource, resourceMethod, wadlResourceParams, requestParams, wadlRequest);
        if (wadlRequest.getRepresentation().size() + wadlRequest.getParam().size() == 0) {
            return null;
        } else {
            return wadlRequest;
        }
    } catch (Exception e) {
        throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_REQUEST(resourceMethod, parentResource), e);
    }
}
Also used : Request(com.sun.research.ws.wadl.Request) Parameter(org.glassfish.jersey.server.model.Parameter) LinkedList(java.util.LinkedList) ProcessingException(javax.ws.rs.ProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

LinkedList (java.util.LinkedList)10512 Test (org.junit.Test)1487 List (java.util.List)1463 HashMap (java.util.HashMap)1371 ArrayList (java.util.ArrayList)1313 Map (java.util.Map)871 IOException (java.io.IOException)800 File (java.io.File)695 HashSet (java.util.HashSet)605 LinkedHashMap (java.util.LinkedHashMap)382 GenericValue (org.apache.ofbiz.entity.GenericValue)296 Iterator (java.util.Iterator)277 Set (java.util.Set)255 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)232 Date (java.util.Date)222 Collection (java.util.Collection)201 Delegator (org.apache.ofbiz.entity.Delegator)162 Locale (java.util.Locale)158 URL (java.net.URL)154 BufferedReader (java.io.BufferedReader)146