Tabnine Logo
GenericTokenEntry
Code IndexAdd Tabnine to your IDE (free)

How to use
GenericTokenEntry
in
org.axonframework.eventhandling.tokenstore

Best Java code snippets using org.axonframework.eventhandling.tokenstore.GenericTokenEntry (Showing top 17 results out of 315)

origin: AxonFramework/AxonFramework

/**
 * Convert given {@code resultSet} to an {@link AbstractTokenEntry}. The result set contains a single token entry.
 *
 * @param resultSet the result set of a prior select statement containing a single token entry
 * @return an token entry with data extracted from the result set
 *
 * @throws SQLException if the result set cannot be converted to an entry
 */
protected AbstractTokenEntry<?> readTokenEntry(ResultSet resultSet) throws SQLException {
  return new GenericTokenEntry<>(readSerializedData(resultSet, schema.tokenColumn()),
                  resultSet.getString(schema.tokenTypeColumn()),
                  resultSet.getString(schema.timestampColumn()),
                  resultSet.getString(schema.ownerColum()),
                  resultSet.getString(schema.processorNameColumn()),
                  resultSet.getInt(schema.segmentColumn()), contentType);
}
origin: AxonFramework/AxonFramework

@Override
public void updateToken(TrackingToken token, Serializer serializer) {
  updateToken(token, serializer, contentType);
}
origin: AxonFramework/AxonFramework

/**
 * Inserts a new token entry via the given updatable {@code resultSet}.
 *
 * @param resultSet     the updatable result set to add the entry to
 * @param token         the token of the entry to insert
 * @param processorName the name of the processor to insert a token for
 * @param segment       the segment of the processor to insert a token for
 * @return the tracking token of the inserted entry
 *
 * @throws SQLException when an exception occurs while inserting a token entry
 */
protected TrackingToken insertTokenEntry(ResultSet resultSet, TrackingToken token, String processorName,
                     int segment) throws SQLException {
  AbstractTokenEntry<?> entry = new GenericTokenEntry<>(token, serializer, contentType, processorName, segment);
  entry.claim(nodeId, claimTimeout);
  resultSet.moveToInsertRow();
  resultSet.updateObject(schema.tokenColumn(), token == null ? null : entry.getSerializedToken().getData());
  resultSet.updateString(schema.tokenTypeColumn(),
              token == null ? null : entry.getSerializedToken().getType().getName());
  resultSet.updateString(schema.timestampColumn(), entry.timestampAsString());
  resultSet.updateString(schema.ownerColum(), entry.getOwner());
  resultSet.updateString(schema.processorNameColumn(), processorName);
  resultSet.updateInt(schema.segmentColumn(), segment);
  resultSet.insertRow();
  return token;
}
origin: org.axonframework/axon-core

@Override
public void updateToken(TrackingToken token, Serializer serializer) {
  updateToken(token, serializer, contentType);
}
origin: org.axonframework/axon-mongo

@Override
public void initializeTokenSegments(String processorName, int segmentCount, TrackingToken initialToken) throws UnableToClaimTokenException {
  if (fetchSegments(processorName).length > 0) {
    throw new UnableToClaimTokenException("Unable to initialize segments. Some tokens were already present for the given processor.");
  }
  List<Document> entries = IntStream.range(0, segmentCount)
                   .mapToObj(segment -> new GenericTokenEntry<>(initialToken, serializer,
                                          contentType, processorName,
                                          segment))
                   .map(this::tokenEntryToDocument)
                   .collect(Collectors.toList());
  mongoTemplate.trackingTokensCollection()
         .insertMany(entries, new InsertManyOptions().ordered(false));
}
origin: org.axonframework/axon-messaging

@Override
public void updateToken(TrackingToken token, Serializer serializer) {
  updateToken(token, serializer, contentType);
}
origin: org.axonframework/axon-core

/**
 * Convert given {@code resultSet} to an {@link AbstractTokenEntry}. The result set contains a single token entry.
 *
 * @param resultSet the result set of a prior select statement containing a single token entry
 * @return an token entry with data extracted from the result set
 * @throws SQLException if the result set cannot be converted to an entry
 */
protected AbstractTokenEntry<?> readTokenEntry(ResultSet resultSet) throws SQLException {
  return new GenericTokenEntry<>(readSerializedData(resultSet, schema.tokenColumn()),
                  resultSet.getString(schema.tokenTypeColumn()),
                  resultSet.getString(schema.timestampColumn()),
                  resultSet.getString(schema.ownerColum()),
                  resultSet.getString(schema.processorNameColumn()),
                  resultSet.getInt(schema.segmentColumn()), contentType);
}
origin: org.axonframework.extensions.mongo/axon-mongo

@Override
public void initializeTokenSegments(String processorName,
                  int segmentCount,
                  TrackingToken initialToken) throws UnableToClaimTokenException {
  if (fetchSegments(processorName).length > 0) {
    throw new UnableToClaimTokenException(
        "Unable to initialize segments. Some tokens were already present for the given processor."
    );
  }
  List<Document> entries = IntStream.range(0, segmentCount)
                   .mapToObj(segment -> new GenericTokenEntry<>(initialToken, serializer,
                                          contentType, processorName,
                                          segment))
                   .map(this::tokenEntryToDocument)
                   .collect(Collectors.toList());
  mongoTemplate.trackingTokensCollection()
         .insertMany(entries, new InsertManyOptions().ordered(false));
}
origin: org.axonframework/axon-messaging

/**
 * Convert given {@code resultSet} to an {@link AbstractTokenEntry}. The result set contains a single token entry.
 *
 * @param resultSet the result set of a prior select statement containing a single token entry
 * @return an token entry with data extracted from the result set
 *
 * @throws SQLException if the result set cannot be converted to an entry
 */
protected AbstractTokenEntry<?> readTokenEntry(ResultSet resultSet) throws SQLException {
  return new GenericTokenEntry<>(readSerializedData(resultSet, schema.tokenColumn()),
                  resultSet.getString(schema.tokenTypeColumn()),
                  resultSet.getString(schema.timestampColumn()),
                  resultSet.getString(schema.ownerColum()),
                  resultSet.getString(schema.processorNameColumn()),
                  resultSet.getInt(schema.segmentColumn()), contentType);
}
origin: org.axonframework/axon-mongo

private AbstractTokenEntry<?> documentToTokenEntry(Document document) {
  return new GenericTokenEntry<>(
      readSerializedData(document),
      document.getString("tokenType"),
      Instant.ofEpochMilli(document.getLong("timestamp")).toString(),
      document.getString("owner"),
      document.getString("processorName"),
      document.getInteger("segment"),
      contentType);
}
origin: org.axonframework.extensions.mongo/axon-mongo

private AbstractTokenEntry<?> documentToTokenEntry(Document document) {
  return new GenericTokenEntry<>(
      readSerializedData(document),
      document.getString("tokenType"),
      Instant.ofEpochMilli(document.getLong("timestamp")).toString(),
      document.getString("owner"),
      document.getString("processorName"),
      document.getInteger("segment"),
      contentType);
}
origin: org.axonframework/axon-mongo

private void updateOrInsertTokenEntry(TrackingToken token, String processorName, int segment) {
  AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(token,
                                serializer,
                                contentType,
                                processorName,
                                segment);
  tokenEntry.claim(nodeId, claimTimeout);
  Bson update = combine(set("owner", nodeId),
             set("timestamp", tokenEntry.timestamp().toEpochMilli()),
             set("token", tokenEntry.getSerializedToken().getData()),
             set("tokenType", tokenEntry.getSerializedToken().getType().getName()));
  UpdateResult updateResult = mongoTemplate.trackingTokensCollection()
                       .updateOne(claimableTokenEntryFilter(processorName, segment), update);
  if (updateResult.getModifiedCount() == 0) {
    try {
      mongoTemplate.trackingTokensCollection()
             .insertOne(tokenEntryToDocument(tokenEntry));
    } catch (MongoWriteException exception) {
      if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) {
        throw new UnableToClaimTokenException(format("Unable to claim token '%s[%s]'",
                               processorName,
                               segment));
      }
    }
  }
}
origin: org.axonframework.extensions.mongo/axon-mongo

private void updateOrInsertTokenEntry(TrackingToken token, String processorName, int segment) {
  AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(token,
                                serializer,
                                contentType,
                                processorName,
                                segment);
  tokenEntry.claim(nodeId, claimTimeout);
  Bson update = combine(set("owner", nodeId),
             set("timestamp", tokenEntry.timestamp().toEpochMilli()),
             set("token", tokenEntry.getSerializedToken().getData()),
             set("tokenType", tokenEntry.getSerializedToken().getType().getName()));
  UpdateResult updateResult = mongoTemplate.trackingTokensCollection()
                       .updateOne(claimableTokenEntryFilter(processorName, segment), update);
  if (updateResult.getModifiedCount() == 0) {
    try {
      mongoTemplate.trackingTokensCollection()
             .insertOne(tokenEntryToDocument(tokenEntry));
    } catch (MongoWriteException exception) {
      if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) {
        throw new UnableToClaimTokenException(format("Unable to claim token '%s[%s]'",
                               processorName,
                               segment));
      }
    }
  }
}
origin: org.axonframework/axon-mongo

private AbstractTokenEntry<?> loadOrInsertTokenEntry(String processorName, int segment) {
  Document document = mongoTemplate.trackingTokensCollection()
                   .findOneAndUpdate(claimableTokenEntryFilter(processorName, segment),
                            combine(set("owner", nodeId),
                                set("timestamp", clock.millis())),
                            new FindOneAndUpdateOptions()
                                .returnDocument(ReturnDocument.AFTER));
  if (document == null) {
    try {
      AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(null,
                                    serializer,
                                    contentType,
                                    processorName,
                                    segment);
      tokenEntry.claim(nodeId, claimTimeout);
      mongoTemplate.trackingTokensCollection()
             .insertOne(tokenEntryToDocument(tokenEntry));
      return tokenEntry;
    } catch (MongoWriteException exception) {
      if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) {
        throw new UnableToClaimTokenException(format("Unable to claim token '%s[%s]'",
                               processorName,
                               segment));
      }
    }
  }
  return documentToTokenEntry(document);
}
origin: org.axonframework.extensions.mongo/axon-mongo

private AbstractTokenEntry<?> loadOrInsertTokenEntry(String processorName, int segment) {
  Document document = mongoTemplate.trackingTokensCollection()
                   .findOneAndUpdate(claimableTokenEntryFilter(processorName, segment),
                            combine(set("owner", nodeId),
                                set("timestamp", clock.millis())),
                            new FindOneAndUpdateOptions()
                                .returnDocument(ReturnDocument.AFTER));
  if (document == null) {
    try {
      AbstractTokenEntry<?> tokenEntry = new GenericTokenEntry<>(null,
                                    serializer,
                                    contentType,
                                    processorName,
                                    segment);
      tokenEntry.claim(nodeId, claimTimeout);
      mongoTemplate.trackingTokensCollection()
             .insertOne(tokenEntryToDocument(tokenEntry));
      return tokenEntry;
    } catch (MongoWriteException exception) {
      if (ErrorCategory.fromErrorCode(exception.getError().getCode()) == ErrorCategory.DUPLICATE_KEY) {
        throw new UnableToClaimTokenException(format("Unable to claim token '%s[%s]'",
                               processorName,
                               segment));
      }
    }
  }
  return documentToTokenEntry(document);
}
origin: org.axonframework/axon-core

/**
 * Inserts a new token entry via the given updatable {@code resultSet}.
 *
 * @param resultSet     the updatable result set to add the entry to
 * @param token         the token of the entry to insert
 * @param processorName the name of the processor to insert a token for
 * @param segment       the segment of the processor to insert a token for
 * @return the tracking token of the inserted entry
 * @throws SQLException when an exception occurs while inserting a token entry
 */
protected TrackingToken insertTokenEntry(ResultSet resultSet, TrackingToken token, String processorName,
                     int segment) throws SQLException {
  AbstractTokenEntry<?> entry = new GenericTokenEntry<>(token, serializer, contentType, processorName, segment);
  entry.claim(nodeId, claimTimeout);
  resultSet.moveToInsertRow();
  resultSet.updateObject(schema.tokenColumn(), token == null ? null : entry.getSerializedToken().getData());
  resultSet.updateString(schema.tokenTypeColumn(),
              token == null ? null : entry.getSerializedToken().getType().getName());
  resultSet.updateString(schema.timestampColumn(), entry.timestampAsString());
  resultSet.updateString(schema.ownerColum(), entry.getOwner());
  resultSet.updateString(schema.processorNameColumn(), processorName);
  resultSet.updateInt(schema.segmentColumn(), segment);
  resultSet.insertRow();
  return token;
}
origin: org.axonframework/axon-messaging

/**
 * Inserts a new token entry via the given updatable {@code resultSet}.
 *
 * @param resultSet     the updatable result set to add the entry to
 * @param token         the token of the entry to insert
 * @param processorName the name of the processor to insert a token for
 * @param segment       the segment of the processor to insert a token for
 * @return the tracking token of the inserted entry
 *
 * @throws SQLException when an exception occurs while inserting a token entry
 */
protected TrackingToken insertTokenEntry(ResultSet resultSet, TrackingToken token, String processorName,
                     int segment) throws SQLException {
  AbstractTokenEntry<?> entry = new GenericTokenEntry<>(token, serializer, contentType, processorName, segment);
  entry.claim(nodeId, claimTimeout);
  resultSet.moveToInsertRow();
  resultSet.updateObject(schema.tokenColumn(), token == null ? null : entry.getSerializedToken().getData());
  resultSet.updateString(schema.tokenTypeColumn(),
              token == null ? null : entry.getSerializedToken().getType().getName());
  resultSet.updateString(schema.timestampColumn(), entry.timestampAsString());
  resultSet.updateString(schema.ownerColum(), entry.getOwner());
  resultSet.updateString(schema.processorNameColumn(), processorName);
  resultSet.updateInt(schema.segmentColumn(), segment);
  resultSet.insertRow();
  return token;
}
org.axonframework.eventhandling.tokenstoreGenericTokenEntry

Javadoc

Generic implementation of a token entry.

Most used methods

  • <init>
    Initializes a new token entry for given token, process and segment. The given serializer can be used
  • updateToken

Popular in Java

  • Finding current android device location
  • addToBackStack (FragmentTransaction)
  • getSharedPreferences (Context)
  • getSupportFragmentManager (FragmentActivity)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • BoxLayout (javax.swing)
  • JButton (javax.swing)
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now