Enlist synchronization instance with the specified UOWCoord
764474
public void enlistWithTransaction(SynchronizationRegistryUOWScope uowCoord,
                                      Synchronization sync)
                    throws CSIException
    {
        try
        {
            if (uowCoord.getUOWType() == UOWSynchronizationRegistry.UOW_TYPE_GLOBAL_TRANSACTION)
            {
                ((Transaction) uowCoord).registerSynchronization(sync);
            }
            else
            {
                ((LocalTransactionCoordinator) uowCoord).enlistSynchronization(sync);
            }
        } catch (Exception ex)
        {
            throw new CSIException("Failed to enlist with transaction", ex);
        }
    }
1146652
@Override
    public final synchronized boolean enlist(ContainerTx tx) // d114677
    throws RemoteException
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "enlist: " + getStateName(state),
                     new Object[] { tx, currentTx }); //123293

        boolean result = false;

        switch (state)
        {
            case METHOD_READY:

                // The only way we could be enlisted in this state is at
                // activation; it is not possible for tx to be a global
                // transaction; we do not care about enlistments for
                // non-global transactions

                // LIDB1181.23.5.1
                // A new possibility exists now for the create case of a BMT bean.
                // The home of this BMT session bean will also be configured as
                // a BMT bean too.  This means that during the Home create method
                // the container will have put a local transaction context (LTC)
                // on the thread.  During postCreate the BMStatefulBeanO enlist
                // will be invoked and a containerTx will already exist
                // (ie. passed in ContainerTx is not null any more)

                if (currentTx != null) {
                    if (isTraceOn && tc.isEntryEnabled()) // d144064
                        Tr.exit(tc, "enlist: unexpected non-null currentTx"); //123293
                    throw new BeanNotReentrantException(getStateName(state) +
                                                        ": enlist: unexpected non-null currentTx"); //123293  //PQ99986
                }

                // Note, for BM stateful bean, the transaction may have
                // already been rolled back as a result of a prior business
                // method being called and an unchecked exception occurring.
                // when that happens, the next business method call will
                // eventually get to this code with tx set to null.
                // for that case, we simply skip doing the enlist and
                // return boolean false to caller so that the business
                // method gets dispatched.  Needed to pass CTS testcase
                // which is checking for the TransactionRolledBackException
                // occurring when client tries to commit a UserTransaction
                // that was already rolled back as a result of the
                // unchecked exception that previously occurred.
                if (tx != null) //123393
                {
                    result = tx.enlist(this);
                    currentTx = tx;
                    setState(TX_METHOD_READY);
                }

                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: " + result + ": " + getStateName(state));

                return result;

            case TX_METHOD_READY:

                // The only way we could be enlisted in this state is at
                // activation; tx must be the same as currentTx, since
                // TransactionControl should have resumed our transaction
                if (tx != currentTx)
                {
                    if (isTraceOn && tc.isEntryEnabled()) // d144064
                        Tr.exit(tc, "enlist: unexpected non-null currentTx"); // 123293
                    String expected = "METHOD_READY"; // 123293
                    if (currentTx == null) // 123293
                    {
                        // This should never happened. Resume did not occur?
                        expected = "MAYBE_RESUME_DID_NOT_OCCUR"; // 123293
                    }
                    throw new InvalidBeanOStateException(getStateName(state)
                                    , expected); // 123293
                }

                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: false");

                return false;

            case IN_METHOD:

                // We've got two possibilities: either the bean has just begun
                // a transaction or we're attempting to activate for a re-entrant
                // call from a different thread (which is an error); in the case of
                // a re-entrant call, we must catch it here (cannot defer to
                // preinvoke) since the other thread may change the state of the
                // bean before preInvoke would be called in this thread.

                // LIDB1181.23.5.1
                // A new possibility exists now for the create case of a BMT bean.
                // The home of this BMT session bean will also be configured as
                // a BMT bean too.  This means that during the Home create method
                // the container will have put a local transaction context (LTC)
                // on the thread.  During postCreate the BMStatefulBeanO enlist
                // will be invoked and a containerTx will already exist
                // (ie. passed in ContainerTx is not null any more)

                if (currentTx != null)
                {
                    if (isTraceOn && tc.isEntryEnabled()) // d144064
                        Tr.exit(tc, "enlist: unexpected non-null currentTx"); //123293
                    throw new InvalidBeanOStateException(getStateName(state)
                                    , "TX_METHOD_READY"); //123293
                }

                if (tx == null) // d149781
                {
                    // The only way for the bean to be in the IN_METHOD state with
                    // no transaction is if a different thread is already using it.
                    if (isTraceOn && tc.isEntryEnabled())
                        Tr.exit(tc, "enlist: reentrant call from different thread");
                    throw new BeanNotReentrantException(StateStrs[state] +
                                                        ": wrong thread");
                }

                result = tx.enlist(this);
                currentTx = tx;

                setState(TX_IN_METHOD);

                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: " + result + ": " + getStateName(state));

                return result;

            case CREATING: // PQ56091
            case ACTIVATING: // d159252
            case PASSIVATING: // d159152

                // For all of these states, the EJB Specification allows the use of
                // UserTransaction methods.  However, it is not appropriate to
                // enlist this bean at this time (enlist will be called later
                // for the CREATING and ACTIVATING scenarios).

                if (currentTx != null) {
                    if (isTraceOn && tc.isEntryEnabled()) // d144064
                        Tr.exit(tc, "enlist: unexpected non-null currentTx"); //1233293
                    throw new InvalidBeanOStateException(getStateName(state)
                                    , "TX_METHOD_READY"); //123293
                }
                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: false - unexpected state!");
                return false;

            case TX_IN_METHOD:
            case COMMITTING_IN_METHOD:
            case COMMITTING_OUTSIDE_METHOD:

                // This bean is already in a transaction - and any of these states
                // could be seen by a different transaction calling a method on it,
                // or they could also be due to a customer coded callback to the same
                // bean.
                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: not re-entrant");
                if (currentTx != tx)
                    throw new BeanNotReentrantException(StateStrs[state] +
                                                        ": wrong transaction");

                // This isn't a different thread/tran, but it is a reentrant call,
                // which must be caught here rather than preInvoke to insure the
                // extra cache pins are undone in the activation strategy.     d159152
                throw new BeanNotReentrantException(getStateName(state));

            case REMOVING:

                // Note: prior to the access timeout support added in EJB 3.1, there
                // were issues for the REMOVING state where multiple threads might
                // attempt to enter the bean concurrently, but now that the bean is
                // properly locked, it is safe to just not enlist the bean and thus
                // support UserTransaction methods in ejbRemove/PreDestroy per spec,
                // though if there is a transaction then verify this is the EJB 3.x
                // remove scenario.

                if (currentTx != null && currentTx.ivRemoveBeanO != this) {
                    if (isTraceOn && tc.isEntryEnabled())
                        Tr.exit(tc, "enlist: unexpected non-null currentTx");
                    throw new InvalidBeanOStateException(getStateName(state), "TX_METHOD_READY");
                }
                if (isTraceOn && tc.isEntryEnabled())
                    Tr.exit(tc, "enlist: false - not enlisted for REMOVING state");
                return false;

            default:
                // Any other state is a programming error... there should be no
                // way to encounter these states even from another thread/transaction.
                if (isTraceOn && tc.isEntryEnabled()) // d144064
                    Tr.exit(tc, "enlist: invalid state: " + getStateName(state)); //123293
                throw new InvalidBeanOStateException(getStateName(state),
                                "METHOD_READY | " +
                                                "TX_METHOD_READY | " +
                                                "IN_METHOD");

        }

    }
1061252
private void syncToOSThread(WebSecurityContext webSecurityContext) throws SecurityViolationException {
        try {
            Object token = ThreadIdentityManager.setAppThreadIdentity(subjectManager.getInvocationSubject());
            webSecurityContext.setSyncToOSThreadToken(token);
        } catch (ThreadIdentityException tie) {
            SecurityViolationException secVE = convertWebSecurityException(new WebSecurityCollaboratorException(tie.getMessage(), DENY_AUTHZ_FAILED, webSecurityContext));
            throw secVE;
        }
    }
30686
def _sync(pack):
    """"""
    task_queue = Queue()
    result_queue = Queue()
    task = SignedPackage.loads(pack)
    task_queue.put(task)
    task_queue.put('STOP')
    worker(task_queue, result_queue, Value('f', -1))
    result_queue.put('STOP')
    monitor(result_queue)
    task_queue.close()
    task_queue.join_thread()
    result_queue.close()
    result_queue.join_thread()
    return task['id']
971337
def synchronised(func):
        """"""

        # pylint: disable=E0213
        def Wrapper(main_obj, *args, **kwargs):
            main_obj._lock.acquire()  # pylint: disable=W0212
            try:
                return func(main_obj, *args, **kwargs)  # pylint: disable=E1102
            finally:
                main_obj._lock.release()  # pylint: disable=W0212

        return Wrapper
846375
final void unipush(Completion c) {
    if (c != null) {
      while (!tryPushStack(c)) {
        if (result != null) {
          lazySetNext(c, null);
          break;
        }
      }
      if (result != null)
        c.tryFire(SYNC);
    }
  }
448273
void synchronizeFromFollower(String peerId)
      throws IOException, TimeoutException, InterruptedException {
    LOG.debug("Begins synchronizing from follower {}.", peerId);
    Zxid lastZxid = persistence.getLatestZxid();
    Message pullTxn = MessageBuilder.buildPullTxnReq(lastZxid);
    LOG.debug("Last zxid of {} is {}", this.serverId, lastZxid);
    sendMessage(peerId, pullTxn);
    // Waits until the synchronization is finished.
    waitForSync(peerId);
  }
819779
@Override
    public boolean addSync() throws ResourceException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) { 
            Tr.entry(this, tc, "addSync");
        }

        UOWCoordinator uowCoord = mcWrapper.getUOWCoordinator();

        if (uowCoord == null) {
            // No transaction context.  Should never happen.
            // removed null check on mcWrapper since it is redundant from the above code (mcWrapper.getUOWCoordinator())
            String pmiName = mcWrapper.gConfigProps.cfName;

            Object[] parms = new Object[] { "addSync", pmiName };
            Tr.error(tc, "NO_VALID_TRANSACTION_CONTEXT_J2CA0040", parms); 
            throw new ResourceException("INTERNAL ERROR: No valid transaction context present");

        }

        try {

            //  No need to register for synchronization for unshared/LTC/res-control=Application.
            //  Instead of cleanup being done via after completion it will either happen at close or
            //  commit/rollback which ever happens last.  This will allow the connection to be returned
            //  to the pool prior to the end of the LTC scope allowing better utilization of the connection.
            boolean shareable = mcWrapper.getConnectionManager().shareable();
            if (!shareable && !J2CUtilityClass.isContainerAtBoundary(mcWrapper.pm.connectorSvc.transactionManager)) {
                //Register an instance of a no-transaction wrapper
                // so the TM will create an RRS NativeLocalTranasction.  The wrapper
                // provides "empty" TransactioWrapper and Synchronization behaviors,
                // but indicates to the TM that the LTC requires RRS support.  
                ((LocalTransactionCoordinator) uowCoord).enlistSynchronization(new RRSNoTransactionWrapper());

                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) { 
                    Tr.exit(this, tc, "addSync", "returning without registering.");
                }
                return false;
            } else { // Register a synchronization with the Transaction Manager
                ((LocalTransactionCoordinator) uowCoord).enlistSynchronization(this);
                mcWrapper.markRRSLocalTransactionWrapperInUse();
                registeredForSync = true;
            }
        } catch (ResourceException e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ejs.j2c.RRSLocalTransactionWrapper.addSync", "594", this);
            Object[] parms = new Object[] { "addSync", e, "Exception" };
            Tr.error(tc, "REGISTER_WITH_SYNCHRONIZATION_EXCP_J2CA0026", parms);
            throw e;
        } catch (Exception e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ejs.j2c.RRSLocalTransactionWrapper.addSync", "605", this);
            Object[] parms = new Object[] { "addSync", e, "Exception" };
            Tr.error(tc, "REGISTER_WITH_SYNCHRONIZATION_EXCP_J2CA0026", parms);
            ResourceException re = new ResourceException("addSync: caught Exception");
            re.initCause(e);
            throw re;
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) { 
            Tr.exit(this, tc, "addSync", registeredForSync);
        }

        return registeredForSync;

    }
199906
private void syncContext(boolean isInit)
    {
    	// jmeter context synchronisation
    	JMeterContext current = JMeterContextService.getContext();
		JMeterContext ctx = this.getThreadContext();
		
		if (isInit)
		{
			current.setCurrentSampler(ctx.getCurrentSampler());
			current.setEngine(ctx.getEngine());
			current.setRestartNextLoop(ctx.isRestartNextLoop());
			current.setSamplingStarted(ctx.isSamplingStarted());
			current.setThread(ctx.getThread());
			current.setThreadGroup(ctx.getThreadGroup());
			current.setThreadNum(ctx.getThreadNum());
		}
		current.setVariables(ctx.getVariables());
		current.setPreviousResult(ctx.getPreviousResult());
		//current.getSamplerContext().putAll(ctx.getSamplerContext());
    }
311245
def synchronized(cls, obj=None):
        

        def get_key(f, o):
            if o is None:
                key = hash(f)
            else:
                key = hash(o)
            return key

        def get_lock(f, o):
            key = get_key(f, o)
            if key not in cls.lock_map:
                with cls.lock_map_lock:
                    if key not in cls.lock_map:
                        cls.lock_map[key] = _init_lock()
            return cls.lock_map[key]

        def wrap(f):
            @functools.wraps(f)
            def new_func(*args, **kw):
                with get_lock(f, obj):
                    return f(*args, **kw)

            return new_func

        return wrap
1187215
def _synced(method, self, args, kwargs):
    """"""
    with self._lock:
        return method(*args, **kwargs)
1101235
def sync(self):
        

        # needs some mods for ultracam ??
        xbin = self.xbin.value()
        ybin = self.ybin.value()
        n = 0
        for xsl, xsr, ys, nx, ny in self:
            if xbin > 1:
                xsl = xbin*((xsl-1)//xbin)+1
                self.xsl[n].set(xsl)
                xsr = xbin*((xsr-1025)//xbin)+1025
                self.xsr[n].set(xsr)

            if ybin > 1:
                ys = ybin*((ys-1)//ybin)+1
                self.ys[n].set(ys)

            n += 1
        g = get_root(self).globals
        self.sbutt.config(bg=g.COL['main'])
        self.sbutt.config(state='disable')
600169
def _sync(timeout=None):
    
    evt = WeakEvent(auto_reset=False)

    # first ensure that any pending callbacks from worker threads have been delivered
    # these are calls of _fromMain()
    Callback(evt.Signal)
    evt.Wait(timeout=timeout)

    evt.Reset() # reuse

    # grab the current set of inprogress cothreads/events
    wait4 = set(_handlers)
    # because Spawn.Wait() can only be called once, remove them and
    # use 'evt' as a proxy for what I'm waiting on so that overlapping
    # calls to _sync() will wait for these as well.
    # However, this means that our failure will must cascade to subsequent
    # calls to _sync() before we complete.
    _handlers.clear()
    _handlers.add(evt)

    try:
        WaitForAll(wait4, timeout=timeout)
    except Exception as e:
        evt.SignalException(e) # pass along error to next concurrent _sync()
    else:
        evt.Signal()
1089490
def join(self, timeout=None):
        """"""
        if not self._ioloop_managed:
            # Do nothing if the loop is not managed
            return
        try:
            self._ioloop_thread.join(timeout)
        except AttributeError:
            raise RuntimeError('Cannot join if not started')
1358810
function subscribeRaw(peripheralId, serviceUuid, uuid, state, callback) {

  //todo catch exceptions
  var peripheral = peripherals[peripheralId];
  var characteristic = servicesCache[peripheralId].services[serviceUuid].characteristics[uuid];
  var handle = characteristic.descriptors['2902'];

  if (state == false) {
    value = '0000';
  } else {
    if (characteristic.properties == 'indicate'){
      value = '0200';
    } else  {// notify
      value = '0100';
    }    
  }

  //if not connected, connect
  checkConnected(peripheral, function(){
    peripheral.writeHandle(handle, new Buffer(value, 'hex'), false, function(error){
      if (error){
        debug('Subscribe error '.red + peripheralId + ' : ' + serviceUuid + ' : ' + uuid )
      }
      sendEvent({
        type: 'notify',
        peripheralId: peripheralId,
        serviceUuid: serviceUuid,
        characteristicUuid: uuid,
        state: state
      });
    });
  })

  checkRawNotificationListeners();
}
827421
public void ccowJoin() {
        if (ccowIsActive()) {
            return;
        }

        if (ccowContextManager == null && ccowEnabled) {
            ccowContextManager = new CCOWContextManager();
            ccowContextManager.subscribe(this);
            ccowContextManager.run("CareWebFramework#", "", true, "*");
        }

        if (ccowContextManager != null) {
            if (!ccowContextManager.isActive()) {
                ccowContextManager.resume();
            }

            init(response -> {
                if (response.rejected()) {
                    ccowContextManager.suspend();
                }

                updateCCOWStatus();
            });
        }
    }
1251394
@Override
    public void enlistAsyncResource(String xaResFactoryFilter, Serializable xaResInfo, Xid xid) throws SystemException // @LIDB1922-5C
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "enlistAsyncResource (SPI): args: ", new Object[] { xaResFactoryFilter, xaResInfo, xid });
        try {
            final WSATAsyncResource res = new WSATAsyncResource(xaResFactoryFilter, xaResInfo, xid);
            final WSATParticipantWrapper wrapper = new WSATParticipantWrapper(res);
            getResources().addAsyncResource(wrapper);
        } finally {
            if (tc.isEntryEnabled())
                Tr.exit(tc, "enlistAsyncResource (SPI)");
        }
    }