/*
Synchronizable: counter is "updated" with the input value
555983
final public void increment(long time, long value) {
        if (!enabled)
            return;

        lastSampleTime = time;
        if (!sync) {
            count += value;
        } else {
            synchronized (this) {
                count += value;
            }
        }
    }
137264
def last(self, name, value):
        
        counter = self.get(name, CounterType.LastValue)
        counter.last = value
        self._update()
870152
void writeLock(int count) {
      if (count > 0 && counter != null)
         counter.acquireShared(count);
      sync.acquireShared(1);
   }
67377
protected void updateCiManagement(CiManagement value, String xmlTag, Counter counter, Element element)
   {
      boolean shouldExist = value != null;
      Element root = updateElement(counter, element, xmlTag, shouldExist);
      if (shouldExist)
      {
         Counter innerCount = new Counter(counter.getDepth() + 1);
         findAndReplaceSimpleElement(innerCount, root, "system", value.getSystem(), null);
         findAndReplaceSimpleElement(innerCount, root, "url", value.getUrl(), null);
         iterateNotifier(innerCount, root, value.getNotifiers(), "notifiers", "notifier");
      }
   }
239409
final public void add(long curTime, long val) {
        if (!enabled)
            return;

        lastSampleTime = curTime;
        if (!sync) {
            if (val > max)
                max = val;

            if (count > 0) {
                if (val < min)
                    min = val;
            } else
                min = val; //set min=val for the first time

            /*
             * if (val < min || min < 0)
             * min = val;
             */
            count++;
            total += val;
            sumOfSquares += val * val;
        } else {
            // synchronized ONLY the count updates
            synchronized (this) {
                count++;
                total += val;
            }

            if (val > max)
                max = val;

            if (count > 0) {
                if (val < min)
                    min = val;
            } else
                min = val; //set min=val for the first time

            sumOfSquares += val * val;
        }
    }
70936
private void checkSystemInput()
        throws IOException
    {
        while ( System.in.available() > 0 )
        {
            int input = System.in.read();
            if ( input >= 0 )
            {
                char c = (char) input;
                if ( c == '\n' )
                {
                    synchronized ( lock )
                    {
                        finished = true;
                        lock.notifyAll();
                    }
                }
            }
            else
            {
                synchronized ( lock )
                {
                    finished = true;
                    lock.notifyAll();
                }
            }
        }
    }
453188
@Override
	public void updateCounterDetails(final Counter incomingCounter)
	{
		Preconditions.checkNotNull(incomingCounter);

		// First, assert the counter is in a proper state. If done consistently (i.e., in a TX, then this will function
		// as an effective CounterData lock).
		// Second, Update the counter details.

		ObjectifyService.ofy().transact(new Work<Void>()
		{
			@Override
			public Void run()
			{
				// First, load the incomingCounter from the datastore via a transactional get to ensure it has the
				// proper state.
				final Optional<CounterData> optCounterData = getCounterData(incomingCounter.getName());

				// //////////////
				// ShortCircuit: Can't update a counter that doesn't exist!
				// //////////////
				if (!optCounterData.isPresent())
				{
					throw new NoCounterExistsException(incomingCounter.getName());
				}

				final CounterData counterDataInDatastore = optCounterData.get();

				// Make sure the stored counter is currently in an updatable state!
				assertCounterDetailsMutatable(incomingCounter.getName(), counterDataInDatastore.getCounterStatus());

				// Make sure the incoming counter status is a validly settable status
				assertValidExternalCounterStatus(incomingCounter.getName(), incomingCounter.getCounterStatus());

				// NOTE: READ_ONLY_COUNT status means the count can't be incremented/decremented. However, it's details
				// can still be mutated.

				// NOTE: The counterName/counterId may not change!

				// Update the Description
				counterDataInDatastore.setDescription(incomingCounter.getDescription());

				// Update the numShards. Aside from setting this value, nothing explicitly needs to happen in the
				// datastore since shards will be created when a counter in incremented (if the shard doesn't already
				// exist). However, if the number of shards is being reduced, then throw an exception since this
				// requires counter shard reduction and some extra thinking. We can't allow the shard-count to go down
				// unless we collapse the entire counter's shards into a single shard or zero, and it's ambiguous if
				// this is even required. Note that if we allow this numShards value to decrease without capturing
				// the count from any of the shards that might no longer be used, then we might lose counts from the
				// shards that would no longer be factored into the #getCount method.
				if (incomingCounter.getNumShards() < counterDataInDatastore.getNumShards())
				{
					throw new IllegalArgumentException(
						"Reducing the number of counter shards is not currently allowed!  See https://github.com/instacount/appengine-counter/issues/4 for more details.");
				}

				counterDataInDatastore.setNumShards(incomingCounter.getNumShards());

				// The Exception above disallows any invalid states.
				counterDataInDatastore.setCounterStatus(incomingCounter.getCounterStatus());

				// Update the CounterDataIndexes
				counterDataInDatastore.setIndexes(
					incomingCounter.getIndexes() == null ? CounterIndexes.none() : incomingCounter.getIndexes());

				// Update the counter in the datastore.
				ObjectifyService.ofy().save().entity(counterDataInDatastore).now();

				// return null to satisfy Java...
				return null;
			}
		});
	}
1247459
private void onKeyUpdated(final int index, final Map.Entry<String, String> object, final String value) {
        final HashMap<String, String> _m = new LinkedHashMap<String, String>(getValue());
        final String lastKeyValue = object.getKey();
        String mapValue = "";
        if (lastKeyValue != null) {
            mapValue = _m.remove(lastKeyValue);
        }
        _m.put(value, mapValue);
        setValue(_m, true);
    }
406158
def increment(self, name, value):
        
        counter = self.get(name, CounterType.Increment)
        counter.count = counter.count + value if counter.count != None else value
        self._update()
31651
private boolean syncRead(int amountToRead) throws IOException{
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){
            Tr.debug(tc, "syncRead, Executing a synchronous read");
        }
        
//      Allocate the buffer and set it on the TCP Channel
      setAndAllocateBuffer(amountToRead);
      
        try{
            long bytesRead = _tcpContext.getReadInterface().read(1, WCCustomProperties31.UPGRADE_READ_TIMEOUT);
            
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){
                Tr.debug(tc, "syncRead, Completed the read, " + bytesRead);
            }
            if(bytesRead > 0){
                //Get the buffer from the TCP Channel after we have told them to read.
                _buffer = _tcpContext.getReadInterface().getBuffer(); 
                
                //We don't need to check for null first as we know we will always get the buffer we just set
                configurePostReadBuffer();
                // record the new amount of data read from the channel
                _totalBytesRead += _buffer.remaining();
                return true;
            }
            return false;
        }catch (IOException e){
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){
                Tr.debug(tc, "syncRead, We encountered an exception during the read : " + e);
            }
            _error = e;
            throw e;
        }
    }
677260
public void awaitCount(long totalCount) throws InterruptedException
  {
    checkTotalCount(totalCount);
    long currentCount = sync.getCount();
    while (compareCounts(totalCount, currentCount) > 0) {
      sync.acquireSharedInterruptibly(currentCount);
      currentCount = sync.getCount();
    }
  }
1141289
private void updateValue() {
        if (list != null) {
            int oldCount = this.count;
            this.count = list.getSelectedIndices().length;
            maybeNotifyListeners(oldCount, count);
        }
    }
1147941
public synchronized boolean sync() {
		if (!validState) {
			throw new InvalidStateException();
		}
		try {
			fc.force(false);
			return true;
		} catch (Exception e) {
			log.error("Exception in sync()", e);
		}
		return false;
	}
166295
public void incrementSync(String distributedObjectName, int count) {
        getOrPutIfAbsent(eventCounterMap, distributedObjectName, EVENT_COUNTER_CONSTRUCTOR_FN)
                .incrementSyncCount(count);
    }
1014809
@Override
    public void setValue(Double value, boolean fireEvents) {
        Double old = getValue();
        if (old == value || old != null && old.equals(value)) return;
        internVal = value;
        setInputValueAttr(value);
        ignoreChange = true;
        try {
            refresh(input.getElement().getId(), doubleToNiceStr(value));
        } finally {
            ignoreChange = false;
        }
        if (fireEvents) ValueChangeEvent.fire(this, value);
    }
580490
def updateCurrentValue(self, value):
        
        xsnap = None
        ysnap = None
        
        if value != self.endValue():
            xsnap = self.targetObject().isXSnappedToGrid()
            ysnap = self.targetObject().isYSnappedToGrid()
            
            self.targetObject().setXSnapToGrid(False)
            self.targetObject().setYSnapToGrid(False)
        
        super(XNodeAnimation, self).updateCurrentValue(value)
        
        if value != self.endValue():
            self.targetObject().setXSnapToGrid(xsnap)
            self.targetObject().setYSnapToGrid(ysnap)
500074
synchronized void reset(double value, int updated) {
        ewma = value;
        ewmaStddev = value * SINGLE_VALUE_STDDEV;
        ewmaVariance = ewmaStddev * ewmaStddev;
        consecutiveOutliers = 0;
        lastUpdate = updated;
    }