org.apache.commons.lang3.mutable.MutableInt Java Examples

The following examples show how to use org.apache.commons.lang3.mutable.MutableInt. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaScriptJobManagerMinimalTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception if an error occurs
 */
@Test
public void addJob_multipleExecution_removeAllJobs() throws Exception {
    final MutableInt count = new MutableInt(0);
    final JavaScriptJob job = new BasicJavaScriptJob(50, Integer.valueOf(50)) {
        @Override
        public void run() {
            count.increment();
            if (count.intValue() >= 5) {
                manager_.removeAllJobs();
            }
        }
    };
    manager_.addJob(job, page_);
    manager_.waitForJobs(1000);
    assertEquals(5, count.intValue());
}
 
Example #2
Source File: TestDataInterface.java    From count-db with MIT License 6 votes vote down vote up
@Test
public void testValuesIteratorWithFilter() {
    DataInterface<Long> dataInterface = createCountDataInterface("testValuesIteratorWithFilter");
    int numOfItems = 100;
    for (int i = 0; i < 100; i++) {
        dataInterface.write(i, (long) i);
    }
    dataInterface.flush();
    //Try with stream
    MutableInt numOfValuesRead = new MutableInt();
    dataInterface.streamValues(new EvenKeysFilter()).forEach((v) -> numOfValuesRead.increment());
    Assert.assertEquals(numOfItems / 2, numOfValuesRead.intValue());
    //Try with iterator
    numOfValuesRead.setValue(0);
    CloseableIterator<Long> closeableIterator = dataInterface.valueIterator(new EvenKeysFilter());
    while (closeableIterator.hasNext()) {
        closeableIterator.next();
        numOfValuesRead.increment();
    }
    closeableIterator.close();
    Assert.assertEquals(numOfItems / 2, numOfValuesRead.intValue());
}
 
Example #3
Source File: WorkflowInterceptorTest.java    From flux with Apache License 2.0 6 votes vote down vote up
@Test
public void testWorkflowInterception_WithActualParameters() throws Throwable {
    /* setup */
    final MutableInt getEventNameCall = new MutableInt(0);
    doAnswer(invocation -> {
        Event argument = (Event) invocation.getArguments()[0];
        final int currentValue = getEventNameCall.intValue();
        getEventNameCall.increment();
        return argument.name() + currentValue;
    }).when(localContext).generateEventName(any(Event.class));

    final Method invokedMethod = simpleWorkflowForTest.getClass().getDeclaredMethod("simpleDummyWorkflow", StringEvent.class, IntegerEvent.class);
    final StringEvent testStringEvent = new StringEvent("someEvent");
    final IntegerEvent testIntegerEvent = new IntegerEvent(1);
    /* invoke method */
    workflowInterceptor.invoke(dummyInvocation(invokedMethod,new Object[]{testStringEvent,testIntegerEvent}));
    /* verifications */
    verify(localContext,times(1)).addEvents(
        new EventData(SimpleWorkflowForTest.STRING_EVENT_NAME + "0", StringEvent.class.getName(), objectMapper.writeValueAsString(testStringEvent), CLIENT),
        new EventData(SimpleWorkflowForTest.INTEGER_EVENT_NAME + "1", IntegerEvent.class.getName(), objectMapper.writeValueAsString(testIntegerEvent), CLIENT)
    );
}
 
Example #4
Source File: GraphStrategy.java    From sqlg with MIT License 6 votes vote down vote up
void combineSteps() {
    @SuppressWarnings("unchecked")
    List<Step<?, ?>> steps = new ArrayList(this.traversal.asAdmin().getSteps());
    ListIterator<Step<?, ?>> stepIterator = steps.listIterator();
    MutableInt pathCount = new MutableInt(0);
    while (stepIterator.hasNext()) {
        Step<?, ?> step = stepIterator.next();
        if (isReplaceableStep(step.getClass())) {
            stepIterator.previous();
            boolean keepGoing = handleStep(stepIterator, pathCount);
            if (!keepGoing) {
                break;
            }
        } else {
            //If a step can not be replaced then its the end of optimizationinging.
            break;
        }
    }
}
 
Example #5
Source File: AllelePileupCounter.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 *
 * @param referenceAllele allele to treat as reference.  Create with {@link Allele#create(String, boolean)}, where
 *                  second parameter is {@code true}.  Never {@code null}.   If the reference is symbolic, exception will be thrown.
 * @param alternateAlleles List of alleles to treat as the alternates.  Easy to create with {@link Allele#create(String, boolean)}, where
 *                  second parameter is {@code false}.  Never {@code null}
 * @param minBaseQualityCutoff minimum base quality for the bases that match the allele in order to be counted.
 *                             Must be positive or zero.
 */
public AllelePileupCounter(final Allele referenceAllele, final List<Allele> alternateAlleles, int minBaseQualityCutoff) {

    this.referenceAllele = Utils.nonNull(referenceAllele);
    this.alternateAlleles = Utils.nonNull(alternateAlleles);

    // Additional checks
    if (referenceAllele.isSymbolic()) {
        throw new UserException.BadInput("A symbolic reference allele was specified.");
    }

    Utils.validateArg(!referenceAllele.isNonReference(), "Reference allele was non-reference: " + referenceAllele);
    Utils.validateArg(alternateAlleles.stream().allMatch(a -> a.isNonReference()),
            "One or more alternate alleles were reference: " + alternateAlleles.stream().map(a-> a.toString()).collect(Collectors.joining(", ")));

    this.minBaseQualityCutoff = ParamUtils.isPositiveOrZero(minBaseQualityCutoff, "Minimum base quality must be positive or zero.");;

    alternateAlleles.forEach(a -> countMap.put(a, new MutableInt(0)));
    countMap.put(referenceAllele, new MutableInt(0));
}
 
Example #6
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
/**
 * Deserializes a {@link GPOMutable} object from the given byte array at the given offset, which was
 * serialized with the given {@link FieldsDescriptor} with the given fields excluded.
 * @param fieldsDescriptor The {@link FieldsDescriptor} object corresponding to the {@link GPOMutable}.
 * @param excludedFields The fields to exclude from serializing the {@link GPOMutable}.
 * @param serializedGPO The array containing the serialized {@link GPOMutable}.
 * @param offset The offset in the provided array to start deserializing from.
 * @return The deserialized {@link GPOMutable}.
 */
public static GPOMutable deserialize(FieldsDescriptor fieldsDescriptor, Fields excludedFields, byte[] serializedGPO,
    int offset)
{
  GPOMutable gpo = new GPOMutable(fieldsDescriptor);
  MutableInt offsetM = new MutableInt(offset);

  Set<String> exFieldsSet = excludedFields.getFields();

  for (String field : fieldsDescriptor.getFields().getFields()) {
    if (exFieldsSet.contains(field)) {
      continue;
    }

    Type type = fieldsDescriptor.getType(field);
    GPOType gpoType = GPOType.GPO_TYPE_ARRAY[type.ordinal()];
    gpoType.deserialize(gpo, field, serializedGPO, offsetM);
  }

  return gpo;
}
 
Example #7
Source File: TestDataInterface.java    From count-db with MIT License 6 votes vote down vote up
@Test
public void testIteratorWithFilter() {
    DataInterface<Long> dataInterface = createCountDataInterface("testIteratorWithFilter");
    int numOfItems = 100;
    for (int i = 0; i < 100; i++) {
        dataInterface.write(i, (long) i);
    }
    dataInterface.flush();
    //Try with stream
    MutableInt numOfValuesRead = new MutableInt();
    dataInterface.stream(new EvenKeysFilter()).forEach((v) -> numOfValuesRead.increment());
    Assert.assertEquals(numOfItems / 2, numOfValuesRead.intValue());
    //Try with iterator
    numOfValuesRead.setValue(0);
    CloseableIterator<KeyValue<Long>> closeableIterator = dataInterface.iterator(new EvenKeysFilter());
    while (closeableIterator.hasNext()) {
        closeableIterator.next();
        numOfValuesRead.increment();
    }
    closeableIterator.close();
    Assert.assertEquals(numOfItems / 2, numOfValuesRead.intValue());
}
 
Example #8
Source File: JavaScriptJobManagerMinimalTest.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception if an error occurs
 */
@Test
public void addJob_multipleExecution_removeJob() throws Exception {
    final MutableInt id = new MutableInt();
    final MutableInt count = new MutableInt(0);
    final JavaScriptJob job = new BasicJavaScriptJob(50, Integer.valueOf(50)) {
        @Override
        public void run() {
            count.increment();
            if (count.intValue() >= 5) {
                manager_.removeJob(id.intValue());
            }
        }
    };
    id.setValue(manager_.addJob(job, page_));
    manager_.waitForJobs(1000);
    assertEquals(5, count.intValue());
}
 
Example #9
Source File: IPCUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
static void execute(EventLoop eventLoop, Runnable action) {
  if (eventLoop.inEventLoop()) {
    // this is used to prevent stack overflow, you can see the same trick in netty's LocalChannel
    // implementation.
    MutableInt depth = DEPTH.get();
    if (depth.intValue() < MAX_DEPTH) {
      depth.increment();
      try {
        action.run();
      } finally {
        depth.decrement();
      }
    } else {
      eventLoop.execute(action);
    }
  } else {
    eventLoop.execute(action);
  }
}
 
Example #10
Source File: ExternalSession.java    From james-project with Apache License 2.0 6 votes vote down vote up
private boolean tryReadFromSocket() throws IOException, InterruptedException {
    final MutableInt status = new MutableInt(0);
    Awaitility
        .waitAtMost(Duration.ONE_MINUTE)
        .pollDelay(new Duration(10, TimeUnit.MILLISECONDS))
        .until(() -> {
            int read = socket.read(readBuffer);
            status.setValue(read);
            return read != 0;
        });
    if (status.intValue() == -1) {
        monitor.debug("Error reading, got -1");
        return false;
    }
    return true;
}
 
Example #11
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
/**
 * This method deserializes a double from the given byte array from the given offset,
 * and increments the offset appropriately.
 * @param buffer The byte buffer to deserialize from.
 * @param offset The offset to deserialize from.
 * @return The deserialized double.
 */
public static double deserializeDouble(byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  long val = (((long)buffer[0 + offsetInt]) & 0xFFL) << 56 |
      ((((long)buffer[1 + offsetInt]) & 0xFFL) << 48) |
      ((((long)buffer[2 + offsetInt]) & 0xFFL) << 40) |
      ((((long)buffer[3 + offsetInt]) & 0xFFL) << 32) |
      ((((long)buffer[4 + offsetInt]) & 0xFFL) << 24) |
      ((((long)buffer[5 + offsetInt]) & 0xFFL) << 16) |
      ((((long)buffer[6 + offsetInt]) & 0xFFL) << 8) |
      (((long)buffer[7 + offsetInt]) & 0xFFL);

  offset.add(Type.DOUBLE.getByteSize());
  return Double.longBitsToDouble(val);
}
 
Example #12
Source File: VertexStrategy.java    From sqlg with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
void combineSteps() {
    List<Step<?, ?>> steps = new ArrayList(this.traversal.asAdmin().getSteps());
    ListIterator<Step<?, ?>> stepIterator = steps.listIterator();
    MutableInt pathCount = new MutableInt(0);
    while (stepIterator.hasNext()) {
        Step<?, ?> step = stepIterator.next();
        if (this.reset) {
            this.reset = false;
            this.sqlgStep = null;
        }
        if (isReplaceableStep(step.getClass())) {
            stepIterator.previous();
            boolean keepGoing = handleStep(stepIterator, pathCount);
            if (!keepGoing) {
                break;
            }
        } else {
            //restart
            this.sqlgStep = null;
        }
    }
}
 
Example #13
Source File: CharacterFootprintTermFilter.java    From termsuite-core with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param anno the word anno
 * @param badChars the bad char counter. Being incremented
 * @return true if the word has one bad char, false otherwise
 */
private boolean isBadWord(WordAnnotation anno, MutableInt badChars) {
	final String coveredText = anno.getCoveredText();
	boolean foundOneBadChar = false;
	for(int i=0; i< coveredText.length(); i++) {
		boolean found = false;
		char c = coveredText.charAt(i);
		for(char a:this.allowedChars) {
			if(a==c) 
				found = true;
		}
		if(!found) {
			badChars.increment();
			foundOneBadChar = true;
		}
	}
	return foundOneBadChar;
}
 
Example #14
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method serializes the given float to the given byte buffer to the given offset,
 * the method also increments the offset appropriately.
 * @param valf The value to serialize.
 * @param buffer The byte buffer to serialize to.
 * @param offset The offset in the buffer to serialize to and also to increment appropriately.
 */
public static void serializeFloat(float valf, byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  int val = Float.floatToIntBits(valf);

  buffer[0 + offsetInt] = (byte)((val >> 24) & 0xFF);
  buffer[1 + offsetInt] = (byte)((val >> 16) & 0xFF);
  buffer[2 + offsetInt] = (byte)((val >> 8) & 0xFF);
  buffer[3 + offsetInt] = (byte)(val & 0xFF);

  offset.add(Type.FLOAT.getByteSize());
}
 
Example #15
Source File: KinesisProxyTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRecordsRetry() throws Exception {
	Properties kinesisConsumerConfig = new Properties();
	kinesisConsumerConfig.setProperty(ConsumerConfigConstants.AWS_REGION, "us-east-1");

	final GetRecordsResult expectedResult = new GetRecordsResult();
	MutableInt retries = new MutableInt();
	final Throwable[] retriableExceptions = new Throwable[] {
		new AmazonKinesisException("mock"),
	};

	AmazonKinesisClient mockClient = mock(AmazonKinesisClient.class);
	Mockito.when(mockClient.getRecords(any())).thenAnswer(new Answer<GetRecordsResult>() {
		@Override
		public GetRecordsResult answer(InvocationOnMock invocation) throws Throwable{
			if (retries.intValue() < retriableExceptions.length) {
				retries.increment();
				throw retriableExceptions[retries.intValue() - 1];
			}
			return expectedResult;
		}
	});

	KinesisProxy kinesisProxy = new KinesisProxy(kinesisConsumerConfig);
	Whitebox.getField(KinesisProxy.class, "kinesisClient").set(kinesisProxy, mockClient);

	GetRecordsResult result = kinesisProxy.getRecords("fakeShardIterator", 1);
	assertEquals(retriableExceptions.length, retries.intValue());
	assertEquals(expectedResult, result);
}
 
Example #16
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method deserializes a short from the given byte array from the given offset,
 * and increments the offset appropriately.
 * @param buffer The byte buffer to deserialize from.
 * @param offset The offset to deserialize from.
 * @return The deserialized short.
 */
public static short deserializeShort(byte[] buffer, MutableInt offset)
{
  int offsetInt = offset.intValue();
  short val = (short)(((((int)buffer[0 + offsetInt]) & 0xFF) << 8) |
      (((int)buffer[1 + offsetInt]) & 0xFF));

  offset.add(Type.SHORT.getByteSize());
  return val;
}
 
Example #17
Source File: Histogram.java    From LSH_DeepLearning with Apache License 2.0 5 votes vote down vote up
public Set<Integer> thresholdSet(double count)
{
    List<Map.Entry<Integer, MutableInt>> list = new LinkedList<>(histogram.entrySet());
    Collections.sort(list, (Map.Entry<Integer,MutableInt> o1, Map.Entry<Integer, MutableInt> o2) -> o2.getValue().compareTo(o1.getValue()));
    count = Math.min(count, list.size());

    Set<Integer> retrieved = new HashSet<>();
    Iterator<Map.Entry<Integer, MutableInt>> iterator = list.iterator();
    for(int idx = 0; idx < count; ++idx)
    {
        retrieved.add(iterator.next().getKey());
    }
    return retrieved;
}
 
Example #18
Source File: ProcedureTree.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void checkReady(Entry rootEntry, Map<Long, Entry> remainingProcMap) {
  if (ProcedureUtil.isFinished(rootEntry.proc)) {
    if (!rootEntry.subProcs.isEmpty()) {
      LOG.error("unexpected active children for root-procedure: {}", rootEntry);
      rootEntry.subProcs.forEach(e -> LOG.error("unexpected active children: {}", e));
      addAllToCorruptedAndRemoveFromProcMap(rootEntry, remainingProcMap);
    } else {
      addAllToValidAndRemoveFromProcMap(rootEntry, remainingProcMap);
    }
    return;
  }
  Map<Integer, List<Entry>> stackId2Proc = new HashMap<>();
  MutableInt maxStackId = new MutableInt(Integer.MIN_VALUE);
  collectStackId(rootEntry, stackId2Proc, maxStackId);
  // the stack ids should start from 0 and increase by one every time
  boolean valid = true;
  for (int i = 0; i <= maxStackId.intValue(); i++) {
    List<Entry> entries = stackId2Proc.get(i);
    if (entries == null) {
      LOG.error("Missing stack id {}, max stack id is {}, root procedure is {}", i, maxStackId,
        rootEntry);
      valid = false;
    } else if (entries.size() > 1) {
      LOG.error("Multiple procedures {} have the same stack id {}, max stack id is {}," +
        " root procedure is {}", entries, i, maxStackId, rootEntry);
      valid = false;
    }
  }
  if (valid) {
    addAllToValidAndRemoveFromProcMap(rootEntry, remainingProcMap);
  } else {
    addAllToCorruptedAndRemoveFromProcMap(rootEntry, remainingProcMap);
  }
}
 
Example #19
Source File: TemplateUtils.java    From systemds with Apache License 2.0 5 votes vote down vote up
public static boolean isValidNumVectorIntermediates(CNode node, CNode main, Map<Long, Set<Long>> parents, Map<Long, Pair<Long, MutableInt>> inUse, Set<Long> inUse2, int count) {
	if( count <= 1 ) return false;
	IDSequence buff = new IDSequence(true, count-1); //zero based
	inUse.clear(); inUse2.clear();
	node.resetVisitStatus();
	return rIsValidNumVectorIntermediates(node, main, parents, inUse, inUse2, buff);
}
 
Example #20
Source File: ZKConnectionRegistry.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static void tryComplete(MutableInt remaining, HRegionLocation[] locs,
    CompletableFuture<RegionLocations> future) {
  remaining.decrement();
  if (remaining.intValue() > 0) {
    return;
  }
  future.complete(new RegionLocations(locs));
}
 
Example #21
Source File: GPOUtils.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
/**
 * This method deserializes a string from the given byte array from the given offset,
 * and increments the offset appropriately.
 * @param buffer The byte buffer to deserialize from.
 * @param offset The offset to deserialize from.
 * @return The deserialized string.
 */
public static String deserializeString(byte[] buffer, MutableInt offset)
{
  int length = deserializeInt(buffer, offset);

  String val = new String(buffer, offset.intValue(), length);
  offset.add(length);
  return val;
}
 
Example #22
Source File: ConcatenationOperatorNode.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
  * Check if this node always evaluates to the same value. If so, return
  * a constant node representing the known result.
  *
  * @return a constant node representing the result of this concatenation
  * operation, or {@code this} if the result is not known up front
  */
 ValueNode evaluateConstantExpressions() throws StandardException {
     if (leftOperand instanceof CharConstantNode &&
             rightOperand instanceof CharConstantNode) {
         CharConstantNode leftOp = (CharConstantNode) leftOperand;
         CharConstantNode rightOp = (CharConstantNode) rightOperand;
         StringDataValue leftValue = (StringDataValue) leftOp.getValue();
         StringDataValue rightValue = (StringDataValue) rightOp.getValue();

StringDataValue resultValue = null;
         DataTypeDescriptor resultDTD = getTypeServices();
         if (resultDTD == null) {
         	TypeId resultTypeId =
	    resolveConcatOperationResultType(leftOp.getTypeServices(),
	                                     rightOp.getTypeServices(),
	                                     new MutableInt());
	resultValue = (StringDataValue)
	  DataValueFactoryImpl.getNullDVD(resultTypeId.getTypeFormatId());
}
         else
             resultValue = (StringDataValue) resultDTD.getNull();

         resultValue.concatenate(leftValue, rightValue, resultValue);

         return (ValueNode) getNodeFactory().getNode(
                 C_NodeTypes.CHAR_CONSTANT_NODE,
                 resultValue.getString(),
                 getContextManager());
     }

     return this;
 }
 
Example #23
Source File: Explain.java    From systemds with Apache License 2.0 5 votes vote down vote up
private static String explainLineageItemNR(LineageItem item, int level) {
	//NOTE: in contrast to similar non-recursive functions like resetVisitStatusNR,
	// we maintain a more complex stack to ensure DFS ordering where current nodes
	// are added after the subtree underneath is processed (backwards compatibility)
	Stack<LineageItem> stackItem = new Stack<>();
	Stack<MutableInt> stackPos = new Stack<>();
	stackItem.push(item); stackPos.push(new MutableInt(0));
	StringBuilder sb = new StringBuilder();
	while( !stackItem.empty() ) {
		LineageItem tmpItem = stackItem.peek();
		MutableInt tmpPos = stackPos.peek();
		//check ascent condition - no item processing
		if( tmpItem.isVisited() ) {
			stackItem.pop(); stackPos.pop();
		}
		//check ascent condition - append item
		else if( tmpItem.getInputs() == null 
			|| tmpItem.getInputs().length <= tmpPos.intValue() ) {
			sb.append(createOffset(level));
			sb.append(tmpItem.toString());
			sb.append('\n');
			stackItem.pop(); stackPos.pop();
			tmpItem.setVisited();
		}
		//check descent condition
		else if( tmpItem.getInputs() != null ) {
			stackItem.push(tmpItem.getInputs()[tmpPos.intValue()]);
			tmpPos.increment();
			stackPos.push(new MutableInt(0));
		}
	}
	return sb.toString();
}
 
Example #24
Source File: BehaviourFilterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ClassFilter getClassFilter(QName className)
{
    ParameterCheck.mandatory("className", className);

    // Check the global, first
    if (!isEnabled())
    {
        return null;
    }

    if (!TransactionalResourceHelper.isResourcePresent(KEY_CLASS_FILTERS))
    {
        // Nothing was disabled
        return null;
    }
    Map<ClassFilter, MutableInt> classFilters = TransactionalResourceHelper.getMap(KEY_CLASS_FILTERS);
    for (ClassFilter classFilter : classFilters.keySet())
    {
        if (classFilter.getClassName().equals(className))
        {
            MutableInt filterNumber = classFilters.get(classFilter);
            if (filterNumber != null && filterNumber.intValue() > 0 )
            {
                return classFilter;
            }
            break;
        }
    }
    return null;
}
 
Example #25
Source File: TestUtil.java    From flux with Apache License 2.0 5 votes vote down vote up
public static MethodInvocation dummyInvocation(Method methodToReturn, Object methodOwner) {
    return new MethodInvocation() {
        private final MutableInt numProceedInvoctions = new MutableInt(0);
        @Override
        public Method getMethod() {
            return methodToReturn;
        }

        @Override
        public Object[] getArguments() {
            return new Object[0];
        }

        @Override
        public Object proceed() throws Throwable {
            numProceedInvoctions.increment();
            return null;
        }

        @Override
        public Object getThis() {
            return methodOwner;
        }

        @Override
        public AccessibleObject getStaticPart() {
            return null;
        }
    };
}
 
Example #26
Source File: LocalContext.java    From flux with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new, local StateMachineDefinition instance
 * @return
 * @param workflowIdentifier
 * @param version
 * @param description
 */
public void registerNew(String workflowIdentifier, long version, String description,String correlationId,
                        String clientElbId) {
    if (this.stateMachineDefinition.get() != null) {
        /* This ensures we don't compose workflows within workflows */
        throw new IllegalStateException("A single thread cannot execute more than one workflow");
    }
    stateMachineDefinition.set(new StateMachineDefinition(description,workflowIdentifier, version, new HashSet<>(),
            new HashSet<>(), correlationId, clientElbId));
    tlUniqueEventCount.set(new MutableInt(0));
    this.eventNames.set(new IdentityHashMap<>());
}
 
Example #27
Source File: ContentStoreCleanerScalabilityRunner.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void loadData(final int maxCount)
{
    final MutableInt doneCount = new MutableInt(0);
    // Batches of 1000 objects
    RetryingTransactionCallback<Integer> makeNodesCallback = new RetryingTransactionCallback<Integer>()
    {
        public Integer execute() throws Throwable
        {
            for (int i = 0; i < 1000; i++)
            {
                // We don't need to write anything
                String contentUrl = FileContentStore.createNewFileStoreUrl();
                ContentData contentData = new ContentData(contentUrl, MimetypeMap.MIMETYPE_TEXT_PLAIN, 10, "UTF-8");
                nodeHelper.makeNode(contentData);
                
                int count = doneCount.intValue();
                count++;
                doneCount.setValue(count);
                
                // Do some reporting
                if (count % 1000 == 0)
                {
                    System.out.println(String.format("   " + (new Date()) + "Total created: %6d", count));
                }
                
                // Double check for shutdown
                if (vmShutdownListener.isVmShuttingDown())
                {
                    break;
                }
            }
            return maxCount;
        }
    };
    int repetitions = (int) Math.floor((double)maxCount / 1000.0);
    for (int i = 0; i < repetitions; i++)
    {
        transactionService.getRetryingTransactionHelper().doInTransaction(makeNodesCallback);
    }
}
 
Example #28
Source File: ConnectionPoolOverloadTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    failCount = new MutableInt(0);
    transactionService = ctx.getBean("transactionComponent", TransactionService.class);
    properties = ctx.getBean("global-properties", Properties.class);

    String dbPoolMaxProp = properties.getProperty("db.pool.max");
    if (PropertyCheck.isValidPropertyString(dbPoolMaxProp))
    {
        dbPoolMax = Integer.parseInt(dbPoolMaxProp);
    }
    else
    {
        throw new IllegalArgumentException("The db.pool.max property is not valid.");
    }
    
    String dbPoolWaitMaxProp = properties.getProperty("db.pool.wait.max");
    if (PropertyCheck.isValidPropertyString(dbPoolWaitMaxProp))
    {
        dbPoolWaitMax = Integer.parseInt(dbPoolWaitMaxProp);
    }
    else
    {
        throw new IllegalArgumentException("The db.pool.wait.max property is not valid.");
    }
    
    dbPoolWaitMax = dbPoolWaitMax == -1 ? 100 : dbPoolWaitMax;
}
 
Example #29
Source File: SameSchemaDeployExecutionDao.java    From obevo with Apache License 2.0 5 votes vote down vote up
public SameSchemaDeployExecutionDao(SqlExecutor sqlExecutor, DbMetadataManager dbMetadataManager, DbPlatform platform, ImmutableSet<PhysicalSchema> physicalSchemas, String tableSqlSuffix, DbEnvironment env, ChangeTypeBehaviorRegistry changeTypeBehaviorRegistry) {
    this.sqlExecutor = sqlExecutor;
    this.jdbc = sqlExecutor.getJdbcTemplate();
    this.dbMetadataManager = dbMetadataManager;
    this.platform = platform;
    this.physicalSchemas = physicalSchemas;
    this.nextIdBySchema = physicalSchemas.toMap(Functions.<PhysicalSchema>getPassThru(), new Function<PhysicalSchema, MutableInt>() {
        @Override
        public MutableInt valueOf(PhysicalSchema object) {
            return new MutableInt(1);
        }
    }).toImmutable();
    this.tableSqlSuffix = tableSqlSuffix;
    this.env = env;
    this.changeTypeBehaviorRegistry = changeTypeBehaviorRegistry;

    Function<String, String> convertDbObjectName = platform.convertDbObjectName();
    this.deployExecutionTableName = convertDbObjectName.valueOf(DEPLOY_EXECUTION_TABLE_NAME);
    this.deployExecutionAttributeTableName = convertDbObjectName.valueOf(DEPLOY_EXECUTION_ATTRIBUTE_TABLE_NAME);
    this.idColName = convertDbObjectName.valueOf("ID");
    this.statusColName = convertDbObjectName.valueOf("STATUS");
    this.deployTimeColName = convertDbObjectName.valueOf("DEPLOYTIME");
    this.executorIdColName = convertDbObjectName.valueOf("EXECUTORID");
    this.toolVersionColName = convertDbObjectName.valueOf("TOOLVERSION");
    this.initCommandColName = convertDbObjectName.valueOf("INIT_COMMAND");
    this.rollbackCommandColName = convertDbObjectName.valueOf("ROLLBACK_COMMAND");
    this.requesterIdColName = convertDbObjectName.valueOf("REQUESTERID");
    this.reasonColName = convertDbObjectName.valueOf("REASON");
    this.productVersionColName = convertDbObjectName.valueOf("PRODUCTVERSION");
    this.dbSchemaColName = convertDbObjectName.valueOf("DBSCHEMA");
    this.allMainColumns = Lists.immutable.with(idColName, statusColName, deployTimeColName, executorIdColName, toolVersionColName, initCommandColName, rollbackCommandColName, requesterIdColName, reasonColName, dbSchemaColName, productVersionColName);

    this.deployExecutionIdColName = convertDbObjectName.valueOf("DEPLOYEXECUTIONID");
    this.attrNameColName = convertDbObjectName.valueOf("ATTRNAME");
    this.attrValueColName = convertDbObjectName.valueOf("ATTRVALUE");
    this.allAttrColumns = Lists.immutable.with(deployExecutionIdColName, attrNameColName, attrValueColName);
}
 
Example #30
Source File: HumanTime.java    From para with Apache License 2.0 5 votes vote down vote up
private boolean append(long d, long mod, long unit, char u, Appendable a, MutableInt parts) throws IOException {
		if (d >= unit) {
			a.append(floor(d, unit));
//                a.append(' ');
			a.append(u);
			parts.increment();
			if (mod <= lowerCeiling(unit)) {
				return true;
			}
		}
		return false;
	}