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;
}
}
}
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();
}
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;
}
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;
}
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);
}
}
Aggregations