private static void writeToOutputStream(Object obj, CodedOutputStream out) throws IOException {
        out.writeRawByte(STRING);
        out.writeStringNoTag((String)obj);
    }

private static void writeToOutputStream ( Object obj , CodedOutputStream out ) throws IOException { out . writeRawByte ( STRING ) ; out . writeStringNoTag ( ( String ) obj ) ; }


protected int getTtl(Locator locator, RollupType rollupType, Granularity granularity) {
        return (int) TTL_PROVIDER.getTTL(locator.getTenantId(),
                    granularity,
                    rollupType).get().toSeconds();
    }

protected int getTtl ( Locator locator , RollupType rollupType , Granularity granularity ) { return ( int ) TTL_PROVIDER . getTTL ( locator . getTenantId ( ) , granularity , rollupType ) . get ( ) . toSeconds ( ) ; }

Gets the TTL for a particular locator, rollupType and granularity.

@param locator
@param rollupType
@param granularity
@return

Gets the TTL for a particular locator rollupType and granularity .


private void createPreparedStatements()  {

        // create a generic select statement for retrieving from metrics_locator
        Select.Where select = QueryBuilder
                .select()
                .all()
                .from( CassandraModel.CF_METRICS_LOCATOR_NAME )
                .where( eq ( KEY, bindMarker() ));
        getValue = DatastaxIO.getSession().prepare( select );

        // create a generic insert statement for inserting into metrics_locator
        Insert insert = QueryBuilder.insertInto( CassandraModel.CF_METRICS_LOCATOR_NAME)
                .using(ttl(TenantTtlProvider.LOCATOR_TTL))
                .value(KEY, bindMarker())
                .value(COLUMN1, bindMarker())
                .value(VALUE, bindMarker());
        putValue = DatastaxIO.getSession()
                .prepare(insert)
                .setConsistencyLevel( ConsistencyLevel.LOCAL_ONE );
    }

Create all prepared statements use in this class for metrics_locator


public void trackDelayedMetricsTenant(String tenantid, final List<Metric> delayedMetrics) {
        if (isTrackingDelayedMetrics) {
            String logMessage = String.format("[TRACKER][DELAYED METRIC] Tenant sending delayed metrics %s", tenantid);
            log.info(logMessage);

            // log individual delayed metrics locator and collectionTime
            double delayedMinutes;
            long nowMillis = System.currentTimeMillis();
            for (Metric metric : delayedMetrics) {
                delayedMinutes = (double)(nowMillis - metric.getCollectionTime()) / 1000 / 60;
                logMessage = String.format("[TRACKER][DELAYED METRIC] %s has collectionTime %s which is delayed by %.2f minutes",
                        metric.getLocator().toString(),
                        dateFormatter.format(new Date(metric.getCollectionTime())),
                        delayedMinutes);
                log.info(logMessage);
            }
        }
    }

This method is used to log delayed metrics, if tracking delayed metrics
is turned on for this Blueflood service.
@param tenantid
@param delayedMetrics

This method is used to log delayed metrics if tracking delayed metrics is turned on for this Blueflood service .


public void trackDelayedAggregatedMetricsTenant(String tenantId, long collectionTimeMs, long delayTimeMs, List<String> delayedMetricNames) {
        if (isTrackingDelayedMetrics) {
            String logMessage = String.format("[TRACKER][DELAYED METRIC] Tenant sending delayed metrics %s", tenantId);
            log.info(logMessage);

            // log individual delayed metrics locator and collectionTime
            double delayMin = delayTimeMs / 1000 / 60;
            logMessage = String.format("[TRACKER][DELAYED METRIC] %s have collectionTime %s which is delayed by %.2f minutes",
                    StringUtils.join(delayedMetricNames, ","),
                        dateFormatter.format(new Date(collectionTimeMs)),
                        delayMin);
            log.info(logMessage);
        }
    }

This method logs the delayed aggregated metrics for a particular tenant,
if tracking delayed metric is turned on for this Blueflood service.
Aggregated metrics have one single timestamp for the group of metrics that
are sent in one request.

@param tenantId              the tenantId who's the sender of the metrics
@param collectionTimeMs      the collection timestamp (ms) in request payload
@param delayTimeMs           the delayed time (ms)
@param delayedMetricNames    the list of delayed metrics in request payload

This method logs the delayed aggregated metrics for a particular tenant if tracking delayed metric is turned on for this Blueflood service . Aggregated metrics have one single timestamp for the group of metrics that are sent in one request .


protected Number getUnversionedDoubleOrLong(CodedInputStream in) throws IOException {
        byte type = in.readRawByte();
        if (type == Constants.B_DOUBLE)
            return in.readDouble();
        else
            return in.readRawVarint64();
    }

protected Number getUnversionedDoubleOrLong ( CodedInputStream in ) throws IOException { byte type = in . readRawByte ( ) ; if ( type == Constants . B_DOUBLE ) return in . readDouble ( ) ; else return in . readRawVarint64 ( ) ; }


protected void putUnversionedDoubleOrLong(Number number, CodedOutputStream out) throws IOException {
        if (number instanceof Double) {
            out.writeRawByte(Constants.B_DOUBLE);
            out.writeDoubleNoTag(number.doubleValue());
        } else {
            out.writeRawByte(Constants.B_I64);
            out.writeRawVarint64(number.longValue());
        }
    }

protected void putUnversionedDoubleOrLong ( Number number , CodedOutputStream out ) throws IOException { if ( number instanceof Double ) { out . writeRawByte ( Constants . B_DOUBLE ) ; out . writeDoubleNoTag ( number . doubleValue ( ) ) ; } else { out . writeRawByte ( Constants . B_I64 ) ; out . writeRawVarint64 ( number . longValue ( ) ) ; } }

put out a number prefaced only by a type.

put out a number prefaced only by a type .


public Map<Object, Object> getAllProperties() {

        Map<Object, Object> map = new HashMap<Object, Object>();
        for (Object key : defaultProps.keySet()) {
            map.put(key, defaultProps.getProperty(key.toString()));
        }
        for (Object key : props.keySet()) {
            map.put(key, props.getProperty(key.toString()));
        }

        return Collections.unmodifiableMap(map);
    }

public Map < Object , Object > getAllProperties ( ) { Map < Object , Object > map = new HashMap < Object , Object > ( ) ; for ( Object key : defaultProps . keySet ( ) ) { map . put ( key , defaultProps . getProperty ( key . toString ( ) ) ) ; } for ( Object key : props . keySet ( ) ) { map . put ( key , props . getProperty ( key . toString ( ) ) ) ; } return Collections . unmodifiableMap ( map ) ; }

Convert the existing configuration values into a Map, including those specified in defaultProps.

@return an unmodifiable Map

Convert the existing configuration values into a Map including those specified in defaultProps .


private void createContainer() {
        String containerName = CONTAINER_DATE_FORMAT.format(new Date());
        blobStore.createContainerInLocation(null, containerName);
        lastContainerCreated = containerName;
    }

private void createContainer ( ) { String containerName = CONTAINER_DATE_FORMAT . format ( new Date ( ) ) ; blobStore . createContainerInLocation ( null , containerName ) ; lastContainerCreated = containerName ; }

idempotent other than when the month changes between two calls


void scheduleEligibleSlots(long maxAgeMillis, long rollupDelayForMetricsWithShortDelay, long rollupWaitForMetricsWithLongDelay) {
        long now = scheduleTime;
        ArrayList<Integer> shardKeys = new ArrayList<Integer>(shardStateManager.getManagedShards());
        Collections.shuffle(shardKeys);

        for (int shard : shardKeys) {
            for (Granularity g : Granularity.rollupGranularities()) {
                // sync on map since we do not want anything added to or taken from it while we iterate.
                synchronized (scheduledSlots) { // read
                    synchronized (runningSlots) { // read

                        List<Integer> slotsToWorkOn = shardStateManager.getSlotStateManager(shard, g)
                                .getSlotsEligibleForRollup(now, maxAgeMillis, rollupDelayForMetricsWithShortDelay, rollupWaitForMetricsWithLongDelay);

                        if (slotsToWorkOn.size() == 0) {
                            continue;
                        }
                        if (!canWorkOnShard(shard)) {
                            continue;
                        }

                        for (Integer slot : slotsToWorkOn) {
                            SlotKey slotKey = SlotKey.of(g, slot, shard);
                            if (areChildKeysOrSelfKeyScheduledOrRunning(slotKey)) {
                                continue;
                            }
                            SlotKey key = SlotKey.of(g, slot, shard);
                            scheduledSlots.add(key);
                            orderedScheduledSlots.add(key);
                            recentlyScheduledShards.put(shard, scheduleTime);
                        }
                    }
                }
            }
        }
    }

only one thread should be calling in this puppy.

only one thread should be calling in this puppy .


void clearFromRunning(SlotKey slotKey) {
        synchronized (runningSlots) {
            runningSlots.remove(slotKey);
            UpdateStamp stamp = shardStateManager.getUpdateStamp(slotKey);
            shardStateManager.setAllCoarserSlotsDirtyForSlot(slotKey);

            //When state gets set to "X", before it got persisted, it might get scheduled for rollup
            //again, if we get delayed metrics. To prevent this we temporarily set last rollup time with current
            //time. This value wont get persisted.
            long currentTimeInMillis = clock.now().getMillis();
            stamp.setLastRollupTimestamp(currentTimeInMillis);
            log.debug("SlotKey {} is marked in memory with last rollup time as {}", slotKey, currentTimeInMillis);

            // Update the stamp to Rolled state if and only if the current state
            // is running. If the current state is active, it means we received
            // a delayed put which toggled the status to Active.
            if (stamp.getState() == UpdateStamp.State.Running) {
                stamp.setState(UpdateStamp.State.Rolled);
                // Note: Rollup state will be updated to the last ACTIVE
                // timestamp which caused rollup process to kick in.
                stamp.setDirty(true);
            }
        }
    }

Remove the given slot from the running group after it has been
successfully re-rolled.

@param slotKey

Remove the given slot from the running group after it has been successfully re - rolled .


public Emitter on(String event, Listener fn) {
        ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.get(event);
        if (callbacks == null) {
            callbacks = new ConcurrentLinkedQueue<Listener>();
            ConcurrentLinkedQueue<Listener> _callbacks = this.callbacks.putIfAbsent(event, callbacks);
            if (_callbacks != null) {
                callbacks = _callbacks;
            }
        }
        callbacks.add(fn);
        return this;
    }

public Emitter on ( String event , Listener fn ) { ConcurrentLinkedQueue < Listener > callbacks = this . callbacks . get ( event ) ; if ( callbacks == null ) { callbacks = new ConcurrentLinkedQueue < Listener > ( ) ; ConcurrentLinkedQueue < Listener > _callbacks = this . callbacks . putIfAbsent ( event , callbacks ) ; if ( _callbacks != null ) { callbacks = _callbacks ; } } callbacks . add ( fn ) ; return this ; }

Listens on the event.
@param event event name.
@param fn
@return a reference to this object.


public Emitter once(final String event, final Listener<T> fn) {
        Listener on = new Listener<T>() {
            @Override
            public void call(T... args) {
                Emitter.this.off(event, this);
                fn.call(args);
            }
        };

        this.onceCallbacks.put(fn, on);
        this.on(event, on);
        return this;
    }

public Emitter once ( final String event , final Listener < T > fn ) { Listener on = new Listener < T > ( ) { @ Override public void call ( T ... args ) { Emitter . this . off ( event , this ) ; fn . call ( args ) ; } } ; this . onceCallbacks . put ( fn , on ) ; this . on ( event , on ) ; return this ; }

Adds a one time listener for the event.

@param event an event name.
@param fn
@return a reference to this object.

Adds a one time listener for the event .


public Emitter off(String event) {
        ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.remove(event);
        if (callbacks != null) {
            for (Listener fn : callbacks) {
                this.onceCallbacks.remove(fn);
            }
        }
        return this;
    }

public Emitter off ( String event ) { ConcurrentLinkedQueue < Listener > callbacks = this . callbacks . remove ( event ) ; if ( callbacks != null ) { for ( Listener fn : callbacks ) { this . onceCallbacks . remove ( fn ) ; } } return this ; }

Removes all listeners of the specified event.

@param event an event name.
@return a reference to this object.

Removes all listeners of the specified event .


public Future emit(String event, T... args) {
        ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.get(event);
        if (callbacks != null) {
            callbacks = new ConcurrentLinkedQueue<Listener>(callbacks);
            for (Listener fn : callbacks) {
                fn.call(args);
            }
        }
        return null;
    }

public Future emit ( String event , T ... args ) { ConcurrentLinkedQueue < Listener > callbacks = this . callbacks . get ( event ) ; if ( callbacks != null ) { callbacks = new ConcurrentLinkedQueue < Listener > ( callbacks ) ; for ( Listener fn : callbacks ) { fn . call ( args ) ; } } return null ; }

Executes each of listeners with the given args.

@param event an event name.
@param args
@return a reference to this object.

Executes each of listeners with the given args .


public List<Listener> listeners(String event) {
        ConcurrentLinkedQueue<Listener> callbacks = this.callbacks.get(event);
        return callbacks != null ?
                new ArrayList<Listener>(callbacks) : new ArrayList<Listener>();
    }

public List < Listener > listeners ( String event ) { ConcurrentLinkedQueue < Listener > callbacks = this . callbacks . get ( event ) ; return callbacks != null ? new ArrayList < Listener > ( callbacks ) : new ArrayList < Listener > ( ) ; }

Returns a list of listeners for the specified event.

@param event an event name.
@return a reference to this object.

Returns a list of listeners for the specified event .


public String getRemoteName() {
        Date time = new Date(timestamp);
        String formattedTime = new SimpleDateFormat("yyyyMMdd_").format(time);
        return formattedTime + System.currentTimeMillis() + "_" + Configuration.getInstance().getStringProperty(CloudfilesConfig.CLOUDFILES_HOST_UNIQUE_IDENTIFIER);
    }

public String getRemoteName ( ) { Date time = new Date ( timestamp ) ; String formattedTime = new SimpleDateFormat ( "yyyyMMdd_" ) . format ( time ) ; return formattedTime + System . currentTimeMillis ( ) + "_" + Configuration . getInstance ( ) . getStringProperty ( CloudfilesConfig . CLOUDFILES_HOST_UNIQUE_IDENTIFIER ) ; }

Get the remote file name.

@return The path to the remote file.


public void append(RollupEvent rollup) throws IOException {
        ensureOpen();
        outputStream.write(serializer.toBytes(rollup));
        outputStream.write('\n');
        outputStream.flush();
    }

public void append ( RollupEvent rollup ) throws IOException { ensureOpen ( ) ; outputStream . write ( serializer . toBytes ( rollup ) ) ; outputStream . write ( ' ' ) ; outputStream . flush ( ) ; }

Serialize a Rollup Event and append it to the file.

@param rollup The rollup to append.
@throws IOException

Serialize a Rollup Event and append it to the file .


private static long parseTimestamp(String fileName) throws NumberFormatException {
        String numberPart = fileName.substring(0, fileName.length() - 5);
        return Long.parseLong(numberPart);
    }

private static long parseTimestamp ( String fileName ) throws NumberFormatException { String numberPart = fileName . substring ( 0 , fileName . length ( ) - 5 ) ; return Long . parseLong ( numberPart ) ; }

Parse the timestamp from a filename.

@param fileName The file name to parse.
@return The timestamp contained in the file name.
@throws NumberFormatException


public void startServer() throws InterruptedException {

        RouteMatcher router = new RouteMatcher();
        router.get("/v1.0", new DefaultHandler());
        router.post("/v1.0/multitenant/experimental/metrics",
                new HttpMultitenantMetricsIngestionHandler(processor, timeout, ENABLE_PER_TENANT_METRICS));
        router.post("/v1.0/:tenantId/experimental/metrics",
                new HttpMetricsIngestionHandler(processor, timeout, ENABLE_PER_TENANT_METRICS));
        router.post("/v1.0/:tenantId/experimental/metrics/statsd",
                new HttpAggregatedIngestionHandler(processor, timeout, ENABLE_PER_TENANT_METRICS));

        router.get("/v2.0", new DefaultHandler());
        router.post("/v2.0/:tenantId/ingest/multi",
                new HttpMultitenantMetricsIngestionHandler(processor, timeout, ENABLE_PER_TENANT_METRICS));
        router.post("/v2.0/:tenantId/ingest",
                new HttpMetricsIngestionHandler(processor, timeout, ENABLE_PER_TENANT_METRICS));
        router.post("/v2.0/:tenantId/ingest/aggregated",
                new HttpAggregatedIngestionHandler(processor, timeout, ENABLE_PER_TENANT_METRICS));
        router.post("/v2.0/:tenantId/ingest/aggregated/multi",
                new HttpAggregatedMultiIngestionHandler(processor, timeout, ENABLE_PER_TENANT_METRICS));
        router.post("/v2.0/:tenantId/events", getHttpEventsIngestionHandler());
        final RouteMatcher finalRouter = router;

        log.info("Starting metrics listener HTTP server on port {}", httpIngestPort);
        ServerBootstrap server = new ServerBootstrap();
        server.group(acceptorGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel channel) throws Exception {
                        setupPipeline(channel, finalRouter);
                    }
                });

        Channel channel = server.bind(new InetSocketAddress(httpIngestHost, httpIngestPort)).sync().channel();
        allOpenChannels.add(channel);

        //register the tracker MBean for JMX/jolokia
        log.info("Registering tracker service");
        Tracker.getInstance().register();

        log.info("Token search improvements enabled: " + EXP_TOKEN_SEARCH_IMPROVEMENTS);
    }

Starts the Ingest server

@throws InterruptedException


public static Rollup.Type getRollupComputer(RollupType srcType, Granularity srcGran) {
        switch (srcType) {
            case COUNTER:
                return Rollup.CounterFromCounter;
            case TIMER:
                return Rollup.TimerFromTimer;
            case GAUGE:
                return Rollup.GaugeFromGauge;
            case BF_BASIC:
                return srcGran == Granularity.FULL ? Rollup.BasicFromRaw : Rollup.BasicFromBasic;
            case SET:
                return Rollup.SetFromSet;
            default:
                break;
        }
        throw new IllegalArgumentException(String.format("Cannot compute rollups for %s from %s", srcType.name(), srcGran.shortName()));
    }

public
static
Rollup
.
Type
getRollupComputer
(
RollupType
srcType
,
Granularity
srcGran
)
{
switch
(
srcType
)
{
case
COUNTER
:
return
Rollup
.
CounterFromCounter
;
case
TIMER
:
return
Rollup
.
TimerFromTimer
;
case
GAUGE
:
return
Rollup
.
GaugeFromGauge
;
case
BF_BASIC
:
return
srcGran
==
Granularity
.
FULL
Rollup
.
BasicFromRaw
:
Rollup
.
BasicFromBasic
;
case
SET
:
return
Rollup
.
SetFromSet
;
default
:
break
;
}
throw
new
IllegalArgumentException
(
String
.
format
(
"Cannot compute rollups for %s from %s"
,
srcType
.
name
(
)
,
srcGran
.
shortName
(
)
)
)
;
}

determine which DataType to use for serialization.

determine which DataType to use for serialization .


public static synchronized IOContainer fromConfig() {
        if ( FROM_CONFIG_INSTANCE == null ) {

            String driver = configuration.getStringProperty(CoreConfig.CASSANDRA_DRIVER);
            LOG.info(String.format("Using driver %s", driver));

            boolean isRecordingDelayedMetrics = configuration.getBooleanProperty(CoreConfig.RECORD_DELAYED_METRICS);
            LOG.info(String.format("Recording delayed metrics: %s", isRecordingDelayedMetrics));

            boolean isDtxIngestBatchEnabled = configuration.getBooleanProperty(CoreConfig.ENABLE_DTX_INGEST_BATCH);
            LOG.info(String.format("Datastax Ingest batch enabled: %s", isDtxIngestBatchEnabled));

            FROM_CONFIG_INSTANCE = new IOContainer(DriverType.getDriverType(driver),
                                            isRecordingDelayedMetrics,
                                            isDtxIngestBatchEnabled);
        }

        return FROM_CONFIG_INSTANCE;
    }

public
static
synchronized
IOContainer
fromConfig
(
)
{
if
(
FROM_CONFIG_INSTANCE
==
)
{
String
driver
=
configuration
.
getStringProperty
(
CoreConfig
.
CASSANDRA_DRIVER
)
;
LOG
.
info
(
String
.
format
(
"Using driver %s"
,
driver
)
)
;
boolean
isRecordingDelayedMetrics
=
configuration
.
getBooleanProperty
(
CoreConfig
.
RECORD_DELAYED_METRICS
)
;
LOG
.
info
(
String
.
format
(
"Recording delayed metrics: %s"
,
isRecordingDelayedMetrics
)
)
;
boolean
isDtxIngestBatchEnabled
=
configuration
.
getBooleanProperty
(
CoreConfig
.
ENABLE_DTX_INGEST_BATCH
)
;
LOG
.
info
(
String
.
format
(
"Datastax Ingest batch enabled: %s"
,
isDtxIngestBatchEnabled
)
)
;
FROM_CONFIG_INSTANCE
=
new
IOContainer
(
DriverType
.
getDriverType
(
driver
)
,
isRecordingDelayedMetrics
,
isDtxIngestBatchEnabled
)
;
}
return
FROM_CONFIG_INSTANCE
;
}

Returns an instance of this class based on what configuration says our
driver should be.

@return IOContainer

Returns an instance of this class based on what configuration says our driver should be .


private boolean put(
        ImmutableTable.Builder<Granularity, RollupType, TimeValue> ttlMapBuilder,
        Configuration config,
        Granularity gran,
        RollupType rollupType,
        TtlConfig configKey) {
        int value;
        try {
            value = config.getIntegerProperty(configKey);
            if (value < 0) return false;
        } catch (NumberFormatException ex) {
            log.trace(String.format("No valid TTL config set for granularity: %s, rollup type: %s",
                    gran.name(), rollupType.name()), ex);
            return false;
        }
        ttlMapBuilder.put(gran, rollupType, new TimeValue(value, TimeUnit.DAYS));
        return true;
    }

Helper function to build the ttl mapping. Only insert to the mapping if the value is a valid date.
@param ttlMapBuilder
@param config
@param gran
@param rollupType
@param configKey
@return true if the insertion is successful, false otherwise.

Helper function to build the ttl mapping . Only insert to the mapping if the value is a valid date .


public static int [] computeMaximums(String[] headers, OutputFormatter... outputs) {
        int[] max = new int[headers.length];
        for (int i = 0; i < headers.length; i++)
            max[i] = headers[i].length();
        for (OutputFormatter output : outputs) {
            max[0] = Math.max(output.host.length(), max[0]);
            for (int i = 1; i < headers.length; i++)
                max[i] = Math.max(output.results[i-1].length(), max[i]);
        }
        return max;
    }

public static int [ ] computeMaximums ( String [ ] headers , OutputFormatter ... outputs ) { int [ ] max = new int [ headers . length ] ; for ( int i = 0 ; i < headers . length ; i ++ ) max [ i ] = headers [ i ] . length ( ) ; for ( OutputFormatter output : outputs ) { max [ 0 ] = Math . max ( output . host . length ( ) , max [ 0 ] ) ; for ( int i = 1 ; i < headers . length ; i ++ ) max [ i ] = Math . max ( output . results [ i - 1 ] . length ( ) , max [ i ] ) ; } return max ; }

compute the maximum width for each field across a collection of formatters.

compute the maximum width for each field across a collection of formatters .


public static String formatHeader(int[] maximums, String[] headers) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < headers.length; i++)
            sb = sb.append(formatIn(headers[i], maximums[i], false)).append(GAP);
        return sb.toString();
    }

public static String formatHeader ( int [ ] maximums , String [ ] headers ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < headers . length ; i ++ ) sb = sb . append ( formatIn ( headers [ i ] , maximums [ i ] , false ) ) . append ( GAP ) ; return sb . toString ( ) ; }

formats a header row after maximums have been established.

formats a header row after maximums have been established .


public static String[] format(int[] maximums, OutputFormatter... outputs) {
        String[] formattedStrings = new String[outputs.length];
        int pos = 0;
        for (OutputFormatter output : outputs) {
            StringBuilder sb = new StringBuilder();
            sb = sb.append(formatIn(output.host, maximums[0], false));
            for (int i = 0; i < output.results.length; i++)
                sb = sb.append(GAP).append(formatIn(output.results[i], maximums[i+1], true));
            formattedStrings[pos++] = sb.toString();
        }
        return formattedStrings;
    }

public static String [ ] format ( int [ ] maximums , OutputFormatter ... outputs ) { String [ ] formattedStrings = new String [ outputs . length ] ; int pos = 0 ; for ( OutputFormatter output : outputs ) { StringBuilder sb = new StringBuilder ( ) ; sb = sb . append ( formatIn ( output . host , maximums [ 0 ] , false ) ) ; for ( int i = 0 ; i < output . results . length ; i ++ ) sb = sb . append ( GAP ) . append ( formatIn ( output . results [ i ] , maximums [ i + 1 ] , true ) ) ; formattedStrings [ pos ++ ] = sb . toString ( ) ; } return formattedStrings ; }

formats results and sets formattedStrings.

formats results and sets formattedStrings .


private void registerMetrics(final ObjectName nameObj, MetricRegistry reg) {
        reg.register(MetricRegistry.name(ZKShardLockManager.class, "Lock Disinterested Time Millis"),
                new JmxAttributeGauge(nameObj, "LockDisinterestedTimeMillis"));
        reg.register(MetricRegistry.name(ZKShardLockManager.class, "Min Lock Hold Time Millis"),
                new JmxAttributeGauge(nameObj, "MinLockHoldTimeMillis"));
        reg.register(MetricRegistry.name(ZKShardLockManager.class, "Seconds Since Last Scavenge"),
                new JmxAttributeGauge(nameObj, "SecondsSinceLastScavenge"));

        reg.register(MetricRegistry.name(ZKShardLockManager.class, "Zk Connection Status"),
                new JmxAttributeGauge(nameObj, "ZkConnectionStatus") {
                    @Override
                    public Object getValue() {
                        Object val = super.getValue();
                        if (val.equals("connected")) {
                            return 1;
                        }
                        return 0;
                    }
                });
        reg.register(MetricRegistry.name(ZKShardLockManager.class, "Held Shards"),
                new Gauge<Integer>() {
                    @Override
                    public Integer getValue() {
                        return getHeldShards().size();
                    }
                });

        reg.register(MetricRegistry.name(ZKShardLockManager.class, "Unheld Shards"),
                new Gauge<Integer>() {
                    @Override
                    public Integer getValue() {
                        return getUnheldShards().size();
                    }
                });
        reg.register(MetricRegistry.name(ZKShardLockManager.class, "Error Shards"),
                new Gauge<Integer>() {
                    @Override
                    public Integer getValue() {
                        return getErrorShards().size();
                    }
                });
    }

private
void
registerMetrics
(
final
ObjectName
nameObj
,
MetricRegistry
reg
)
{
reg
.
register
(
MetricRegistry
.
name
(
ZKShardLockManager
.
class
,
"Lock Disinterested Time Millis"
)
,
new
JmxAttributeGauge
(
nameObj
,
"LockDisinterestedTimeMillis"
)
)
;
reg
.
register
(
MetricRegistry
.
name
(
ZKShardLockManager
.
class
,
"Min Lock Hold Time Millis"
)
,
new
JmxAttributeGauge
(
nameObj
,
"MinLockHoldTimeMillis"
)
)
;
reg
.
register
(
MetricRegistry
.
name
(
ZKShardLockManager
.
class
,
"Seconds Since Last Scavenge"
)
,
new
JmxAttributeGauge
(
nameObj
,
"SecondsSinceLastScavenge"
)
)
;
reg
.
register
(
MetricRegistry
.
name
(
ZKShardLockManager
.
class
,
"Zk Connection Status"
)
,
new
JmxAttributeGauge
(
nameObj
,
"ZkConnectionStatus"
)
{
@
Override
public
Object
getValue
(
)
{
Object
val
=
super
.
getValue
(
)
;
if
(
val
.
equals
(
"connected"
)
)
{
return
1
;
}
return
0
;
}
}
)
;
reg
.
register
(
MetricRegistry
.
name
(
ZKShardLockManager
.
class
,
"Held Shards"
)
,
new
Gauge
<
Integer
>
(
)
{
@
Override
public
Integer
getValue
(
)
{
return
getHeldShards
(
)
.
size
(
)
;
}
}
)
;
reg
.
register
(
MetricRegistry
.
name
(
ZKShardLockManager
.
class
,
"Unheld Shards"
)
,
new
Gauge
<
Integer
>
(
)
{
@
Override
public
Integer
getValue
(
)
{
return
getUnheldShards
(
)
.
size
(
)
;
}
}
)
;
reg
.
register
(
MetricRegistry
.
name
(
ZKShardLockManager
.
class
,
"Error Shards"
)
,
new
Gauge
<
Integer
>
(
)
{
@
Override
public
Integer
getValue
(
)
{
return
getErrorShards
(
)
.
size
(
)
;
}
}
)
;
}

Registers the different ZooKeeper metrics.

Registers the different ZooKeeper metrics .


public ThreadPoolBuilder withName(String name) {
        // ensure we've got a spot to put the thread id.
        if (!name.contains("%d")) {
            name = name + "-%d";
        }
        nameMap.putIfAbsent(name, new AtomicInteger(0));
        int id = nameMap.get(name).incrementAndGet();
        this.poolName = String.format(name, id);
        if (id > 1) {
            this.threadNameFormat = name.replace("%d", id + "-%d");
        } else {
            this.threadNameFormat = name;
        }
        return this;
    }

Set the threadpool name. Used to generate metric names and thread names.

Set the threadpool name . Used to generate metric names and thread names .


public void add(String metricIndex, long docCount) {

        final String[] tokens = metricIndex.split(METRIC_TOKEN_SEPARATOR_REGEX);

        /**
         *
         * For the ES response shown in class description, for a baseLevel of 2,
         * the data is classified as follows
         *
         * metricNamesWithNextLevelSet    -> {foo.bar.baz}   (Metric Names which are at base + 1 level and also have a subsequent level.)
         *
         * For count map, data is in the form {metricIndex, (actualDocCount, childrenTotalDocCount)}
         *
         * metricNameBaseLevelMap   -> {foo.bar.baz -> (2, 1)}     (all indexes which are of same length as baseLevel)
         *
         */

        switch (tokens.length - baseLevel) {
            case 1:
                if (baseLevel > 0) {
                    metricNamesWithNextLevelSet.add(metricIndex.substring(0, metricIndex.lastIndexOf(".")));
                } else {
                    metricNamesWithNextLevelSet.add(metricIndex.substring(0, metricIndex.indexOf(".")));
                }

                //For foo.bar.baz, baseLevel=3 we update children doc count of foo.bar.baz
                addChildrenDocCount(metricNameBaseLevelMap,
                                    metricIndex.substring(0, metricIndex.lastIndexOf(".")),
                                    docCount);
                break;

            case 0:

                setActualDocCount(metricNameBaseLevelMap, metricIndex, docCount);
                break;

            default:
                break;
        }
    }

For a given metricIndex and docCount, classifies the data with respect to baseLevel
and stores it accordingly.

@param metricIndex
@param docCount is document(metric name) count

For a given metricIndex and docCount classifies the data with respect to baseLevel and stores it accordingly .


private Set<String> getCompleteMetricNames(Map<String, MetricIndexDocCount> metricIndexMap) {

        Set<String> completeMetricNames = new HashSet<String>();
        for (Map.Entry<String, MetricIndexDocCount> entry : metricIndexMap.entrySet()) {

            MetricIndexDocCount metricIndexDocCount = entry.getValue();
            if (metricIndexDocCount != null) {

                //if total doc count is greater than its children docs, its a complete metric name
                if (metricIndexDocCount.actualDocCount > 0 &&
                        metricIndexDocCount.actualDocCount > metricIndexDocCount.childrenTotalDocCount) {
                    completeMetricNames.add(entry.getKey());
                }
            }
        }

        return Collections.unmodifiableSet(completeMetricNames);
    }

Compares actualDocCount and total docCount of its immediate children of an index
to determine if the metric index is a complete metric name or not.

For the ES response shown in class description, for a baseLevel of 2,
foo.bar.baz has actualDocCount of 2, but total doc count of all its children,
which in this case is only foo.bar.baz, is 1. So foo.bar.baz must be metric by itself

@param metricIndexMap
@return

Compares actualDocCount and total docCount of its immediate children of an index to determine if the metric index is a complete metric name or not .


public static List<Token> getTokens(Locator locator) {

        if (StringUtils.isEmpty(locator.getMetricName()) || StringUtils.isEmpty(locator.getTenantId()))
            return new ArrayList<>();

        String[] tokens = locator.getMetricName().split(Locator.METRIC_TOKEN_SEPARATOR_REGEX);

        return IntStream.range(0, tokens.length)
                        .mapToObj(index -> new Token(locator, tokens, index))
                        .collect(toList());
    }

public static List < Token > getTokens ( Locator locator ) { if ( StringUtils . isEmpty ( locator . getMetricName ( ) ) || StringUtils . isEmpty ( locator . getTenantId ( ) ) ) return new ArrayList <> ( ) ; String [ ] tokens = locator . getMetricName ( ) . split ( Locator . METRIC_TOKEN_SEPARATOR_REGEX ) ; return IntStream . range ( 0 , tokens . length ) . mapToObj ( index -> new Token ( locator , tokens , index ) ) . collect ( toList ( ) ) ; }

This method return list of tokens with their parents for a current Discovery object.

For example: A locator of 1111:a.b.c.d would generate the following tokens

Token{token='a', parent='', isLeaf=false, id='111111:a', locator=111111.a.b.c.d}
Token{token='b', parent='a', isLeaf=false, id='111111:a.b', locator=111111.a.b.c.d}
Token{token='c', parent='a.b', isLeaf=false, id='111111:a.b.c', locator=111111.a.b.c.d}
Token{token='d', parent='a.b.c', isLeaf=true, id='111111:a.b.c.d:$', locator=111111.a.b.c.d}

@return

This method return list of tokens with their parents for a current Discovery object .


public ResultSetFuture putAsync(Locator locator, long collectionTime, Rollup rollup, Granularity granularity, int ttl) {

        Session session = DatastaxIO.getSession();

        // we use batch statement here in case sub classes
        // override the addRollupToBatch() and provide
        // multiple statements
        BatchStatement batch = new BatchStatement();
        addRollupToBatch(batch, locator, rollup, collectionTime, granularity, ttl);

        Collection<Statement> statements = batch.getStatements();
        if ( statements.size() == 1 ) {
            Statement oneStatement = statements.iterator().next();
            return session.executeAsync(oneStatement);
        } else {
            LOG.debug(String.format("Using BatchStatement for %d statements", statements.size()));
            return session.executeAsync(batch);
        }
    }

Asynchronously insert a rolled up metric to the appropriate column family
for a particular granularity

@param locator
@param collectionTime
@param rollup
@param granularity
@return


public static Granularity granularityFromPointsInInterval(String tenantid, long from, long to, int points, String algorithm, long assumedIntervalMillis, Clock ttlComparisonClock) {
        if (from >= to) {
            throw new RuntimeException("Invalid interval specified for fromPointsInInterval");
        }

        double requestedDuration = to - from;

        if (algorithm.startsWith("GEOMETRIC"))
            return granularityFromPointsGeometric(tenantid, from, to, requestedDuration, points, assumedIntervalMillis, ttlComparisonClock);
        else if (algorithm.startsWith("LINEAR"))
            return granularityFromPointsLinear(requestedDuration, points, assumedIntervalMillis);
        else if (algorithm.startsWith("LESSTHANEQUAL"))
            return granularityFromPointsLessThanEqual(requestedDuration, points, assumedIntervalMillis);

        return granularityFromPointsGeometric(tenantid, from, to, requestedDuration, points, assumedIntervalMillis, ttlComparisonClock);
    }

Return granularity that maps most closely to requested number of points based on
provided selection algorithm

@param from beginning of interval (millis)
@param to end of interval (millis)
@param points count of desired data points
@param algorithm the algorithm to use. Valid values are
{@code "GEOMETRIC"}, {@code "LINEAR"}, and
{@code "LESSTHANEQUAL"}. Any other value is treated as
{@code "GEOMETRIC"}.
@param assumedIntervalMillis FULL resolution is tricky because we don't
know the period of check in question.
Assume the minimum period and go from there.
NOTE: This value and description was from a
previous version of the software, and the
original author is no longer available to
clarify. The exact purpose of this
parameter is not yet fully understood.
@param ttlComparisonClock The GEOMETRIC algorithm checks the specified
interval against a TTL. Normally, the TTL is
measured relative to the current point in
time. For testing purposes, an alternate time
source can be provided, to measure the TTL
relative to a different point in time.
@return


private static Granularity granularityFromPointsLessThanEqual(double requestedDuration, int points, long assumedIntervalMillis) {
        Granularity gran = granularityFromPointsLinear(requestedDuration, points, assumedIntervalMillis);

        if (requestedDuration / gran.milliseconds() > points) {
            try {
                gran = gran.coarser();
            } catch (GranularityException e) { /* do nothing, already at 1440m */ }
        }

        return gran;
    }

private
static
Granularity
granularityFromPointsLessThanEqual
(
double
requestedDuration
,
int
points
,
long
assumedIntervalMillis
)
{
Granularity
gran
=
granularityFromPointsLinear
(
requestedDuration
,
points
,
assumedIntervalMillis
)
;
if
(
requestedDuration
/
gran
.
milliseconds
(
)
>
points
)
{
try
{
gran
=
gran
.
coarser
(
)
;
}
catch
(
GranularityException
e
)
{
/* do nothing, already at 1440m */
}
}
return
gran
;
}

Find the granularity in the interval that will yield a number of data points that are
closest to the requested points but <= requested points.

@param requestedDuration
@param points
@return

Find the granularity in the interval that will yield a number of data points that are closest to the requested points but < = requested points .


public synchronized void setServerTime(long millis) {
        log.info("Manually setting server time to {}  {}", millis, new java.util.Date(millis));
        context.setCurrentTimeMillis(millis);
    }

"Manually setting server time to {}  {}"


public Set<String> getUniqueHosts() {
        Set<String> uniqueHosts = new HashSet<String>();
        Collections.addAll(uniqueHosts, config.getStringProperty(CoreConfig.CASSANDRA_HOSTS).split(","));
        return uniqueHosts;
    }

public Set < String > getUniqueHosts ( ) { Set < String > uniqueHosts = new HashSet < String > ( ) ; Collections . addAll ( uniqueHosts , config . getStringProperty ( CoreConfig . CASSANDRA_HOSTS ) . split ( "," ) ) ; return uniqueHosts ; }

Retrieves the set of unique Cassandra hosts from configuration file.
If a single host appears multiple times in the configuration, only one will
be listed.

@return set of unique Cassandra hosts

Retrieves the set of unique Cassandra hosts from configuration file . If a single host appears multiple times in the configuration only one will be listed .


public int getMaxConnPerHost(int numHosts) {
        int maxConns = config.getIntegerProperty(CoreConfig.MAX_CASSANDRA_CONNECTIONS);
        return maxConns / numHosts + (maxConns % numHosts == 0 ? 0 : 1);
    }

public int getMaxConnPerHost ( int numHosts ) { int maxConns = config . getIntegerProperty ( CoreConfig . MAX_CASSANDRA_CONNECTIONS ) ; return maxConns / numHosts + ( maxConns % numHosts == 0 ? 0 : 1 ) ; }

Calculates the number of max connections per Cassandra hosts

@param numHosts the number of Cassandra hosts in the cluster
@return the number of max connections


public static Iterable<MetricColumnFamily> getMetricColumnFamilies() {
        return new Iterable<MetricColumnFamily>() {
            @Override
            public Iterator<MetricColumnFamily> iterator() {
                return new Iterator<MetricColumnFamily>() {
                    private int pos = 0;
                    @Override
                    public boolean hasNext() {
                        return pos < METRIC_COLUMN_FAMILES.length;
                    }

                    @Override
                    public MetricColumnFamily next() {
                        return METRIC_COLUMN_FAMILES[pos++];
                    }

                    @Override
                    public void remove() {
                        throw new NoSuchMethodError("Not implemented");
                    }
                };
            }
        };
    }

public
static
Iterable
<
MetricColumnFamily
>
getMetricColumnFamilies
(
)
{
return
new
Iterable
<
MetricColumnFamily
>
(
)
{
@
Override
public
Iterator
<
MetricColumnFamily
>
iterator
(
)
{
return
new
Iterator
<
MetricColumnFamily
>
(
)
{
private
int
pos
=
0
;
@
Override
public
boolean
hasNext
(
)
{
return
pos
<
METRIC_COLUMN_FAMILES
.
length
;
}
@
Override
public
MetricColumnFamily
next
(
)
{
return
METRIC_COLUMN_FAMILES
[
pos
++
]
;
}
@
Override
public
void
remove
(
)
{
throw
new
NoSuchMethodError
(
"Not implemented"
)
;
}
}
;
}
}
;
}

iterate over all column families that store metrics.

iterate over all column families that store metrics .


@Override
    public void insertMetrics(Collection<IMetric> metrics) throws IOException {
        insertMetrics(metrics, Granularity.FULL);
    }

@ Override public void insertMetrics ( Collection < IMetric > metrics ) throws IOException { insertMetrics ( metrics , Granularity . FULL ) ; }

Inserts a collection of metrics to the metrics_preaggregated_full column family

@param metrics
@throws IOException


@Override
    public void insertMetrics(Collection<IMetric> metrics, Granularity granularity) throws IOException {
        try {
            AstyanaxWriter.getInstance().insertMetrics(metrics, CassandraModel.getPreaggregatedColumnFamily(granularity), isRecordingDelayedMetrics, clock);
        } catch (ConnectionException ex) {
            throw new IOException(ex);
        }
    }

@ Override public void insertMetrics ( Collection < IMetric > metrics , Granularity granularity ) throws IOException { try { AstyanaxWriter . getInstance ( ) . insertMetrics ( metrics , CassandraModel . getPreaggregatedColumnFamily ( granularity ) , isRecordingDelayedMetrics , clock ) ; } catch ( ConnectionException ex ) { throw new IOException ( ex ) ; } }

Inserts a collection of metrics to the correct column family based on
the specified granularity

@param metrics
@param granularity
@throws IOException


protected Set<Locator> getLocators(RollupExecutionContext executionContext,
                                       boolean isReroll,
                                       Granularity delayedMetricsRerollGranularity,
                                       Granularity delayedMetricsStorageGranularity) {
        Set<Locator> locators = new HashSet<Locator>();

        //if delayed metric tracking is enabled, if its re-roll, if slot granularity is no coarser than
        // DELAYED_METRICS_REROLL_GRANULARITY, get delayed locators
        if (RECORD_DELAYED_METRICS &&
                isReroll &&
                !getGranularity().isCoarser(delayedMetricsRerollGranularity)) {

            if (getGranularity().isCoarser(delayedMetricsStorageGranularity)) {

                // For example, if we are re-rolling a 60m slot, and we store delayed metrics at 20m, we need to
                // grab delayed metrics for 3 * 20m slots corresponding to the 60m slot.
                for (SlotKey slotKey: parentSlotKey.getChildrenKeys(delayedMetricsStorageGranularity)) {
                    locators.addAll(getDelayedLocators(executionContext, slotKey));
                }

            } else {
                locators = getDelayedLocators(executionContext,
                        parentSlotKey.extrapolate(delayedMetricsStorageGranularity));
            }

        } else {
            locators = getLocators(executionContext);
        }
        return locators;
    }

This methods gets locators to rollup a slot.

During re-rolls, If the granularity of the slot is finer(or equal) to the configured
DELAYED_METRICS_REROLL_GRANULARITY, we re-roll only the delayed locator's corresponding
to that slot. if not, we re-roll the locators of the entire shard.

@param executionContext
@param isReroll
@param delayedMetricsRerollGranularity
@param delayedMetricsStorageGranularity
@return

This methods gets locators to rollup a slot .


private String getMetricNamesFromES(final String tenant, final String regexMetricName) throws IOException {
        String metricNamesFromElasticsearchQueryString = String.format(queryToFetchMetricNamesFromElasticsearchFormat,
                tenant, regexMetricName, regexMetricName);

        return elasticsearchRestHelper.fetchDocuments(
                ELASTICSEARCH_INDEX_NAME_READ,
                ELASTICSEARCH_DOCUMENT_TYPE,
                tenant,
                metricNamesFromElasticsearchQueryString);
    }

Performs terms aggregation by metric_name which returns doc_count by
metric_name index that matches the given regex.

Sample request body:

{
"size": 0,
"query": {
"bool" : {
"must" : [ {
"term" : {
"tenantId" : "ratanasv"
}
}, {
"regexp" : {
"metric_name" : {
"value" : "<regex>"
}
}
} ]
}
},
"aggs": {
"metric_name_tokens": {
"terms": {
"field" : "metric_name",
"include": "<regex>",
"execution_hint": "map",
"size": 0
}
}
}
}

The two regex expressions used in the query above would be same, one to filter
at query level and another to filter the aggregation buckets.

Execution hint of "map" works by using field values directly instead of ordinals
in order to aggregate data per-bucket

@param tenant
@param regexMetricName
@return

Performs terms aggregation by metric_name which returns doc_count by metric_name index that matches the given regex .


protected String regexToGrabCurrentAndNextLevel(final String query) {

        if (StringUtils.isEmpty(query)) {
            throw new IllegalArgumentException("Query(glob) string cannot be null/empty");
        }

        String queryRegex = getRegex(query);
        int totalQueryTokens = getTotalTokens(query);

        if (totalQueryTokens == 1) {

            // get metric names which matches the given query and have a next level,
            // Ex: For metric foo.bar.baz.qux, if query=*, we should get foo.bar. We are not
            // grabbing 0 level as it will give back bar, baz, qux because of the way data is structured.
            String baseRegex = convertRegexToCaptureUptoNextToken(queryRegex);
            return baseRegex + METRIC_TOKEN_SEPARATOR_REGEX + REGEX_TO_GRAB_SINGLE_TOKEN;

        } else {

            String[] queryRegexParts = queryRegex.split("\\\\.");

            String queryRegexUptoPrevLevel = StringUtils.join(queryRegexParts, METRIC_TOKEN_SEPARATOR_REGEX, 0, totalQueryTokens - 1);
            String baseRegex = convertRegexToCaptureUptoNextToken(queryRegexUptoPrevLevel);

            String queryRegexLastLevel = queryRegexParts[totalQueryTokens - 1];
            String lastTokenRegex = convertRegexToCaptureUptoNextToken(queryRegexLastLevel);

            // Ex: For metric foo.bar.baz.qux.xxx, if query=foo.bar.b*, get foo.bar.baz, foo.bar.baz.qux
            // In this case baseRegex = "foo.bar", lastTokenRegex = "b[^.]*"' and the final
            // regex is foo\.bar\.b[^.]*(\.[^.]*){0,1}
            return baseRegex +
                    METRIC_TOKEN_SEPARATOR_REGEX + lastTokenRegex +
                        "(" +
                    METRIC_TOKEN_SEPARATOR_REGEX + REGEX_TO_GRAB_SINGLE_TOKEN +
                        ")"  + "{0,1}";
        }
    }

Returns regex which could grab metric names from current level to the next level
for a given query.

(Some exceptions when query has only one level due to the nature of underlying data)

for metrics : foo.bar.baz,
foo.bar.baz.qux,

for query=foo.bar.*, the regex which this method returns will capture the following metric token paths.

"foo.bar.baz"       <- current level
"foo.bar.baz.qux"   <- next level

@param query
@return

Returns regex which could grab metric names from current level to the next level for a given query .


public synchronized void start() {
        if (uploaderThread != null) {
            throw new RuntimeException("StorageManager is already started");
        }

        fileUploader = new DoneFileUploader();
        uploaderThread = new Thread(fileUploader, "StorageManager uploader");
        uploaderThread.start();
    }

public
synchronized
void
start
(
)
{
if
(
uploaderThread
!=
)
{
throw
new
RuntimeException
(
"StorageManager is already started"
)
;
}
fileUploader
=
new
DoneFileUploader
(
)
;
uploaderThread
=
new
Thread
(
fileUploader
,
"StorageManager uploader"
)
;
uploaderThread
.
start
(
)
;
}

Start background storage management and uploading tasks.

Start background storage management and uploading tasks .


public synchronized void stop() throws IOException {
        if (uploaderThread == null) {
            throw new RuntimeException("Not running");
        }

        uploaderThread.interrupt();
        uploaderThread = null;
        fileUploader.shutdown();
    }

public
synchronized
void
stop
(
)
throws
IOException
{
if
(
uploaderThread
==
)
{
throw
new
RuntimeException
(
"Not running"
)
;
}
uploaderThread
.
interrupt
(
)
;
uploaderThread
=
;
fileUploader
.
shutdown
(
)
;
}

Stop background storage management.
@throws IOException


public synchronized boolean isLocatorCurrentInBatchLayer(Locator loc) {
        LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString());
        return entry != null && entry.isBatchCurrent();
    }

public synchronized boolean isLocatorCurrentInBatchLayer ( Locator loc ) { LocatorCacheEntry entry = insertedLocators . getIfPresent ( loc . toString ( ) ) ; return entry != null && entry . isBatchCurrent ( ) ; }

Checks if Locator is recently inserted in the batch layer

@param loc
@return


public synchronized boolean isLocatorCurrentInDiscoveryLayer(Locator loc) {
        LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString());
        return entry != null && entry.isDiscoveryCurrent();
    }

public synchronized boolean isLocatorCurrentInDiscoveryLayer ( Locator loc ) { LocatorCacheEntry entry = insertedLocators . getIfPresent ( loc . toString ( ) ) ; return entry != null && entry . isDiscoveryCurrent ( ) ; }

Checks if Locator is recently inserted in the discovery layer

@param loc
@return


public synchronized boolean isLocatorCurrentInTokenDiscoveryLayer(Locator loc) {
        LocatorCacheEntry entry = insertedLocators.getIfPresent(loc.toString());
        return entry != null && entry.isTokenDiscoveryCurrent();
    }

public synchronized boolean isLocatorCurrentInTokenDiscoveryLayer ( Locator loc ) { LocatorCacheEntry entry = insertedLocators . getIfPresent ( loc . toString ( ) ) ; return entry != null && entry . isTokenDiscoveryCurrent ( ) ; }

Checks if Locator is recently inserted in the token discovery layer

@param loc
@return


public synchronized boolean isDelayedLocatorForASlotCurrent(int slot, Locator locator) {
        return insertedDelayedLocators.getIfPresent(getLocatorSlotKey(slot, locator)) != null;
    }

public synchronized boolean isDelayedLocatorForASlotCurrent ( int slot , Locator locator ) { return insertedDelayedLocators . getIfPresent ( getLocatorSlotKey ( slot , locator ) ) != null ; }

Check if the delayed locator is recently inserted for a given slot

@param slot
@param locator
@return


public synchronized void setDelayedLocatorForASlotCurrent(int slot, Locator locator) {
        insertedDelayedLocators.put(getLocatorSlotKey(slot, locator), Boolean.TRUE);
    }

public synchronized void setDelayedLocatorForASlotCurrent ( int slot , Locator locator ) { insertedDelayedLocators . put ( getLocatorSlotKey ( slot , locator ) , Boolean . TRUE ) ; }

Marks the delayed locator as recently inserted for a given slot
@param slot
@param locator


public static Map<Range, Iterable<Range>> mapFinerRanges(Granularity g, Range range) throws GranularityException {

        if(range.getStart() >= range.getStop())
            throw new IllegalArgumentException("start cannot be greater than end. Start: " + range.getStart() + " Stop:" + range.getStop());

        final long snappedStartMillis = g.snapMillis(range.getStart());
        final long snappedStopMillis = g.snapMillis(range.getStop() + g.milliseconds());
        HashMap<Range, Iterable<Range>> rangeMap = new HashMap<Range, Iterable<Range>>();
        long tempStartMillis = snappedStartMillis;
        int numberOfMillis = g.milliseconds();

        while (tempStartMillis <= (snappedStopMillis - numberOfMillis)) {
            Range slotRange = new Range(tempStartMillis, tempStartMillis + numberOfMillis);
            rangeMap.put(slotRange, new IntervalRangeIterator(g.finer(), slotRange.start, slotRange.stop));
            tempStartMillis = tempStartMillis + numberOfMillis;
        }

        return rangeMap;
    }

Returns a mapping of ranges in the coarser granularity to the sub-ranges in finer granularity

Here is an example: Given start/end (s,e), we need to return mapping between ranges in Y that will be mapped to
a single range in X. From the example above, it will be mapping from A to all the sub-ranges in Y that get rolled
to a single point in A
@param g Coarser Granularity
@param range Range to be mapped
@return
@throws GranularityException

Returns a mapping of ranges in the coarser granularity to the sub - ranges in finer granularity


public static Iterable<Range> rangesForInterval(Granularity g, final long from, final long to) {
        if (g == Granularity.FULL) {
            return Arrays.asList(new Range(from, to));
        }

        final long snappedStartMillis = g.snapMillis(from);
        final long snappedStopMillis = g.snapMillis(to + g.milliseconds());

        return new IntervalRangeIterator(g, snappedStartMillis, snappedStopMillis);
    }

public static Iterable < Range > rangesForInterval ( Granularity g , final long from , final long to ) { if ( g == Granularity . FULL ) { return Arrays . asList ( new Range ( from , to ) ) ; } final long snappedStartMillis = g . snapMillis ( from ) ; final long snappedStopMillis = g . snapMillis ( to + g . milliseconds ( ) ) ; return new IntervalRangeIterator ( g , snappedStartMillis , snappedStopMillis ) ; }

return the Ranges for an interval at this granularity
@param from start time
@param to end time
@return Range[]


public void insertFull(Collection<? extends IMetric> metrics, boolean isRecordingDelayedMetrics, Clock clock) throws ConnectionException {
        Timer.Context ctx = Instrumentation.getWriteTimerContext(CassandraModel.CF_METRICS_FULL_NAME);

        try {
            MutationBatch mutationBatch = keyspace.prepareMutationBatch();
            for (IMetric metric: metrics) {
                final Locator locator = metric.getLocator();

                // key = shard
                // col = locator (acct + entity + check + dimension.metric)
                // value = <nothing>
                if (!LocatorCache.getInstance().isLocatorCurrentInBatchLayer(locator)) {
                    if (mutationBatch != null)
                        insertLocator(locator, mutationBatch);
                    LocatorCache.getInstance().setLocatorCurrentInBatchLayer(locator);
                }

                if (isRecordingDelayedMetrics) {
                    //retaining the same conditional logic that was used to insertLocator(locator, batch) above.
                    if (mutationBatch != null) {
                        insertLocatorIfDelayed(metric, mutationBatch, clock);
                    }
                }

                insertMetric(metric, mutationBatch);

                Instrumentation.markFullResMetricWritten();
            }
            // insert it
            try {
                mutationBatch.execute();
            } catch (ConnectionException e) {
                Instrumentation.markWriteError(e);
                log.error("Connection exception during insertFull", e);
                throw e;
            }
        } finally {
            ctx.stop();
        }
    }


public void insertMetrics(Collection<IMetric> metrics, ColumnFamily cf, boolean isRecordingDelayedMetrics, Clock clock) throws ConnectionException {
        Timer.Context ctx = Instrumentation.getWriteTimerContext(cf.getName());
        Multimap<Locator, IMetric> map = asMultimap(metrics);
        MutationBatch batch = keyspace.prepareMutationBatch();
        try {
            for (Locator locator : map.keySet()) {
                ColumnListMutation<Long> mutation = batch.withRow(cf, locator);

                for (IMetric metric : map.get(locator)) {

                    mutation.putColumn(
                                metric.getCollectionTime(),
                                metric.getMetricValue(),
                                (AbstractSerializer) (Serializers.serializerFor(metric.getMetricValue().getClass())),
                                metric.getTtlInSeconds());
                    if (cf.getName().equals(CassandraModel.CF_METRICS_PREAGGREGATED_FULL_NAME)) {
                            Instrumentation.markFullResPreaggregatedMetricWritten();
                    }

                    if (isRecordingDelayedMetrics) {
                        //retaining the same conditional logic that was used to perform insertLocator(locator, batch).
                        insertLocatorIfDelayed(metric, batch, clock);
                    }
                }

                if (!LocatorCache.getInstance().isLocatorCurrentInBatchLayer(locator)) {
                    insertLocator(locator, batch);
                    LocatorCache.getInstance().setLocatorCurrentInBatchLayer(locator);
                }
            }
            try {
                batch.execute();
            } catch (ConnectionException e) {
                Instrumentation.markWriteError(e);
                log.error("Connection exception persisting data", e);
                throw e;
            }
        } finally {
            ctx.stop();
        }
    }

generic IMetric insertion. All other metric insertion methods could use this one.

generic IMetric insertion . All other metric insertion methods could use this one .


protected boolean isDelayed(IMetric metric) {
        long delay = clock.now().getMillis() - metric.getCollectionTime();
        return delay > MAX_AGE_ALLOWED;
    }

protected boolean isDelayed ( IMetric metric ) { long delay = clock . now ( ) . getMillis ( ) - metric . getCollectionTime ( ) ; return delay > MAX_AGE_ALLOWED ; }

Determines if the metric is considered delayed or not

@param metric
@return


protected BoundStatement getBoundStatementForMetricIfDelayed(IMetric metric) {
        Locator locator = metric.getLocator();
        if ( isDelayed(metric) ) {
            int slot = getDelayedSlot(metric);
            if (!LocatorCache.getInstance().isDelayedLocatorForASlotCurrent(slot, locator)) {
                LocatorCache.getInstance().setDelayedLocatorForASlotCurrent(slot, locator);
                return delayedLocatorIO.getBoundStatementForLocator(DELAYED_METRICS_STORAGE_GRANULARITY, slot, locator);
            }
        }
        return null;
    }

protected BoundStatement getBoundStatementForMetricIfDelayed ( IMetric metric ) { Locator locator = metric . getLocator ( ) ; if ( isDelayed ( metric ) ) { int slot = getDelayedSlot ( metric ) ; if ( ! LocatorCache . getInstance ( ) . isDelayedLocatorForASlotCurrent ( slot , locator ) ) { LocatorCache . getInstance ( ) . setDelayedLocatorForASlotCurrent ( slot , locator ) ; return delayedLocatorIO . getBoundStatementForLocator ( DELAYED_METRICS_STORAGE_GRANULARITY , slot , locator ) ; } } return null ; }

Returns a BoundStatement if a metric needs to be inserted to the metrics_delayed_locator
Column Family. Returns null otherwise.

@param metric
@return

Returns a BoundStatement if a metric needs to be inserted to the metrics_delayed_locator Column Family . Returns null otherwise .


public Map<String, String> getMetadataValues(Locator locator) {
        Timer.Context ctx = Instrumentation.getReadTimerContext(CassandraModel.CF_METRICS_METADATA_NAME);
        try {
            final ColumnList<String> results = keyspace.prepareQuery(CassandraModel.CF_METRICS_METADATA)
                    .getKey(locator)
                    .execute().getResult();
            return new HashMap<String, String>(){{
                for (Column<String> result : results) {
                    put(result.getName(), result.getValue(StringMetadataSerializer.get()));
                }
            }};
        } catch (NotFoundException ex) {
            Instrumentation.markNotFound(CassandraModel.CF_METRICS_METADATA_NAME);
            return null;
        } catch (ConnectionException e) {
            log.error("Error reading metadata value", e);
            Instrumentation.markReadError(e);
            throw new RuntimeException(e);
        } finally {
            ctx.stop();
        }
    }

public
Map
<
String
,
String
>
getMetadataValues
(
Locator
locator
)
{
Timer
.
Context
ctx
=
Instrumentation
.
getReadTimerContext
(
CassandraModel
.
CF_METRICS_METADATA_NAME
)
;
try
{
final
ColumnList
<
String
>
results
=
keyspace
.
prepareQuery
(
CassandraModel
.
CF_METRICS_METADATA
)
.
getKey
(
locator
)
.
execute
(
)
.
getResult
(
)
;
return
new
HashMap
<
String
,
String
>
(
)
{
{
for
(
Column
<
String
>
result
:
results
)
{
put
(
result
.
getName
(
)
,
result
.
getValue
(
StringMetadataSerializer
.
get
(
)
)
)
;
}
}
}
;
}
catch
(
NotFoundException
ex
)
{
Instrumentation
.
markNotFound
(
CassandraModel
.
CF_METRICS_METADATA_NAME
)
;
return
;
}
catch
(
ConnectionException
e
)
{
log
.
error
(
"Error reading metadata value"
,
e
)
;
Instrumentation
.
markReadError
(
e
)
;
throw
new
RuntimeException
(
e
)
;
}
finally
{
ctx
.
stop
(
)
;
}
}

Method that returns all metadata for a given locator as a map.

@param locator  locator name
@return Map of metadata for that locator
@throws RuntimeException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Method that returns all metadata for a given locator as a map .


public static <T> AbstractSerializer<T> serializerFor(Class<T> type) {
        if (type == null)
            throw new RuntimeException("serializable type cannot be null",
                    new SerializationException("serializable type cannot be null"));
        else if (type.equals(String.class))
            throw new RuntimeException("We don't serialize strings anymore",
                    new SerializationException("We don't serialize strings anymore"));

        if (type.equals(BasicRollup.class))
            return (AbstractSerializer<T>) basicRollupInstance;
        else if (type.equals(BluefloodTimerRollup.class))
            return (AbstractSerializer<T>)timerRollupInstance;
        else if (type.equals(BluefloodCounterRollup.class))
            return (AbstractSerializer<T>) counterRollupInstance;
        else if (type.equals(BluefloodGaugeRollup.class))
            return (AbstractSerializer<T>)gaugeRollupInstance;
        else if (type.equals(BluefloodSetRollup.class))
            return (AbstractSerializer<T>)setRollupInstance;
        else if (type.equals(SimpleNumber.class))
            return (AbstractSerializer<T>)fullInstance;
        else if (type.equals(Integer.class))
            return (AbstractSerializer<T>)fullInstance;
        else if (type.equals(Long.class))
            return (AbstractSerializer<T>)fullInstance;
        else if (type.equals(Double.class))
            return (AbstractSerializer<T>)fullInstance;
        else if (type.equals(Float.class))
                return (AbstractSerializer<T>)fullInstance;
        else if (type.equals(byte[].class))
            return (AbstractSerializer<T>)fullInstance;
        else if (type.equals(Object.class))
            return (AbstractSerializer<T>)fullInstance;
        else
            return (AbstractSerializer<T>)fullInstance;
    }

public
static
<
T
>
AbstractSerializer
<
T
>
serializerFor
(
Class
<
T
>
type
)
{
if
(
type
==
)
throw
new
RuntimeException
(
"serializable type cannot be null"
,
new
SerializationException
(
"serializable type cannot be null"
)
)
;
else
if
(
type
.
equals
(
String
.
class
)
)
throw
new
RuntimeException
(
"We don't serialize strings anymore"
,
new
SerializationException
(
"We don't serialize strings anymore"
)
)
;
if
(
type
.
equals
(
BasicRollup
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
basicRollupInstance
;
else
if
(
type
.
equals
(
BluefloodTimerRollup
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
timerRollupInstance
;
else
if
(
type
.
equals
(
BluefloodCounterRollup
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
counterRollupInstance
;
else
if
(
type
.
equals
(
BluefloodGaugeRollup
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
gaugeRollupInstance
;
else
if
(
type
.
equals
(
BluefloodSetRollup
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
setRollupInstance
;
else
if
(
type
.
equals
(
SimpleNumber
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
fullInstance
;
else
if
(
type
.
equals
(
Integer
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
fullInstance
;
else
if
(
type
.
equals
(
Long
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
fullInstance
;
else
if
(
type
.
equals
(
Double
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
fullInstance
;
else
if
(
type
.
equals
(
Float
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
fullInstance
;
else
if
(
type
.
equals
(
byte
[
]
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
fullInstance
;
else
if
(
type
.
equals
(
Object
.
class
)
)
return
(
AbstractSerializer
<
T
>
)
fullInstance
;
else
return
(
AbstractSerializer
<
T
>
)
fullInstance
;
}


public boolean isContentTypeValid(HttpHeaders headers) {

        String contentType = headers.get(HttpHeaders.Names.CONTENT_TYPE);

        // if we get no Content-Type or we get application/json, then it's valid
        // any other, it's invalid
        return (Strings.isNullOrEmpty(contentType) ||
                contentType.toLowerCase().contains(MEDIA_TYPE_APPLICATION_JSON));
    }

Checks the Content-Type header to see if clients specify the right
media type
@param headers
@return

Checks the Content - Type header to see if clients specify the right media type


public boolean isAcceptValid(HttpHeaders headers) {
        String accept = headers.get(HttpHeaders.Names.ACCEPT);

        // if we get no Accept (which means */*), or */*,
        // or application/json, then it's valid
        return ( Strings.isNullOrEmpty(accept) ||
                accept.contains(ACCEPT_ALL) ||
                accept.toLowerCase().contains(MEDIA_TYPE_APPLICATION_JSON));
    }

Checks the Accept header to see if clients accept the correct
media type
@param headers
@return


public void insertDiscovery(List<IMetric> batch) throws IOException {
        batchHistogram.update(batch.size());
        if (batch.size() == 0) {
            log.debug("ElasticIO: batch size for insertDiscovery is zero, so skip calling Elasticsearch ingest.");
            return;
        }

        Timer.Context ctx = writeTimer.time();
        try {
            for (Object obj : batch) {
                if (!(obj instanceof IMetric)) {
                    classCastExceptionMeter.mark();
                    continue;
                }
            }

            elasticsearchRestHelper.indexMetrics(batch);
        } finally {
            ctx.stop();
        }
    }


@AssertTrue(message="At least one of the aggregated metrics(gauges, counters, timers, sets) are expected")
    private boolean isValid() {
        boolean isGaugePresent = gauges != null && gauges.length > 0;
        boolean isCounterPresent = counters != null && counters.length > 0;
        boolean isTimerPresent = timers != null && timers.length > 0;
        boolean isSetPresent = sets != null && sets.length > 0;

        return (isGaugePresent || isCounterPresent || isTimerPresent || isSetPresent);
    }

This method is invoked by the validator automatically


private void doCheck() {
        if (!running) return;
        if (fileManager == null) return;

        if (unexpectedErrors > MAX_UNEXPECTED_ERRORS) {
            log.info("Terminating because of errors");
            terminate(false);
            return;
        }

        Timer.Context waitTimerContext = waitingTimer.time();
        // Possible infinite thread sleep? This will make sure we fire downloading only when are the files are consumed/merged
        while (downloadDir.listFiles().length != 0) {
            log.debug("Waiting for files in download directory to clear up. Sleeping for 1 min. If you see this persistently, it means the downloaded files are not getting merged properly/timely");
            try { Thread.sleep(60000); } catch (Exception ex) {}
        }
        waitTimerContext.stop();
        if (downloadLock.tryLock()) {
            try {
                if (fileManager.hasNewFiles()) {
                    fileManager.downloadNewFiles(downloadDir);
                }
            } catch (Throwable unexpected) {
                unexpectedErrors += 1;
                log.error("UNEXPECTED; WILL TRY TO RECOVER");
                log.error(unexpected.getMessage(), unexpected);
                // sleep for a minute?
                if (Thread.interrupted()) {
                    try {
                        thread.sleep(60000);
                    } catch (Exception ex) {
                        log.error(ex.getMessage(), ex);
                    }
                }
            } finally {
                downloadLock.unlock();
            }
        } else {
            log.debug("Download in progress");
        }
    }


public Extractor getNewInstance() {
    Extractor extractor = new BasicExtractor(config);
    if (config.shouldCachedDownload()) {
      extractor = new CachedExtractor(extractor, config);
    }
    return extractor;
  }

public Extractor getNewInstance ( ) { Extractor extractor = new BasicExtractor ( config ) ; if ( config . shouldCachedDownload ( ) ) { extractor = new CachedExtractor ( extractor , config ) ; } return extractor ; }

Returns an Extractor instance appropriate based on the given configuration.

Returns an Extractor instance appropriate based on the given configuration .


private static boolean getOSMatches(final String osNamePrefix, final String osVersionPrefix) {
        return isOSMatch(OS_NAME, OS_VERSION, osNamePrefix, osVersionPrefix);
    }

private static boolean getOSMatches ( final String osNamePrefix , final String osVersionPrefix ) { return isOSMatch ( OS_NAME , OS_VERSION , osNamePrefix , osVersionPrefix ) ; }

Decides if the operating system matches.

@param osNamePrefix the prefix for the os name
@param osVersionPrefix the prefix for the version
@return true if matches, or false if not or can't determine

Decides if the operating system matches .


public void start() throws ErlangVersionException, DownloadException, ExtractionException, StartupException {
    if (rabbitMqProcess != null) {
      throw new IllegalStateException("Start shouldn't be called more than once unless stop() has been called before.");
    }

    check();
    download();
    extract();
    run();
  }

Starts the RabbitMQ server process and blocks the current thread until the initialization is completed.

@throws ErlangVersionException when there's an issue with the system's Erlang version
@throws DownloadException    when there's an issue downloading the appropriate artifact
@throws ExtractionException  when there's an issue extracting the files from the downloaded artifact
@throws StartupException     when there's an issue starting the RabbitMQ server

Starts the RabbitMQ server process and blocks the current thread until the initialization is completed .


public void stop() throws ShutDownException {
    if (rabbitMqProcess == null) {
      throw new IllegalStateException("Stop shouldn't be called unless 'start()' was successful.");
    }
    new ShutdownHelper(config, rabbitMqProcess).run();
    rabbitMqProcess = null;
  }

Submits the command to stop RabbitMQ and blocks the current thread until the shutdown is completed.

@throws ShutDownException if there's an issue shutting down the RabbitMQ server

Submits the command to stop RabbitMQ and blocks the current thread until the shutdown is completed .


public static PnSignalingParams defaultInstance() {
        MediaConstraints pcConstraints    = PnSignalingParams.defaultPcConstraints();
        MediaConstraints videoConstraints = PnSignalingParams.defaultVideoConstraints();
        MediaConstraints audioConstraints = PnSignalingParams.defaultAudioConstraints();
        List<PeerConnection.IceServer> iceServers = PnSignalingParams.defaultIceServers();
        return new PnSignalingParams(iceServers, pcConstraints, videoConstraints, audioConstraints);
    }

public static PnSignalingParams defaultInstance ( ) { MediaConstraints pcConstraints = PnSignalingParams . defaultPcConstraints ( ) ; MediaConstraints videoConstraints = PnSignalingParams . defaultVideoConstraints ( ) ; MediaConstraints audioConstraints = PnSignalingParams . defaultAudioConstraints ( ) ; List < PeerConnection . IceServer > iceServers = PnSignalingParams . defaultIceServers ( ) ; return new PnSignalingParams ( iceServers , pcConstraints , videoConstraints , audioConstraints ) ; }

The default parameters for media constraints. Might have to tweak in future.
@return default parameters

The default parameters for media constraints . Might have to tweak in future .


public void addIceServers(List<PeerConnection.IceServer> iceServers){
        if(this.iceServers!=null) {
            iceServers.addAll(this.iceServers);
        }
        this.iceServers = iceServers;
    }

public void addIceServers ( List < PeerConnection . IceServer > iceServers ) { if ( this . iceServers != null ) { iceServers . addAll ( this . iceServers ) ; } this . iceServers = iceServers ; }

Append default servers to the end of given list and set as iceServers instance variable
@param iceServers List of iceServers


public void addIceServers(PeerConnection.IceServer iceServers){
        if (this.iceServers == null){
            this.iceServers = new ArrayList<PeerConnection.IceServer>();
        }
        this.iceServers.add(0, iceServers);
    }

public void addIceServers ( PeerConnection . IceServer iceServers ) { if ( this . iceServers == null ) { this . iceServers = new ArrayList < PeerConnection . IceServer > ( ) ; } this . iceServers . add ( 0 , iceServers ) ; }

Instantiate iceServers if they are not already, and add Ice Server to beginning of list.
@param iceServers Ice Server to add

Instantiate iceServers if they are not already and add Ice Server to beginning of list .


public void transmit(String userId, JSONObject message){
        JSONObject usrMsgJson = new JSONObject();
        try {
            usrMsgJson.put(PnRTCMessage.JSON_USERMSG, message);
            this.pcClient.transmitMessage(userId, usrMsgJson);
        } catch (JSONException e){
            e.printStackTrace();
        }
    }

public void transmit ( String userId , JSONObject message ) { JSONObject usrMsgJson = new JSONObject ( ) ; try { usrMsgJson . put ( PnRTCMessage . JSON_USERMSG , message ) ; this . pcClient . transmitMessage ( userId , usrMsgJson ) ; } catch ( JSONException e ) { e . printStackTrace ( ) ; } }

Send a custom JSONObject user message to a single peer.
@param userId user to send a message to
@param message the JSON message to pass to a peer.

Send a custom JSONObject user message to a single peer .


public void transmitAll(JSONObject message){
        List<PnPeer> peerList = this.pcClient.getPeers();
        for(PnPeer p : peerList){
            transmit(p.getId(), message);
        }
    }

public void transmitAll ( JSONObject message ) { List < PnPeer > peerList = this . pcClient . getPeers ( ) ; for ( PnPeer p : peerList ) { transmit ( p . getId ( ) , message ) ; } }

Send a custom JSONObject user message to all peers.
@param message the JSON message to pass to all peers.

Send a custom JSONObject user message to all peers .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public List<WeitereAdresse> getWeitereAdresse() {
        if (weitereAdresse == null) {
            weitereAdresse = new ArrayList<WeitereAdresse>();
        }
        return this.weitereAdresse;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:50:55+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
List
<
WeitereAdresse
>
getWeitereAdresse
(
)
{
if
(
weitereAdresse
==
)
{
weitereAdresse
=
new
ArrayList
<
WeitereAdresse
>
(
)
;
}
return
this
.
weitereAdresse
;
}

Gets the value of the weitereAdresse property.

This accessor method returns a reference to the live list,
not a snapshot. Therefore any modification you make to the
returned list will be present inside the JAXB object.
This is why there is not a set method for the weitereAdresse property.

For example, to add a new item, do as follows:

getWeitereAdresse().add(newItem);

Objects of the following type(s) are allowed in the list
{@link WeitereAdresse }

Gets the value of the weitereAdresse property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public List<UserDefinedSimplefield> getUserDefinedSimplefield() {
        if (userDefinedSimplefield == null) {
            userDefinedSimplefield = new ArrayList<UserDefinedSimplefield>();
        }
        return this.userDefinedSimplefield;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:50:55+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
List
<
UserDefinedSimplefield
>
getUserDefinedSimplefield
(
)
{
if
(
userDefinedSimplefield
==
)
{
userDefinedSimplefield
=
new
ArrayList
<
UserDefinedSimplefield
>
(
)
;
}
return
this
.
userDefinedSimplefield
;
}

Gets the value of the userDefinedSimplefield property.

This accessor method returns a reference to the live list,
not a snapshot. Therefore any modification you make to the
returned list will be present inside the JAXB object.
This is why there is not a set method for the userDefinedSimplefield property.

For example, to add a new item, do as follows:

getUserDefinedSimplefield().add(newItem);

Objects of the following type(s) are allowed in the list
{@link UserDefinedSimplefield }

Gets the value of the userDefinedSimplefield property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:50:55+02:00", comments = "JAXB RI v2.2.11")
    public List<UserDefinedAnyfield> getUserDefinedAnyfield() {
        if (userDefinedAnyfield == null) {
            userDefinedAnyfield = new ArrayList<UserDefinedAnyfield>();
        }
        return this.userDefinedAnyfield;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:50:55+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
List
<
UserDefinedAnyfield
>
getUserDefinedAnyfield
(
)
{
if
(
userDefinedAnyfield
==
)
{
userDefinedAnyfield
=
new
ArrayList
<
UserDefinedAnyfield
>
(
)
;
}
return
this
.
userDefinedAnyfield
;
}

Gets the value of the userDefinedAnyfield property.

This accessor method returns a reference to the live list,
not a snapshot. Therefore any modification you make to the
returned list will be present inside the JAXB object.
This is why there is not a set method for the userDefinedAnyfield property.

For example, to add a new item, do as follows:

getUserDefinedAnyfield().add(newItem);

Objects of the following type(s) are allowed in the list
{@link UserDefinedAnyfield }

Gets the value of the userDefinedAnyfield property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:52:47+02:00", comments = "JAXB RI v2.2.11")
    public void setApiSuchfelder(JAXBElement<ApiSuchfelderTyp> value) {
        this.apiSuchfelder = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:52:47+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setApiSuchfelder
(
JAXBElement
<
ApiSuchfelderTyp
>
value
)
{
this
.
apiSuchfelder
=
value
;
}

Sets the value of the apiSuchfelder property.

@param value
allowed object is
{@link JAXBElement }{@code <}{@link ApiSuchfelderTyp }{@code >}

Sets the value of the apiSuchfelder property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:52:47+02:00", comments = "JAXB RI v2.2.11")
    public List<MultimediaAnhangTyp> getMultimediaAnhang() {
        if (multimediaAnhang == null) {
            multimediaAnhang = new ArrayList<MultimediaAnhangTyp>();
        }
        return this.multimediaAnhang;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:52:47+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
List
<
MultimediaAnhangTyp
>
getMultimediaAnhang
(
)
{
if
(
multimediaAnhang
==
)
{
multimediaAnhang
=
new
ArrayList
<
MultimediaAnhangTyp
>
(
)
;
}
return
this
.
multimediaAnhang
;
}

Gets the value of the multimediaAnhang property.

This accessor method returns a reference to the live list,
not a snapshot. Therefore any modification you make to the
returned list will be present inside the JAXB object.
This is why there is not a set method for the multimediaAnhang property.

For example, to add a new item, do as follows:

getMultimediaAnhang().add(newItem);

Objects of the following type(s) are allowed in the list
{@link MultimediaAnhangTyp }

Gets the value of the multimediaAnhang property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:52:47+02:00", comments = "JAXB RI v2.2.11")
    public StatusTyp getStatusVBM() {
        if (statusVBM == null) {
            return StatusTyp.AKTIV;
        } else {
            return statusVBM;
        }
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:52:47+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
StatusTyp
getStatusVBM
(
)
{
if
(
statusVBM
==
)
{
return
StatusTyp
.
AKTIV
;
}
else
{
return
statusVBM
;
}
}

Gets the value of the statusVBM property.

@return
possible object is
{@link StatusTyp }

Gets the value of the statusVBM property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:52:47+02:00", comments = "JAXB RI v2.2.11")
    public StatusTyp getStatusIS24() {
        if (statusIS24 == null) {
            return StatusTyp.AKTIV;
        } else {
            return statusIS24;
        }
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:52:47+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
StatusTyp
getStatusIS24
(
)
{
if
(
statusIS24
==
)
{
return
StatusTyp
.
AKTIV
;
}
else
{
return
statusIS24
;
}
}

Gets the value of the statusIS24 property.

@return
possible object is
{@link StatusTyp }

Gets the value of the statusIS24 property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:52:47+02:00", comments = "JAXB RI v2.2.11")
    public StatusTyp getStatusHP() {
        if (statusHP == null) {
            return StatusTyp.AKTIV;
        } else {
            return statusHP;
        }
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:52:47+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
StatusTyp
getStatusHP
(
)
{
if
(
statusHP
==
)
{
return
StatusTyp
.
AKTIV
;
}
else
{
return
statusHP
;
}
}

Gets the value of the statusHP property.

@return
possible object is
{@link StatusTyp }

Gets the value of the statusHP property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:52:47+02:00", comments = "JAXB RI v2.2.11")
    public AktionsTyp getImportmodus() {
        if (importmodus == null) {
            return AktionsTyp.IMPORTIEREN;
        } else {
            return importmodus;
        }
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:52:47+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
AktionsTyp
getImportmodus
(
)
{
if
(
importmodus
==
)
{
return
AktionsTyp
.
IMPORTIEREN
;
}
else
{
return
importmodus
;
}
}

Gets the value of the importmodus property.

@return
possible object is
{@link AktionsTyp }

Gets the value of the importmodus property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:52:47+02:00", comments = "JAXB RI v2.2.11")
    public Boolean getAdressdruck() {
        if (adressdruck == null) {
            return false;
        } else {
            return adressdruck;
        }
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:52:47+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
Boolean
getAdressdruck
(
)
{
if
(
adressdruck
==
)
{
return
false
;
}
else
{
return
adressdruck
;
}
}

Gets the value of the adressdruck property.

@return
possible object is
{@link Boolean }

Gets the value of the adressdruck property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:52:47+02:00", comments = "JAXB RI v2.2.11")
    public WaehrungTyp getWaehrung() {
        if (waehrung == null) {
            return WaehrungTyp.EUR;
        } else {
            return waehrung;
        }
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:52:47+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
WaehrungTyp
getWaehrung
(
)
{
if
(
waehrung
==
)
{
return
WaehrungTyp
.
EUR
;
}
else
{
return
waehrung
;
}
}

Gets the value of the waehrung property.

@return
possible object is
{@link WaehrungTyp }

Gets the value of the waehrung property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:52:47+02:00", comments = "JAXB RI v2.2.11")
    public BodenbelagTyp getBodenbelag() {
        if (bodenbelag == null) {
            return BodenbelagTyp.KEINE_ANGABE;
        } else {
            return bodenbelag;
        }
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:52:47+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
BodenbelagTyp
getBodenbelag
(
)
{
if
(
bodenbelag
==
)
{
return
BodenbelagTyp
.
KEINE_ANGABE
;
}
else
{
return
bodenbelag
;
}
}

Gets the value of the bodenbelag property.

@return
possible object is
{@link BodenbelagTyp }

Gets the value of the bodenbelag property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setRegion(java.lang.String value) {
        this.region = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setRegion
(
java
.
lang
.
String
value
)
{
this
.
region
=
value
;
}

Sets the value of the region property.

@param value
allowed object is
{@link java.lang.String }


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setArea(java.lang.String value) {
        this.area = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setArea
(
java
.
lang
.
String
value
)
{
this
.
area
=
value
;
}

Sets the value of the area property.

@param value
allowed object is
{@link java.lang.String }


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setAddress(java.lang.String value) {
        this.address = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setAddress
(
java
.
lang
.
String
value
)
{
this
.
address
=
value
;
}

Sets the value of the address property.

@param value
allowed object is
{@link java.lang.String }

Sets the value of the address property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setDescription(java.lang.String value) {
        this.description = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setDescription
(
java
.
lang
.
String
value
)
{
this
.
description
=
value
;
}

Sets the value of the description property.

@param value
allowed object is
{@link java.lang.String }

Sets the value of the description property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setRentCollectionPeriod(OverseasRentalAdType.RentPeriod value) {
        this.rentCollectionPeriod = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setRentCollectionPeriod
(
OverseasRentalAdType
.
RentPeriod
value
)
{
this
.
rentCollectionPeriod
=
value
;
}

Sets the value of the rentCollectionPeriod property.

@param value
allowed object is
{@link OverseasRentalAdType.RentPeriod }

Sets the value of the rentCollectionPeriod property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setFurnished(OverseasRentalAdType.Furnished value) {
        this.furnished = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setFurnished
(
OverseasRentalAdType
.
Furnished
value
)
{
this
.
furnished
=
value
;
}

Sets the value of the furnished property.

@param value
allowed object is
{@link OverseasRentalAdType.Furnished }

Sets the value of the furnished property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setPhone1(java.lang.String value) {
        this.phone1 = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setPhone1
(
java
.
lang
.
String
value
)
{
this
.
phone1
=
value
;
}

Sets the value of the phone1 property.

@param value
allowed object is
{@link java.lang.String }


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setPhone2(java.lang.String value) {
        this.phone2 = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setPhone2
(
java
.
lang
.
String
value
)
{
this
.
phone2
=
value
;
}

Sets the value of the phone2 property.

@param value
allowed object is
{@link java.lang.String }


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setContactName(java.lang.String value) {
        this.contactName = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setContactName
(
java
.
lang
.
String
value
)
{
this
.
contactName
=
value
;
}

Sets the value of the contactName property.

@param value
allowed object is
{@link java.lang.String }

Sets the value of the contactName property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setPhoneInfo(java.lang.String value) {
        this.phoneInfo = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setPhoneInfo
(
java
.
lang
.
String
value
)
{
this
.
phoneInfo
=
value
;
}

Sets the value of the phoneInfo property.

@param value
allowed object is
{@link java.lang.String }

Sets the value of the phoneInfo property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setMainEmail(java.lang.String value) {
        this.mainEmail = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setMainEmail
(
java
.
lang
.
String
value
)
{
this
.
mainEmail
=
value
;
}

Sets the value of the mainEmail property.

@param value
allowed object is
{@link java.lang.String }

Sets the value of the mainEmail property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setCcEmail(java.lang.String value) {
        this.ccEmail = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setCcEmail
(
java
.
lang
.
String
value
)
{
this
.
ccEmail
=
value
;
}

Sets the value of the ccEmail property.

@param value
allowed object is
{@link java.lang.String }

Sets the value of the ccEmail property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setExternalId(java.lang.String value) {
        this.externalId = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setExternalId
(
java
.
lang
.
String
value
)
{
this
.
externalId
=
value
;
}

Sets the value of the externalId property.

@param value
allowed object is
{@link java.lang.String }

Sets the value of the externalId property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:41:42+02:00", comments = "JAXB RI v2.2.11")
    public void setAgentId(java.lang.String value) {
        this.agentId = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:41:42+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setAgentId
(
java
.
lang
.
String
value
)
{
this
.
agentId
=
value
;
}

Sets the value of the agentId property.

@param value
allowed object is
{@link java.lang.String }

Sets the value of the agentId property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public void setEpart(Energiepass.Epart value) {
        this.epart = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:54:50+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setEpart
(
Energiepass
.
Epart
value
)
{
this
.
epart
=
value
;
}

Sets the value of the epart property.

@param value
allowed object is
{@link Energiepass.Epart }


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public void setJahrgang(Energiepass.Jahrgang value) {
        this.jahrgang = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:54:50+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setJahrgang
(
Energiepass
.
Jahrgang
value
)
{
this
.
jahrgang
=
value
;
}

Sets the value of the jahrgang property.

@param value
allowed object is
{@link Energiepass.Jahrgang }

Sets the value of the jahrgang property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public void setGebaeudeart(Energiepass.Gebaeudeart value) {
        this.gebaeudeart = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:54:50+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setGebaeudeart
(
Energiepass
.
Gebaeudeart
value
)
{
this
.
gebaeudeart
=
value
;
}

Sets the value of the gebaeudeart property.

@param value
allowed object is
{@link Energiepass.Gebaeudeart }

Sets the value of the gebaeudeart property .


@Generated(value = "com.sun.tools.xjc.Driver", date = "2018-10-12T02:54:50+02:00", comments = "JAXB RI v2.2.11")
    public void setBueroTyp(BueroPraxen.BueroTyp value) {
        this.bueroTyp = value;
    }

@
Generated
(
value
=
"com.sun.tools.xjc.Driver"
,
date
=
"2018-10-12T02:54:50+02:00"
,
comments
=
"JAXB RI v2.2.11"
)
public
void
setBueroTyp
(
BueroPraxen
.
BueroTyp
value
)
{
this
.
bueroTyp
=
value
;
}

Sets the value of the bueroTyp property.

@param value
allowed object is
{@link BueroPraxen.BueroTyp }

Sets the value of the bueroTyp property .