/* (non-Javadoc)
@see org.jdiameter.api.auth.ClientAuthSessionListener#
doAuthAnswerEvent(org.jdiameter.api.auth.ClientAuthSession, org.jdiameter.api.app.AppRequestEvent, org.jdiameter.api.app.AppAnswerEvent)
356851
@Override
  public void doAuthAnswerEvent(ClientAuthSession appSession, AppRequestEvent request, AppAnswerEvent answer)
      throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
    logger.info("Diameter Gq AuthorizationSessionFactory :: doAuthAnswerEvent :: appSession[{}], Request[{}], Answer[{}]",
        new Object[]{appSession, request, answer});
  }
651871
public void onTimerEvent(TimerEvent event, ActivityContextInterface aci) {
		// detaching so the null AC is claimed after the event handling
		aci.detach(sbbContext.getSbbLocalObject());
		try {
			DataSourceChildSbbLocalInterface child = (DataSourceChildSbbLocalInterface) getLocationChildRelation().create();
			child.getBindings(getSender().getURI().toString());
		} catch (Exception e) {
			tracer.severe("failed to create sip registrar child sbb, to lookup the sender's contacts",e);
			return;
		}
	}
1127485
@Override
    public void publishTenantCreatedTenantEvent(
            HttpServletRequest request, Object source, ITenant tenant) {
        final PortalEvent.PortalEventBuilder eventBuilder =
                this.createPortalEventBuilder(source, request);
        final TenantCreatedTenantEvent event = new TenantCreatedTenantEvent(eventBuilder, tenant);
        this.applicationEventPublisher.publishEvent(event);
    }
616343
@Override
    public synchronized void processAuthorize(WebSocketChannel channel, String authorizeToken) {
        nextHandler.processAuthorize(channel, authorizeToken); 
    }
188593
@Override
  public void sendAuthAnswer(AppAnswerEvent appAnswerEvent) throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
    send(null, appAnswerEvent);
  }
442529
public Closeable onAuthenticationSuccessEvent(final Consumer<BitfinexAccountSymbol> listener) {
        authSuccessConsumers.offer(listener);
        return () -> authSuccessConsumers.remove(listener);
    }
1312124
BoxRevokeAuthRequest revokeOAuth(String token, String clientId, String clientSecret) {
        BoxRevokeAuthRequest request = new BoxRevokeAuthRequest(mSession, getTokenRevokeUrl(), token, clientId, clientSecret);
        request.setRequestHandler(new BoxRequest.BoxRequestHandler(request){

            @Override
            public boolean onException(BoxRequest request, BoxHttpResponse response, BoxException ex) throws BoxException.RefreshFailure {
                // if a revoke request fails for any reason we do not want to retry it again after the user refreshes or logs in again.
                return false;
            }
        });
        return request;
    }
756923
@Override
    public ChainableEvent onSuccess(Event onSuccessEvent) {
        this.onSuccessChains.add(new ChainLink()
                .onSuccess(linkChainIdentifier(onSuccessEvent)));
        return this;
    }
574612
void triggerSessionRequested(Jingle initJin) {

        JingleSessionRequestListener[] jingleSessionRequestListeners;

        // Make a synchronized copy of the listenerJingles
        synchronized (this.jingleSessionRequestListeners) {
            jingleSessionRequestListeners = new JingleSessionRequestListener[this.jingleSessionRequestListeners.size()];
            this.jingleSessionRequestListeners.toArray(jingleSessionRequestListeners);
        }

        // ... and let them know of the event
        JingleSessionRequest request = new JingleSessionRequest(this, initJin);
        for (int i = 0; i < jingleSessionRequestListeners.length; i++) {
            jingleSessionRequestListeners[i].sessionRequested(request);
        }
    }
830699
function SubscriptionOperation(
    log, cb, streamId, resolveLinkTos, userCredentials, eventAppeared,
    subscriptionDropped, verboseLogging, getConnection
) {
  //TODO: validations
  //Ensure.NotNull(log, "log");
  //Ensure.NotNull(source, "source");
  //Ensure.NotNull(eventAppeared, "eventAppeared");
  //Ensure.NotNull(getConnection, "getConnection");

  this._log = log;
  this._cb = cb;
  this._streamId = streamId || '';
  this._resolveLinkTos = resolveLinkTos;
  this._userCredentials = userCredentials;
  this._eventAppeared = eventAppeared;
  this._subscriptionDropped = subscriptionDropped || function() {};
  this._verboseLogging = verboseLogging;
  this._getConnection = getConnection;

  this._correlationId = null;
  this._unsubscribed = false;
  this._subscription = null;
  this._actionExecuting = false;
  this._actionQueue = [];
}
1175816
public static <T> T getPasswordlessAuthenticationAccount(final RequestContext event, final Class<T> clazz) {
        return getPasswordlessAuthenticationAccount(event.getCurrentEvent(), clazz);
    }
914871
@Override
  public void doReAuthRequestEvent(ClientAuthSession appSession, ReAuthRequest rar)
      throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
    logger.info("Diameter Gq AuthorizationSessionFactory :: doReAuthRequestEvent :: appSession[{}], RAR[{}]", appSession, rar);
  }
681146
@Override
  public boolean handleEvent(StateEvent event) throws InternalException, OverloadException {
    try {
      sendAndStateLock.lock();
      if (!super.session.isValid()) {
        // FIXME: throw new InternalException("Generic session is not valid.");
        return false;
      }
      final S6aSessionState state = this.sessionData.getS6aSessionState();
      S6aSessionState newState = null;
      Event localEvent = (Event) event;
      Event.Type eventType = (Type) event.getType();
      switch (state) {

        case IDLE:
          switch (eventType) {

            case RECEIVE_AIR:
              this.sessionData.setBuffer((Request) ((AppEvent) event.getData()).getMessage());
              super.cancelMsgTimer();
              super.startMsgTimer();
              newState = S6aSessionState.MESSAGE_SENT_RECEIVED;
              setState(newState);
              listener.doAuthenticationInformationRequestEvent(this, (JAuthenticationInformationRequest) event.getData());
              break;

            case RECEIVE_PUR:
              this.sessionData.setBuffer((Request) ((AppEvent) event.getData()).getMessage());
              super.cancelMsgTimer();
              super.startMsgTimer();
              newState = S6aSessionState.MESSAGE_SENT_RECEIVED;
              setState(newState);
              listener.doPurgeUERequestEvent(this, (JPurgeUERequest) event.getData());
              break;

            case RECEIVE_ULR:
              this.sessionData.setBuffer((Request) ((AppEvent) event.getData()).getMessage());
              super.cancelMsgTimer();
              super.startMsgTimer();
              newState = S6aSessionState.MESSAGE_SENT_RECEIVED;
              setState(newState);
              listener.doUpdateLocationRequestEvent(this, (JUpdateLocationRequest) event.getData());
              break;

            case RECEIVE_NOR:
              this.sessionData.setBuffer((Request) ((AppEvent) event.getData()).getMessage());
              super.cancelMsgTimer();
              super.startMsgTimer();
              newState = S6aSessionState.MESSAGE_SENT_RECEIVED;
              setState(newState);
              listener.doNotifyRequestEvent(this, (JNotifyRequest) event.getData());
              break;

            case SEND_MESSAGE:
              super.session.send(((AppEvent) event.getData()).getMessage(), this);
              newState = S6aSessionState.MESSAGE_SENT_RECEIVED;
              setState(newState);
              break;

            default:
              logger.error("Wrong action in S6a Server FSM. State: IDLE, Event Type: {}", eventType);
              break;
          }
          break;

        case MESSAGE_SENT_RECEIVED:
          switch (eventType) {
            case TIMEOUT_EXPIRES:
              newState = S6aSessionState.TIMEDOUT;
              setState(newState);
              break;

            case SEND_MESSAGE:
              try {
                super.session.send(((AppEvent) event.getData()).getMessage(), this);
              }
              finally {
                newState = S6aSessionState.TERMINATED;
                setState(newState);
              }
              break;

            case RECEIVE_CLA:
              try {
                super.cancelMsgTimer();
                listener.doCancelLocationAnswerEvent(this, (JCancelLocationRequest) localEvent.getRequest(), (JCancelLocationAnswer) localEvent.getAnswer());
              }
              finally {
                newState = S6aSessionState.TERMINATED;
                setState(newState);
              }
              break;

            case RECEIVE_IDA:
              try {
                super.cancelMsgTimer();
                listener.doInsertSubscriberDataAnswerEvent(this, (JInsertSubscriberDataRequest) localEvent.getRequest(),
                    (JInsertSubscriberDataAnswer) localEvent.getAnswer());
              }
              finally {
                newState = S6aSessionState.TERMINATED;
                setState(newState);
              }
              break;

            case RECEIVE_DSA:
              try {
                super.cancelMsgTimer();
                listener.doDeleteSubscriberDataAnswerEvent(this, (JDeleteSubscriberDataRequest) localEvent.getRequest(),
                    (JDeleteSubscriberDataAnswer) localEvent.getAnswer());
              }
              finally {
                newState = S6aSessionState.TERMINATED;
                setState(newState);
              }
              break;

            case RECEIVE_RSA:
              try {
                super.cancelMsgTimer();
                listener.doResetAnswerEvent(this, (JResetRequest) localEvent.getRequest(), (JResetAnswer) localEvent.getAnswer());
              }
              finally {
                newState = S6aSessionState.TERMINATED;
                setState(newState);
              }
              break;

            default:
              throw new InternalException("Should not receive more messages after initial. Command: " + event.getData());
          }
          break;

        case TERMINATED:
          throw new InternalException("Cant receive message in state TERMINATED. Command: " + event.getData());

        case TIMEDOUT:
          throw new InternalException("Cant receive message in state TIMEDOUT. Command: " + event.getData());

        default:
          logger.error("S6a Server FSM in wrong state: {}", state);
          break;
      }
    }
    catch (Exception e) {
      throw new InternalException(e);
    }
    finally {
      sendAndStateLock.unlock();
    }

    return true;
  }
1156773
@Override
  public void addAuthListener(final StitchAuthListener listener) {
    synchronized (this) {
      listeners.add(listener);
    }

    // Trigger the onUserLoggedIn event in case some event happens and
    // this caller would miss out on this event other wise.
    onAuthEvent(listener);
    dispatcher.dispatch(
        new Callable<Void>() {
          @Override
          public Void call() {
            listener.onListenerRegistered(StitchAuthImpl.this);
            return null;
          }
        });
  }
244908
public function onPreAuthorizationProcess(OAuthEvent $event)
    {
        /* @var $client Client */
        if(null !== $client = $event->getClient())
        {
            if ($client->isPrivate())
            {
                $event->setAuthorizedClient(true);
            }
        }
    }
1279874
public void onServiceStartedEvent(ServiceStartedEvent event,
			ActivityContextInterface aci) {
		tracer.info("Restcomm SLEE REST Client Enabler Example service activation.");
		try {
			RESTClientEnablerChild child = (RESTClientEnablerChild) getChildRelation()
					.create(ChildRelationExt.DEFAULT_CHILD_NAME);
			String uri = twitterStatusUpdateBaseURI
					+ URLEncoder.encode(
							"Restcomm SLEE REST Client Application Enabler Example ACTIVATED - "
									+ new Date(), "UTF-8");
			RESTClientEnablerRequest request = new RESTClientEnablerRequest(
					RESTClientEnablerRequest.Type.POST, uri)
					.setOAuthConsumer(consumer);
			child.execute(request);
		} catch (Exception e) {
			tracer.severe("failed to post service activation to twitter", e);
		}
	}
94549
private void scheduleAuthentication(final int appId, final String bridgeId,
      final CallStatsHttp2Client httpClient) {
    scheduler.schedule(new Runnable() {
      public void run() {
        sendAsyncAuthenticationRequest(appId, bridgeId, httpClient);
      }
    }, authenticationRetryTimeout, TimeUnit.MILLISECONDS);
  }