public void run()

in gremlin-client-demo/src/main/java/software/amazon/neptune/TxDemo.java [90:156]


    public void run() {

        try {

            EndpointsSelector selector = EndpointsType.ClusterEndpoint;

            ClusterEndpointsRefreshAgent refreshAgent = createRefreshAgent();

            NeptuneGremlinClusterBuilder builder = NeptuneGremlinClusterBuilder.build()
                    .enableSsl(!disableSsl)
                    .enableIamAuth(enableIam)
                    .iamProfile(profile)
                    .addContactPoints(refreshAgent.getEndpoints(selector))
                    .minConnectionPoolSize(3)
                    .maxConnectionPoolSize(3)
                    .port(neptunePort);

            if (StringUtils.isNotEmpty(serviceRegion)) {
                builder = builder.serviceRegion(serviceRegion);
            }

            GremlinCluster cluster = builder.create();
            GremlinClient client = cluster.connect();

            refreshAgent.startPollingNeptuneAPI(
                    client, selector, intervalSeconds,
                    TimeUnit.SECONDS
            );

            DriverRemoteConnection connection = DriverRemoteConnection.using(client);

            for (int i = 0; i < txCount; i++) {

                Transaction tx = traversal().withRemote(connection).tx();
                GraphTraversalSource g = tx.begin();

                try {

                    String id1 = UUID.randomUUID().toString();
                    String id2 = UUID.randomUUID().toString();

                    g.addV("testNode").property(T.id, id1).iterate();
                    g.addV("testNode").property(T.id, id2).iterate();
                    g.addE("testEdge").from(__.V(id1)).to(__.V(id2)).iterate();

                    tx.commit();

                    System.out.println("Tx complete: " + i);
                    System.out.println("id1        : " + id1);
                    System.out.println("id2        : " + id2);

                } catch (Exception e) {
                    logger.warn("Error processing query: {}", e.getMessage());
                    tx.rollback();
                }
            }

            refreshAgent.close();
            client.close();
            cluster.close();

        } catch (Exception e) {
            System.err.println("An error occurred while connecting to Neptune:");
            e.printStackTrace();
            System.exit(-1);
        }
    }