id int32 0 165k | repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1 value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 |
|---|---|---|---|---|---|---|---|---|---|---|---|
25,100 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/logging/LogManager.java | LogManager.d | public static void d(String tag, String message, Object... args) {
sLogger.d(tag, message, args);
} | java | public static void d(String tag, String message, Object... args) {
sLogger.d(tag, message, args);
} | [
"public",
"static",
"void",
"d",
"(",
"String",
"tag",
",",
"String",
"message",
",",
"Object",
"...",
"args",
")",
"{",
"sLogger",
".",
"d",
"(",
"tag",
",",
"message",
",",
"args",
")",
";",
"}"
] | Send a debug log message to the logger.
@param tag Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
@param message The message you would like logged. This message may contain string formatting
which will be replaced with values from args.
@param args Arguments for string formatting. | [
"Send",
"a",
"debug",
"log",
"message",
"to",
"the",
"logger",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/logging/LogManager.java#L111-L113 |
25,101 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/logging/LogManager.java | LogManager.i | public static void i(String tag, String message, Object... args) {
sLogger.i(tag, message, args);
} | java | public static void i(String tag, String message, Object... args) {
sLogger.i(tag, message, args);
} | [
"public",
"static",
"void",
"i",
"(",
"String",
"tag",
",",
"String",
"message",
",",
"Object",
"...",
"args",
")",
"{",
"sLogger",
".",
"i",
"(",
"tag",
",",
"message",
",",
"args",
")",
";",
"}"
] | Send a info log message to the logger.
@param tag Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
@param message The message you would like logged. This message may contain string formatting
which will be replaced with values from args.
@param args Arguments for string formatting. | [
"Send",
"a",
"info",
"log",
"message",
"to",
"the",
"logger",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/logging/LogManager.java#L138-L140 |
25,102 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/logging/LogManager.java | LogManager.w | public static void w(String tag, String message, Object... args) {
sLogger.w(tag, message, args);
} | java | public static void w(String tag, String message, Object... args) {
sLogger.w(tag, message, args);
} | [
"public",
"static",
"void",
"w",
"(",
"String",
"tag",
",",
"String",
"message",
",",
"Object",
"...",
"args",
")",
"{",
"sLogger",
".",
"w",
"(",
"tag",
",",
"message",
",",
"args",
")",
";",
"}"
] | Send a warning log message to the logger.
@param tag Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
@param message The message you would like logged. This message may contain string formatting
which will be replaced with values from args.
@param args Arguments for string formatting. | [
"Send",
"a",
"warning",
"log",
"message",
"to",
"the",
"logger",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/logging/LogManager.java#L165-L167 |
25,103 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/logging/LogManager.java | LogManager.e | public static void e(String tag, String message, Object... args) {
sLogger.e(tag, message, args);
} | java | public static void e(String tag, String message, Object... args) {
sLogger.e(tag, message, args);
} | [
"public",
"static",
"void",
"e",
"(",
"String",
"tag",
",",
"String",
"message",
",",
"Object",
"...",
"args",
")",
"{",
"sLogger",
".",
"e",
"(",
"tag",
",",
"message",
",",
"args",
")",
";",
"}"
] | Send a error log message to the logger.
@param tag Used to identify the source of a log message. It usually identifies
the class or activity where the log call occurs.
@param message The message you would like logged. This message may contain string formatting
which will be replaced with values from args.
@param args Arguments for string formatting. | [
"Send",
"a",
"error",
"log",
"message",
"to",
"the",
"logger",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/logging/LogManager.java#L192-L194 |
25,104 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/service/BeaconService.java | BeaconService.onBind | @Override
public IBinder onBind(Intent intent) {
LogManager.i(TAG, "binding");
return mMessenger.getBinder();
} | java | @Override
public IBinder onBind(Intent intent) {
LogManager.i(TAG, "binding");
return mMessenger.getBinder();
} | [
"@",
"Override",
"public",
"IBinder",
"onBind",
"(",
"Intent",
"intent",
")",
"{",
"LogManager",
".",
"i",
"(",
"TAG",
",",
"\"binding\"",
")",
";",
"return",
"mMessenger",
".",
"getBinder",
"(",
")",
";",
"}"
] | When binding to the service, we return an interface to our messenger
for sending messages to the service. | [
"When",
"binding",
"to",
"the",
"service",
"we",
"return",
"an",
"interface",
"to",
"our",
"messenger",
"for",
"sending",
"messages",
"to",
"the",
"service",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/BeaconService.java#L307-L311 |
25,105 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/service/BeaconService.java | BeaconService.onUnbind | @Override
public boolean onUnbind(Intent intent) {
LogManager.i(TAG, "unbinding so destroying self");
this.stopForeground(true);
this.stopSelf();
return false;
} | java | @Override
public boolean onUnbind(Intent intent) {
LogManager.i(TAG, "unbinding so destroying self");
this.stopForeground(true);
this.stopSelf();
return false;
} | [
"@",
"Override",
"public",
"boolean",
"onUnbind",
"(",
"Intent",
"intent",
")",
"{",
"LogManager",
".",
"i",
"(",
"TAG",
",",
"\"unbinding so destroying self\"",
")",
";",
"this",
".",
"stopForeground",
"(",
"true",
")",
";",
"this",
".",
"stopSelf",
"(",
")",
";",
"return",
"false",
";",
"}"
] | called when the last bound client calls unbind | [
"called",
"when",
"the",
"last",
"bound",
"client",
"calls",
"unbind"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/BeaconService.java#L314-L320 |
25,106 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/service/BeaconService.java | BeaconService.startRangingBeaconsInRegion | @MainThread
public void startRangingBeaconsInRegion(Region region, Callback callback) {
synchronized (mScanHelper.getRangedRegionState()) {
if (mScanHelper.getRangedRegionState().containsKey(region)) {
LogManager.i(TAG, "Already ranging that region -- will replace existing region.");
mScanHelper.getRangedRegionState().remove(region); // need to remove it, otherwise the old object will be retained because they are .equal //FIXME That is not true
}
mScanHelper.getRangedRegionState().put(region, new RangeState(callback));
LogManager.d(TAG, "Currently ranging %s regions.", mScanHelper.getRangedRegionState().size());
}
if (mScanHelper.getCycledScanner() != null) {
mScanHelper.getCycledScanner().start();
}
} | java | @MainThread
public void startRangingBeaconsInRegion(Region region, Callback callback) {
synchronized (mScanHelper.getRangedRegionState()) {
if (mScanHelper.getRangedRegionState().containsKey(region)) {
LogManager.i(TAG, "Already ranging that region -- will replace existing region.");
mScanHelper.getRangedRegionState().remove(region); // need to remove it, otherwise the old object will be retained because they are .equal //FIXME That is not true
}
mScanHelper.getRangedRegionState().put(region, new RangeState(callback));
LogManager.d(TAG, "Currently ranging %s regions.", mScanHelper.getRangedRegionState().size());
}
if (mScanHelper.getCycledScanner() != null) {
mScanHelper.getCycledScanner().start();
}
} | [
"@",
"MainThread",
"public",
"void",
"startRangingBeaconsInRegion",
"(",
"Region",
"region",
",",
"Callback",
"callback",
")",
"{",
"synchronized",
"(",
"mScanHelper",
".",
"getRangedRegionState",
"(",
")",
")",
"{",
"if",
"(",
"mScanHelper",
".",
"getRangedRegionState",
"(",
")",
".",
"containsKey",
"(",
"region",
")",
")",
"{",
"LogManager",
".",
"i",
"(",
"TAG",
",",
"\"Already ranging that region -- will replace existing region.\"",
")",
";",
"mScanHelper",
".",
"getRangedRegionState",
"(",
")",
".",
"remove",
"(",
"region",
")",
";",
"// need to remove it, otherwise the old object will be retained because they are .equal //FIXME That is not true",
"}",
"mScanHelper",
".",
"getRangedRegionState",
"(",
")",
".",
"put",
"(",
"region",
",",
"new",
"RangeState",
"(",
"callback",
")",
")",
";",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Currently ranging %s regions.\"",
",",
"mScanHelper",
".",
"getRangedRegionState",
"(",
")",
".",
"size",
"(",
")",
")",
";",
"}",
"if",
"(",
"mScanHelper",
".",
"getCycledScanner",
"(",
")",
"!=",
"null",
")",
"{",
"mScanHelper",
".",
"getCycledScanner",
"(",
")",
".",
"start",
"(",
")",
";",
"}",
"}"
] | methods for clients | [
"methods",
"for",
"clients"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/BeaconService.java#L368-L381 |
25,107 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/Identifier.java | Identifier.parse | public static Identifier parse(String stringValue, int desiredByteLength) {
if (stringValue == null) {
throw new NullPointerException("Identifiers cannot be constructed from null pointers but \"stringValue\" is null.");
}
if (HEX_PATTERN.matcher(stringValue).matches()) {
return parseHex(stringValue.substring(2), desiredByteLength);
}
if (UUID_PATTERN.matcher(stringValue).matches()) {
return parseHex(stringValue.replace("-", ""), desiredByteLength);
}
if (DECIMAL_PATTERN.matcher(stringValue).matches()) {
int value = -1;
try {
value = Integer.valueOf(stringValue);
}
catch (Throwable t) {
throw new IllegalArgumentException("Unable to parse Identifier in decimal format.", t);
}
if (desiredByteLength <= 0 || desiredByteLength == 2) {
return fromInt(value);
}
else {
return fromLong(value, desiredByteLength);
}
}
if (HEX_PATTERN_NO_PREFIX.matcher(stringValue).matches()) {
return parseHex(stringValue, desiredByteLength);
}
throw new IllegalArgumentException("Unable to parse Identifier.");
} | java | public static Identifier parse(String stringValue, int desiredByteLength) {
if (stringValue == null) {
throw new NullPointerException("Identifiers cannot be constructed from null pointers but \"stringValue\" is null.");
}
if (HEX_PATTERN.matcher(stringValue).matches()) {
return parseHex(stringValue.substring(2), desiredByteLength);
}
if (UUID_PATTERN.matcher(stringValue).matches()) {
return parseHex(stringValue.replace("-", ""), desiredByteLength);
}
if (DECIMAL_PATTERN.matcher(stringValue).matches()) {
int value = -1;
try {
value = Integer.valueOf(stringValue);
}
catch (Throwable t) {
throw new IllegalArgumentException("Unable to parse Identifier in decimal format.", t);
}
if (desiredByteLength <= 0 || desiredByteLength == 2) {
return fromInt(value);
}
else {
return fromLong(value, desiredByteLength);
}
}
if (HEX_PATTERN_NO_PREFIX.matcher(stringValue).matches()) {
return parseHex(stringValue, desiredByteLength);
}
throw new IllegalArgumentException("Unable to parse Identifier.");
} | [
"public",
"static",
"Identifier",
"parse",
"(",
"String",
"stringValue",
",",
"int",
"desiredByteLength",
")",
"{",
"if",
"(",
"stringValue",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"Identifiers cannot be constructed from null pointers but \\\"stringValue\\\" is null.\"",
")",
";",
"}",
"if",
"(",
"HEX_PATTERN",
".",
"matcher",
"(",
"stringValue",
")",
".",
"matches",
"(",
")",
")",
"{",
"return",
"parseHex",
"(",
"stringValue",
".",
"substring",
"(",
"2",
")",
",",
"desiredByteLength",
")",
";",
"}",
"if",
"(",
"UUID_PATTERN",
".",
"matcher",
"(",
"stringValue",
")",
".",
"matches",
"(",
")",
")",
"{",
"return",
"parseHex",
"(",
"stringValue",
".",
"replace",
"(",
"\"-\"",
",",
"\"\"",
")",
",",
"desiredByteLength",
")",
";",
"}",
"if",
"(",
"DECIMAL_PATTERN",
".",
"matcher",
"(",
"stringValue",
")",
".",
"matches",
"(",
")",
")",
"{",
"int",
"value",
"=",
"-",
"1",
";",
"try",
"{",
"value",
"=",
"Integer",
".",
"valueOf",
"(",
"stringValue",
")",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unable to parse Identifier in decimal format.\"",
",",
"t",
")",
";",
"}",
"if",
"(",
"desiredByteLength",
"<=",
"0",
"||",
"desiredByteLength",
"==",
"2",
")",
"{",
"return",
"fromInt",
"(",
"value",
")",
";",
"}",
"else",
"{",
"return",
"fromLong",
"(",
"value",
",",
"desiredByteLength",
")",
";",
"}",
"}",
"if",
"(",
"HEX_PATTERN_NO_PREFIX",
".",
"matcher",
"(",
"stringValue",
")",
".",
"matches",
"(",
")",
")",
"{",
"return",
"parseHex",
"(",
"stringValue",
",",
"desiredByteLength",
")",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Unable to parse Identifier.\"",
")",
";",
"}"
] | Variant of the parse method that allows specifying the byte length of the identifier.
@see #parse(String)
@param stringValue
@param desiredByteLength
@return | [
"Variant",
"of",
"the",
"parse",
"method",
"that",
"allows",
"specifying",
"the",
"byte",
"length",
"of",
"the",
"identifier",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/Identifier.java#L66-L100 |
25,108 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/Identifier.java | Identifier.fromLong | public static Identifier fromLong(long longValue, int desiredByteLength) {
if (desiredByteLength < 0) {
throw new IllegalArgumentException("Identifier length must be > 0.");
}
byte[] newValue = new byte[desiredByteLength];
for (int i = desiredByteLength-1; i >= 0; i--) {
newValue[i] = (byte) (longValue & 0xff);
longValue = longValue >> 8;
}
return new Identifier(newValue);
} | java | public static Identifier fromLong(long longValue, int desiredByteLength) {
if (desiredByteLength < 0) {
throw new IllegalArgumentException("Identifier length must be > 0.");
}
byte[] newValue = new byte[desiredByteLength];
for (int i = desiredByteLength-1; i >= 0; i--) {
newValue[i] = (byte) (longValue & 0xff);
longValue = longValue >> 8;
}
return new Identifier(newValue);
} | [
"public",
"static",
"Identifier",
"fromLong",
"(",
"long",
"longValue",
",",
"int",
"desiredByteLength",
")",
"{",
"if",
"(",
"desiredByteLength",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Identifier length must be > 0.\"",
")",
";",
"}",
"byte",
"[",
"]",
"newValue",
"=",
"new",
"byte",
"[",
"desiredByteLength",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"desiredByteLength",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"newValue",
"[",
"i",
"]",
"=",
"(",
"byte",
")",
"(",
"longValue",
"&",
"0xff",
")",
";",
"longValue",
"=",
"longValue",
">>",
"8",
";",
"}",
"return",
"new",
"Identifier",
"(",
"newValue",
")",
";",
"}"
] | Creates an Identifer backed by an array of length desiredByteLength
@param longValue a long to put into the identifier
@param desiredByteLength how many bytes to make the identifier
@return | [
"Creates",
"an",
"Identifer",
"backed",
"by",
"an",
"array",
"of",
"length",
"desiredByteLength"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/Identifier.java#L130-L140 |
25,109 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/Identifier.java | Identifier.fromBytes | @TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static Identifier fromBytes(byte[] bytes, int start, int end, boolean littleEndian) {
if (bytes == null) {
throw new NullPointerException("Identifiers cannot be constructed from null pointers but \"bytes\" is null.");
}
if (start < 0 || start > bytes.length) {
throw new ArrayIndexOutOfBoundsException("start < 0 || start > bytes.length");
}
if (end > bytes.length) {
throw new ArrayIndexOutOfBoundsException("end > bytes.length");
}
if (start > end) {
throw new IllegalArgumentException("start > end");
}
byte[] byteRange = Arrays.copyOfRange(bytes, start, end);
if (littleEndian) {
reverseArray(byteRange);
}
return new Identifier(byteRange);
} | java | @TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static Identifier fromBytes(byte[] bytes, int start, int end, boolean littleEndian) {
if (bytes == null) {
throw new NullPointerException("Identifiers cannot be constructed from null pointers but \"bytes\" is null.");
}
if (start < 0 || start > bytes.length) {
throw new ArrayIndexOutOfBoundsException("start < 0 || start > bytes.length");
}
if (end > bytes.length) {
throw new ArrayIndexOutOfBoundsException("end > bytes.length");
}
if (start > end) {
throw new IllegalArgumentException("start > end");
}
byte[] byteRange = Arrays.copyOfRange(bytes, start, end);
if (littleEndian) {
reverseArray(byteRange);
}
return new Identifier(byteRange);
} | [
"@",
"TargetApi",
"(",
"Build",
".",
"VERSION_CODES",
".",
"GINGERBREAD",
")",
"public",
"static",
"Identifier",
"fromBytes",
"(",
"byte",
"[",
"]",
"bytes",
",",
"int",
"start",
",",
"int",
"end",
",",
"boolean",
"littleEndian",
")",
"{",
"if",
"(",
"bytes",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"Identifiers cannot be constructed from null pointers but \\\"bytes\\\" is null.\"",
")",
";",
"}",
"if",
"(",
"start",
"<",
"0",
"||",
"start",
">",
"bytes",
".",
"length",
")",
"{",
"throw",
"new",
"ArrayIndexOutOfBoundsException",
"(",
"\"start < 0 || start > bytes.length\"",
")",
";",
"}",
"if",
"(",
"end",
">",
"bytes",
".",
"length",
")",
"{",
"throw",
"new",
"ArrayIndexOutOfBoundsException",
"(",
"\"end > bytes.length\"",
")",
";",
"}",
"if",
"(",
"start",
">",
"end",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"start > end\"",
")",
";",
"}",
"byte",
"[",
"]",
"byteRange",
"=",
"Arrays",
".",
"copyOfRange",
"(",
"bytes",
",",
"start",
",",
"end",
")",
";",
"if",
"(",
"littleEndian",
")",
"{",
"reverseArray",
"(",
"byteRange",
")",
";",
"}",
"return",
"new",
"Identifier",
"(",
"byteRange",
")",
";",
"}"
] | Creates an Identifier from the specified byte array.
@param bytes array to copy from
@param start the start index, inclusive
@param end the end index, exclusive
@param littleEndian whether the bytes are ordered in little endian
@return a new Identifier
@throws java.lang.NullPointerException <code>bytes</code> must not be <code>null</code>
@throws java.lang.ArrayIndexOutOfBoundsException start or end are outside the bounds of the array
@throws java.lang.IllegalArgumentException start is larger than end | [
"Creates",
"an",
"Identifier",
"from",
"the",
"specified",
"byte",
"array",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/Identifier.java#L171-L191 |
25,110 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/Identifier.java | Identifier.toByteArrayOfSpecifiedEndianness | @TargetApi(Build.VERSION_CODES.GINGERBREAD)
public byte[] toByteArrayOfSpecifiedEndianness(boolean bigEndian) {
byte[] copy = Arrays.copyOf(mValue, mValue.length);
if (!bigEndian) {
reverseArray(copy);
}
return copy;
} | java | @TargetApi(Build.VERSION_CODES.GINGERBREAD)
public byte[] toByteArrayOfSpecifiedEndianness(boolean bigEndian) {
byte[] copy = Arrays.copyOf(mValue, mValue.length);
if (!bigEndian) {
reverseArray(copy);
}
return copy;
} | [
"@",
"TargetApi",
"(",
"Build",
".",
"VERSION_CODES",
".",
"GINGERBREAD",
")",
"public",
"byte",
"[",
"]",
"toByteArrayOfSpecifiedEndianness",
"(",
"boolean",
"bigEndian",
")",
"{",
"byte",
"[",
"]",
"copy",
"=",
"Arrays",
".",
"copyOf",
"(",
"mValue",
",",
"mValue",
".",
"length",
")",
";",
"if",
"(",
"!",
"bigEndian",
")",
"{",
"reverseArray",
"(",
"copy",
")",
";",
"}",
"return",
"copy",
";",
"}"
] | Converts identifier to a byte array
@param bigEndian true if bytes are MSB first
@return a new byte array with a copy of the value | [
"Converts",
"identifier",
"to",
"a",
"byte",
"array"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/Identifier.java#L272-L281 |
25,111 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/Identifier.java | Identifier.toUuid | public UUID toUuid() {
if (mValue.length != 16) {
throw new UnsupportedOperationException("Only Identifiers backed by a byte array with length of exactly 16 can be UUIDs.");
}
LongBuffer buf = ByteBuffer.wrap(mValue).asLongBuffer();
return new UUID(buf.get(), buf.get());
} | java | public UUID toUuid() {
if (mValue.length != 16) {
throw new UnsupportedOperationException("Only Identifiers backed by a byte array with length of exactly 16 can be UUIDs.");
}
LongBuffer buf = ByteBuffer.wrap(mValue).asLongBuffer();
return new UUID(buf.get(), buf.get());
} | [
"public",
"UUID",
"toUuid",
"(",
")",
"{",
"if",
"(",
"mValue",
".",
"length",
"!=",
"16",
")",
"{",
"throw",
"new",
"UnsupportedOperationException",
"(",
"\"Only Identifiers backed by a byte array with length of exactly 16 can be UUIDs.\"",
")",
";",
"}",
"LongBuffer",
"buf",
"=",
"ByteBuffer",
".",
"wrap",
"(",
"mValue",
")",
".",
"asLongBuffer",
"(",
")",
";",
"return",
"new",
"UUID",
"(",
"buf",
".",
"get",
"(",
")",
",",
"buf",
".",
"get",
"(",
")",
")",
";",
"}"
] | Gives you the Identifier as a UUID if possible.
@throws UnsupportedOperationException if the byte array backing this Identifier is not exactly
16 bytes long. | [
"Gives",
"you",
"the",
"Identifier",
"as",
"a",
"UUID",
"if",
"possible",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/Identifier.java#L358-L364 |
25,112 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/Identifier.java | Identifier.compareTo | @Override
public int compareTo(Identifier that) {
if (mValue.length != that.mValue.length) {
return mValue.length < that.mValue.length ? -1 : 1;
}
for (int i = 0; i < mValue.length; i++) {
if (mValue[i] != that.mValue[i]) {
return mValue[i] < that.mValue[i] ? -1 : 1;
}
}
return 0;
} | java | @Override
public int compareTo(Identifier that) {
if (mValue.length != that.mValue.length) {
return mValue.length < that.mValue.length ? -1 : 1;
}
for (int i = 0; i < mValue.length; i++) {
if (mValue[i] != that.mValue[i]) {
return mValue[i] < that.mValue[i] ? -1 : 1;
}
}
return 0;
} | [
"@",
"Override",
"public",
"int",
"compareTo",
"(",
"Identifier",
"that",
")",
"{",
"if",
"(",
"mValue",
".",
"length",
"!=",
"that",
".",
"mValue",
".",
"length",
")",
"{",
"return",
"mValue",
".",
"length",
"<",
"that",
".",
"mValue",
".",
"length",
"?",
"-",
"1",
":",
"1",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"mValue",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"mValue",
"[",
"i",
"]",
"!=",
"that",
".",
"mValue",
"[",
"i",
"]",
")",
"{",
"return",
"mValue",
"[",
"i",
"]",
"<",
"that",
".",
"mValue",
"[",
"i",
"]",
"?",
"-",
"1",
":",
"1",
";",
"}",
"}",
"return",
"0",
";",
"}"
] | Compares two identifiers.
When the Identifiers don't have the same length, the Identifier having the shortest
array is considered smaller than the other.
@param that the other identifier
@return 0 if both identifiers are equal. Otherwise returns -1 or 1 depending
on which is bigger than the other.
@see Comparable#compareTo | [
"Compares",
"two",
"identifiers",
".",
"When",
"the",
"Identifiers",
"don",
"t",
"have",
"the",
"same",
"length",
"the",
"Identifier",
"having",
"the",
"shortest",
"array",
"is",
"considered",
"smaller",
"than",
"the",
"other",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/Identifier.java#L386-L397 |
25,113 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/distance/AndroidModel.java | AndroidModel.matchScore | public int matchScore(AndroidModel otherModel) {
int score = 0;
if (this.mManufacturer.equalsIgnoreCase(otherModel.mManufacturer)) {
score = 1;
}
if (score ==1 && this.mModel.equals(otherModel.mModel)) {
score = 2;
}
if (score == 2 && this.mBuildNumber.equals(otherModel.mBuildNumber)) {
score = 3;
}
if (score == 3 && this.mVersion.equals(otherModel.mVersion)) {
score = 4;
}
LogManager.d(TAG, "Score is %s for %s compared to %s", score, toString(), otherModel);
return score;
} | java | public int matchScore(AndroidModel otherModel) {
int score = 0;
if (this.mManufacturer.equalsIgnoreCase(otherModel.mManufacturer)) {
score = 1;
}
if (score ==1 && this.mModel.equals(otherModel.mModel)) {
score = 2;
}
if (score == 2 && this.mBuildNumber.equals(otherModel.mBuildNumber)) {
score = 3;
}
if (score == 3 && this.mVersion.equals(otherModel.mVersion)) {
score = 4;
}
LogManager.d(TAG, "Score is %s for %s compared to %s", score, toString(), otherModel);
return score;
} | [
"public",
"int",
"matchScore",
"(",
"AndroidModel",
"otherModel",
")",
"{",
"int",
"score",
"=",
"0",
";",
"if",
"(",
"this",
".",
"mManufacturer",
".",
"equalsIgnoreCase",
"(",
"otherModel",
".",
"mManufacturer",
")",
")",
"{",
"score",
"=",
"1",
";",
"}",
"if",
"(",
"score",
"==",
"1",
"&&",
"this",
".",
"mModel",
".",
"equals",
"(",
"otherModel",
".",
"mModel",
")",
")",
"{",
"score",
"=",
"2",
";",
"}",
"if",
"(",
"score",
"==",
"2",
"&&",
"this",
".",
"mBuildNumber",
".",
"equals",
"(",
"otherModel",
".",
"mBuildNumber",
")",
")",
"{",
"score",
"=",
"3",
";",
"}",
"if",
"(",
"score",
"==",
"3",
"&&",
"this",
".",
"mVersion",
".",
"equals",
"(",
"otherModel",
".",
"mVersion",
")",
")",
"{",
"score",
"=",
"4",
";",
"}",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Score is %s for %s compared to %s\"",
",",
"score",
",",
"toString",
"(",
")",
",",
"otherModel",
")",
";",
"return",
"score",
";",
"}"
] | Calculates a qualitative match score between two different Android device models for the
purposes of how likely they are to have similar Bluetooth signal level responses
@param otherModel
@return match quality, higher numbers are a better match | [
"Calculates",
"a",
"qualitative",
"match",
"score",
"between",
"two",
"different",
"Android",
"device",
"models",
"for",
"the",
"purposes",
"of",
"how",
"likely",
"they",
"are",
"to",
"have",
"similar",
"Bluetooth",
"signal",
"level",
"responses"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/distance/AndroidModel.java#L76-L92 |
25,114 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/Beacon.java | Beacon.getIdentifiers | public List<Identifier> getIdentifiers() {
if (mIdentifiers.getClass().isInstance(UNMODIFIABLE_LIST_OF_IDENTIFIER)) {
return mIdentifiers;
}
else {
return Collections.unmodifiableList(mIdentifiers);
}
} | java | public List<Identifier> getIdentifiers() {
if (mIdentifiers.getClass().isInstance(UNMODIFIABLE_LIST_OF_IDENTIFIER)) {
return mIdentifiers;
}
else {
return Collections.unmodifiableList(mIdentifiers);
}
} | [
"public",
"List",
"<",
"Identifier",
">",
"getIdentifiers",
"(",
")",
"{",
"if",
"(",
"mIdentifiers",
".",
"getClass",
"(",
")",
".",
"isInstance",
"(",
"UNMODIFIABLE_LIST_OF_IDENTIFIER",
")",
")",
"{",
"return",
"mIdentifiers",
";",
"}",
"else",
"{",
"return",
"Collections",
".",
"unmodifiableList",
"(",
"mIdentifiers",
")",
";",
"}",
"}"
] | Returns the list of identifiers transmitted with the advertisement
@return identifier | [
"Returns",
"the",
"list",
"of",
"identifiers",
"transmitted",
"with",
"the",
"advertisement"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/Beacon.java#L453-L460 |
25,115 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/Beacon.java | Beacon.getDistance | public double getDistance() {
if (mDistance == null) {
double bestRssiAvailable = mRssi;
if (mRunningAverageRssi != null) {
bestRssiAvailable = mRunningAverageRssi;
}
else {
LogManager.d(TAG, "Not using running average RSSI because it is null");
}
mDistance = calculateDistance(mTxPower, bestRssiAvailable);
}
return mDistance;
} | java | public double getDistance() {
if (mDistance == null) {
double bestRssiAvailable = mRssi;
if (mRunningAverageRssi != null) {
bestRssiAvailable = mRunningAverageRssi;
}
else {
LogManager.d(TAG, "Not using running average RSSI because it is null");
}
mDistance = calculateDistance(mTxPower, bestRssiAvailable);
}
return mDistance;
} | [
"public",
"double",
"getDistance",
"(",
")",
"{",
"if",
"(",
"mDistance",
"==",
"null",
")",
"{",
"double",
"bestRssiAvailable",
"=",
"mRssi",
";",
"if",
"(",
"mRunningAverageRssi",
"!=",
"null",
")",
"{",
"bestRssiAvailable",
"=",
"mRunningAverageRssi",
";",
"}",
"else",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Not using running average RSSI because it is null\"",
")",
";",
"}",
"mDistance",
"=",
"calculateDistance",
"(",
"mTxPower",
",",
"bestRssiAvailable",
")",
";",
"}",
"return",
"mDistance",
";",
"}"
] | Provides a calculated estimate of the distance to the beacon based on a running average of
the RSSI and the transmitted power calibration value included in the beacon advertisement.
This value is specific to the type of Android device receiving the transmission.
@see #mDistance
@return distance | [
"Provides",
"a",
"calculated",
"estimate",
"of",
"the",
"distance",
"to",
"the",
"beacon",
"based",
"on",
"a",
"running",
"average",
"of",
"the",
"RSSI",
"and",
"the",
"transmitted",
"power",
"calibration",
"value",
"included",
"in",
"the",
"beacon",
"advertisement",
".",
"This",
"value",
"is",
"specific",
"to",
"the",
"type",
"of",
"Android",
"device",
"receiving",
"the",
"transmission",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/Beacon.java#L471-L483 |
25,116 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/Beacon.java | Beacon.writeToParcel | @Deprecated
public void writeToParcel(Parcel out, int flags) {
out.writeInt(mIdentifiers.size());
for (Identifier identifier: mIdentifiers) {
out.writeString(identifier == null ? null : identifier.toString());
}
out.writeDouble(getDistance());
out.writeInt(mRssi);
out.writeInt(mTxPower);
out.writeString(mBluetoothAddress);
out.writeInt(mBeaconTypeCode);
out.writeInt(mServiceUuid);
out.writeInt(mDataFields.size());
for (Long dataField: mDataFields) {
out.writeLong(dataField);
}
out.writeInt(mExtraDataFields.size());
for (Long dataField: mExtraDataFields) {
out.writeLong(dataField);
}
out.writeInt(mManufacturer);
out.writeString(mBluetoothName);
out.writeString(mParserIdentifier);
out.writeByte((byte) (mMultiFrameBeacon ? 1: 0));
out.writeValue(mRunningAverageRssi);
out.writeInt(mRssiMeasurementCount);
out.writeInt(mPacketCount);
} | java | @Deprecated
public void writeToParcel(Parcel out, int flags) {
out.writeInt(mIdentifiers.size());
for (Identifier identifier: mIdentifiers) {
out.writeString(identifier == null ? null : identifier.toString());
}
out.writeDouble(getDistance());
out.writeInt(mRssi);
out.writeInt(mTxPower);
out.writeString(mBluetoothAddress);
out.writeInt(mBeaconTypeCode);
out.writeInt(mServiceUuid);
out.writeInt(mDataFields.size());
for (Long dataField: mDataFields) {
out.writeLong(dataField);
}
out.writeInt(mExtraDataFields.size());
for (Long dataField: mExtraDataFields) {
out.writeLong(dataField);
}
out.writeInt(mManufacturer);
out.writeString(mBluetoothName);
out.writeString(mParserIdentifier);
out.writeByte((byte) (mMultiFrameBeacon ? 1: 0));
out.writeValue(mRunningAverageRssi);
out.writeInt(mRssiMeasurementCount);
out.writeInt(mPacketCount);
} | [
"@",
"Deprecated",
"public",
"void",
"writeToParcel",
"(",
"Parcel",
"out",
",",
"int",
"flags",
")",
"{",
"out",
".",
"writeInt",
"(",
"mIdentifiers",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Identifier",
"identifier",
":",
"mIdentifiers",
")",
"{",
"out",
".",
"writeString",
"(",
"identifier",
"==",
"null",
"?",
"null",
":",
"identifier",
".",
"toString",
"(",
")",
")",
";",
"}",
"out",
".",
"writeDouble",
"(",
"getDistance",
"(",
")",
")",
";",
"out",
".",
"writeInt",
"(",
"mRssi",
")",
";",
"out",
".",
"writeInt",
"(",
"mTxPower",
")",
";",
"out",
".",
"writeString",
"(",
"mBluetoothAddress",
")",
";",
"out",
".",
"writeInt",
"(",
"mBeaconTypeCode",
")",
";",
"out",
".",
"writeInt",
"(",
"mServiceUuid",
")",
";",
"out",
".",
"writeInt",
"(",
"mDataFields",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Long",
"dataField",
":",
"mDataFields",
")",
"{",
"out",
".",
"writeLong",
"(",
"dataField",
")",
";",
"}",
"out",
".",
"writeInt",
"(",
"mExtraDataFields",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Long",
"dataField",
":",
"mExtraDataFields",
")",
"{",
"out",
".",
"writeLong",
"(",
"dataField",
")",
";",
"}",
"out",
".",
"writeInt",
"(",
"mManufacturer",
")",
";",
"out",
".",
"writeString",
"(",
"mBluetoothName",
")",
";",
"out",
".",
"writeString",
"(",
"mParserIdentifier",
")",
";",
"out",
".",
"writeByte",
"(",
"(",
"byte",
")",
"(",
"mMultiFrameBeacon",
"?",
"1",
":",
"0",
")",
")",
";",
"out",
".",
"writeValue",
"(",
"mRunningAverageRssi",
")",
";",
"out",
".",
"writeInt",
"(",
"mRssiMeasurementCount",
")",
";",
"out",
".",
"writeInt",
"(",
"mPacketCount",
")",
";",
"}"
] | Required for making object Parcelable. If you override this class, you must override this
method if you add any additional fields. | [
"Required",
"for",
"making",
"object",
"Parcelable",
".",
"If",
"you",
"override",
"this",
"class",
"you",
"must",
"override",
"this",
"method",
"if",
"you",
"add",
"any",
"additional",
"fields",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/Beacon.java#L612-L639 |
25,117 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/Region.java | Region.matchesBeacon | public boolean matchesBeacon(Beacon beacon) {
// All identifiers must match, or the corresponding region identifier must be null.
for (int i = mIdentifiers.size(); --i >= 0; ) {
final Identifier identifier = mIdentifiers.get(i);
Identifier beaconIdentifier = null;
if (i < beacon.mIdentifiers.size()) {
beaconIdentifier = beacon.getIdentifier(i);
}
if ((beaconIdentifier == null && identifier != null) ||
(beaconIdentifier != null && identifier != null && !identifier.equals(beaconIdentifier))) {
return false;
}
}
if (mBluetoothAddress != null && !mBluetoothAddress.equalsIgnoreCase(beacon.mBluetoothAddress)) {
return false;
}
return true;
} | java | public boolean matchesBeacon(Beacon beacon) {
// All identifiers must match, or the corresponding region identifier must be null.
for (int i = mIdentifiers.size(); --i >= 0; ) {
final Identifier identifier = mIdentifiers.get(i);
Identifier beaconIdentifier = null;
if (i < beacon.mIdentifiers.size()) {
beaconIdentifier = beacon.getIdentifier(i);
}
if ((beaconIdentifier == null && identifier != null) ||
(beaconIdentifier != null && identifier != null && !identifier.equals(beaconIdentifier))) {
return false;
}
}
if (mBluetoothAddress != null && !mBluetoothAddress.equalsIgnoreCase(beacon.mBluetoothAddress)) {
return false;
}
return true;
} | [
"public",
"boolean",
"matchesBeacon",
"(",
"Beacon",
"beacon",
")",
"{",
"// All identifiers must match, or the corresponding region identifier must be null.",
"for",
"(",
"int",
"i",
"=",
"mIdentifiers",
".",
"size",
"(",
")",
";",
"--",
"i",
">=",
"0",
";",
")",
"{",
"final",
"Identifier",
"identifier",
"=",
"mIdentifiers",
".",
"get",
"(",
"i",
")",
";",
"Identifier",
"beaconIdentifier",
"=",
"null",
";",
"if",
"(",
"i",
"<",
"beacon",
".",
"mIdentifiers",
".",
"size",
"(",
")",
")",
"{",
"beaconIdentifier",
"=",
"beacon",
".",
"getIdentifier",
"(",
"i",
")",
";",
"}",
"if",
"(",
"(",
"beaconIdentifier",
"==",
"null",
"&&",
"identifier",
"!=",
"null",
")",
"||",
"(",
"beaconIdentifier",
"!=",
"null",
"&&",
"identifier",
"!=",
"null",
"&&",
"!",
"identifier",
".",
"equals",
"(",
"beaconIdentifier",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"mBluetoothAddress",
"!=",
"null",
"&&",
"!",
"mBluetoothAddress",
".",
"equalsIgnoreCase",
"(",
"beacon",
".",
"mBluetoothAddress",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks to see if an Beacon object is included in the matching criteria of this Region
@param beacon the beacon to check to see if it is in the Region
@return true if is covered | [
"Checks",
"to",
"see",
"if",
"an",
"Beacon",
"object",
"is",
"included",
"in",
"the",
"matching",
"criteria",
"of",
"this",
"Region"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/Region.java#L183-L200 |
25,118 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconParser.java | BeaconParser.fromScanData | public Beacon fromScanData(byte[] scanData, int rssi, BluetoothDevice device) {
return fromScanData(scanData, rssi, device, new Beacon());
} | java | public Beacon fromScanData(byte[] scanData, int rssi, BluetoothDevice device) {
return fromScanData(scanData, rssi, device, new Beacon());
} | [
"public",
"Beacon",
"fromScanData",
"(",
"byte",
"[",
"]",
"scanData",
",",
"int",
"rssi",
",",
"BluetoothDevice",
"device",
")",
"{",
"return",
"fromScanData",
"(",
"scanData",
",",
"rssi",
",",
"device",
",",
"new",
"Beacon",
"(",
")",
")",
";",
"}"
] | Construct a Beacon from a Bluetooth LE packet collected by Android's Bluetooth APIs,
including the raw Bluetooth device info
@param scanData The actual packet bytes
@param rssi The measured signal strength of the packet
@param device The Bluetooth device that was detected
@return An instance of a <code>Beacon</code> | [
"Construct",
"a",
"Beacon",
"from",
"a",
"Bluetooth",
"LE",
"packet",
"collected",
"by",
"Android",
"s",
"Bluetooth",
"APIs",
"including",
"the",
"raw",
"Bluetooth",
"device",
"info"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconParser.java#L417-L419 |
25,119 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconTransmitter.java | BeaconTransmitter.startAdvertising | public void startAdvertising(Beacon beacon, AdvertiseCallback callback) {
mBeacon = beacon;
mAdvertisingClientCallback = callback;
startAdvertising();
} | java | public void startAdvertising(Beacon beacon, AdvertiseCallback callback) {
mBeacon = beacon;
mAdvertisingClientCallback = callback;
startAdvertising();
} | [
"public",
"void",
"startAdvertising",
"(",
"Beacon",
"beacon",
",",
"AdvertiseCallback",
"callback",
")",
"{",
"mBeacon",
"=",
"beacon",
";",
"mAdvertisingClientCallback",
"=",
"callback",
";",
"startAdvertising",
"(",
")",
";",
"}"
] | Starts advertising with fields from the passed beacon
@param beacon | [
"Starts",
"advertising",
"with",
"fields",
"from",
"the",
"passed",
"beacon"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconTransmitter.java#L156-L160 |
25,120 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconTransmitter.java | BeaconTransmitter.startAdvertising | public void startAdvertising() {
if (mBeacon == null) {
throw new NullPointerException("Beacon cannot be null. Set beacon before starting advertising");
}
int manufacturerCode = mBeacon.getManufacturer();
int serviceUuid = -1;
if (mBeaconParser.getServiceUuid() != null) {
serviceUuid = mBeaconParser.getServiceUuid().intValue();
}
if (mBeaconParser == null) {
throw new NullPointerException("You must supply a BeaconParser instance to BeaconTransmitter.");
}
byte[] advertisingBytes = mBeaconParser.getBeaconAdvertisementData(mBeacon);
String byteString = "";
for (int i= 0; i < advertisingBytes.length; i++) {
byteString += String.format("%02X", advertisingBytes[i]);
byteString += " ";
}
LogManager.d(TAG, "Starting advertising with ID1: %s ID2: %s ID3: %s and data: %s of size "
+ "%s", mBeacon.getId1(),
mBeacon.getIdentifiers().size() > 1 ? mBeacon.getId2() : "",
mBeacon.getIdentifiers().size() > 2 ? mBeacon.getId3() : "", byteString,
advertisingBytes.length);
try{
AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
if (serviceUuid > 0) {
byte[] serviceUuidBytes = new byte[] {
(byte) (serviceUuid & 0xff),
(byte) ((serviceUuid >> 8) & 0xff)};
ParcelUuid parcelUuid = parseUuidFrom(serviceUuidBytes);
dataBuilder.addServiceData(parcelUuid, advertisingBytes);
dataBuilder.addServiceUuid(parcelUuid);
dataBuilder.setIncludeTxPowerLevel(false);
dataBuilder.setIncludeDeviceName(false);
} else {
dataBuilder.addManufacturerData(manufacturerCode, advertisingBytes);
}
AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();
settingsBuilder.setAdvertiseMode(mAdvertiseMode);
settingsBuilder.setTxPowerLevel(mAdvertiseTxPowerLevel);
settingsBuilder.setConnectable(mConnectable);
mBluetoothLeAdvertiser.startAdvertising(settingsBuilder.build(), dataBuilder.build(), getAdvertiseCallback());
LogManager.d(TAG, "Started advertisement with callback: %s", getAdvertiseCallback());
} catch (Exception e){
LogManager.e(e, TAG, "Cannot start advertising due to exception");
}
} | java | public void startAdvertising() {
if (mBeacon == null) {
throw new NullPointerException("Beacon cannot be null. Set beacon before starting advertising");
}
int manufacturerCode = mBeacon.getManufacturer();
int serviceUuid = -1;
if (mBeaconParser.getServiceUuid() != null) {
serviceUuid = mBeaconParser.getServiceUuid().intValue();
}
if (mBeaconParser == null) {
throw new NullPointerException("You must supply a BeaconParser instance to BeaconTransmitter.");
}
byte[] advertisingBytes = mBeaconParser.getBeaconAdvertisementData(mBeacon);
String byteString = "";
for (int i= 0; i < advertisingBytes.length; i++) {
byteString += String.format("%02X", advertisingBytes[i]);
byteString += " ";
}
LogManager.d(TAG, "Starting advertising with ID1: %s ID2: %s ID3: %s and data: %s of size "
+ "%s", mBeacon.getId1(),
mBeacon.getIdentifiers().size() > 1 ? mBeacon.getId2() : "",
mBeacon.getIdentifiers().size() > 2 ? mBeacon.getId3() : "", byteString,
advertisingBytes.length);
try{
AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
if (serviceUuid > 0) {
byte[] serviceUuidBytes = new byte[] {
(byte) (serviceUuid & 0xff),
(byte) ((serviceUuid >> 8) & 0xff)};
ParcelUuid parcelUuid = parseUuidFrom(serviceUuidBytes);
dataBuilder.addServiceData(parcelUuid, advertisingBytes);
dataBuilder.addServiceUuid(parcelUuid);
dataBuilder.setIncludeTxPowerLevel(false);
dataBuilder.setIncludeDeviceName(false);
} else {
dataBuilder.addManufacturerData(manufacturerCode, advertisingBytes);
}
AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();
settingsBuilder.setAdvertiseMode(mAdvertiseMode);
settingsBuilder.setTxPowerLevel(mAdvertiseTxPowerLevel);
settingsBuilder.setConnectable(mConnectable);
mBluetoothLeAdvertiser.startAdvertising(settingsBuilder.build(), dataBuilder.build(), getAdvertiseCallback());
LogManager.d(TAG, "Started advertisement with callback: %s", getAdvertiseCallback());
} catch (Exception e){
LogManager.e(e, TAG, "Cannot start advertising due to exception");
}
} | [
"public",
"void",
"startAdvertising",
"(",
")",
"{",
"if",
"(",
"mBeacon",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"Beacon cannot be null. Set beacon before starting advertising\"",
")",
";",
"}",
"int",
"manufacturerCode",
"=",
"mBeacon",
".",
"getManufacturer",
"(",
")",
";",
"int",
"serviceUuid",
"=",
"-",
"1",
";",
"if",
"(",
"mBeaconParser",
".",
"getServiceUuid",
"(",
")",
"!=",
"null",
")",
"{",
"serviceUuid",
"=",
"mBeaconParser",
".",
"getServiceUuid",
"(",
")",
".",
"intValue",
"(",
")",
";",
"}",
"if",
"(",
"mBeaconParser",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"You must supply a BeaconParser instance to BeaconTransmitter.\"",
")",
";",
"}",
"byte",
"[",
"]",
"advertisingBytes",
"=",
"mBeaconParser",
".",
"getBeaconAdvertisementData",
"(",
"mBeacon",
")",
";",
"String",
"byteString",
"=",
"\"\"",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"advertisingBytes",
".",
"length",
";",
"i",
"++",
")",
"{",
"byteString",
"+=",
"String",
".",
"format",
"(",
"\"%02X\"",
",",
"advertisingBytes",
"[",
"i",
"]",
")",
";",
"byteString",
"+=",
"\" \"",
";",
"}",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Starting advertising with ID1: %s ID2: %s ID3: %s and data: %s of size \"",
"+",
"\"%s\"",
",",
"mBeacon",
".",
"getId1",
"(",
")",
",",
"mBeacon",
".",
"getIdentifiers",
"(",
")",
".",
"size",
"(",
")",
">",
"1",
"?",
"mBeacon",
".",
"getId2",
"(",
")",
":",
"\"\"",
",",
"mBeacon",
".",
"getIdentifiers",
"(",
")",
".",
"size",
"(",
")",
">",
"2",
"?",
"mBeacon",
".",
"getId3",
"(",
")",
":",
"\"\"",
",",
"byteString",
",",
"advertisingBytes",
".",
"length",
")",
";",
"try",
"{",
"AdvertiseData",
".",
"Builder",
"dataBuilder",
"=",
"new",
"AdvertiseData",
".",
"Builder",
"(",
")",
";",
"if",
"(",
"serviceUuid",
">",
"0",
")",
"{",
"byte",
"[",
"]",
"serviceUuidBytes",
"=",
"new",
"byte",
"[",
"]",
"{",
"(",
"byte",
")",
"(",
"serviceUuid",
"&",
"0xff",
")",
",",
"(",
"byte",
")",
"(",
"(",
"serviceUuid",
">>",
"8",
")",
"&",
"0xff",
")",
"}",
";",
"ParcelUuid",
"parcelUuid",
"=",
"parseUuidFrom",
"(",
"serviceUuidBytes",
")",
";",
"dataBuilder",
".",
"addServiceData",
"(",
"parcelUuid",
",",
"advertisingBytes",
")",
";",
"dataBuilder",
".",
"addServiceUuid",
"(",
"parcelUuid",
")",
";",
"dataBuilder",
".",
"setIncludeTxPowerLevel",
"(",
"false",
")",
";",
"dataBuilder",
".",
"setIncludeDeviceName",
"(",
"false",
")",
";",
"}",
"else",
"{",
"dataBuilder",
".",
"addManufacturerData",
"(",
"manufacturerCode",
",",
"advertisingBytes",
")",
";",
"}",
"AdvertiseSettings",
".",
"Builder",
"settingsBuilder",
"=",
"new",
"AdvertiseSettings",
".",
"Builder",
"(",
")",
";",
"settingsBuilder",
".",
"setAdvertiseMode",
"(",
"mAdvertiseMode",
")",
";",
"settingsBuilder",
".",
"setTxPowerLevel",
"(",
"mAdvertiseTxPowerLevel",
")",
";",
"settingsBuilder",
".",
"setConnectable",
"(",
"mConnectable",
")",
";",
"mBluetoothLeAdvertiser",
".",
"startAdvertising",
"(",
"settingsBuilder",
".",
"build",
"(",
")",
",",
"dataBuilder",
".",
"build",
"(",
")",
",",
"getAdvertiseCallback",
"(",
")",
")",
";",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Started advertisement with callback: %s\"",
",",
"getAdvertiseCallback",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LogManager",
".",
"e",
"(",
"e",
",",
"TAG",
",",
"\"Cannot start advertising due to exception\"",
")",
";",
"}",
"}"
] | Starts this beacon advertising | [
"Starts",
"this",
"beacon",
"advertising"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconTransmitter.java#L165-L219 |
25,121 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconTransmitter.java | BeaconTransmitter.stopAdvertising | public void stopAdvertising() {
if (!mStarted) {
LogManager.d(TAG, "Skipping stop advertising -- not started");
return;
}
LogManager.d(TAG, "Stopping advertising with object %s", mBluetoothLeAdvertiser);
mAdvertisingClientCallback = null;
try {
mBluetoothLeAdvertiser.stopAdvertising(getAdvertiseCallback());
}
catch (IllegalStateException e) {
LogManager.w(TAG, "Bluetooth is turned off. Transmitter stop call failed.");
}
mStarted = false;
} | java | public void stopAdvertising() {
if (!mStarted) {
LogManager.d(TAG, "Skipping stop advertising -- not started");
return;
}
LogManager.d(TAG, "Stopping advertising with object %s", mBluetoothLeAdvertiser);
mAdvertisingClientCallback = null;
try {
mBluetoothLeAdvertiser.stopAdvertising(getAdvertiseCallback());
}
catch (IllegalStateException e) {
LogManager.w(TAG, "Bluetooth is turned off. Transmitter stop call failed.");
}
mStarted = false;
} | [
"public",
"void",
"stopAdvertising",
"(",
")",
"{",
"if",
"(",
"!",
"mStarted",
")",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Skipping stop advertising -- not started\"",
")",
";",
"return",
";",
"}",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Stopping advertising with object %s\"",
",",
"mBluetoothLeAdvertiser",
")",
";",
"mAdvertisingClientCallback",
"=",
"null",
";",
"try",
"{",
"mBluetoothLeAdvertiser",
".",
"stopAdvertising",
"(",
"getAdvertiseCallback",
"(",
")",
")",
";",
"}",
"catch",
"(",
"IllegalStateException",
"e",
")",
"{",
"LogManager",
".",
"w",
"(",
"TAG",
",",
"\"Bluetooth is turned off. Transmitter stop call failed.\"",
")",
";",
"}",
"mStarted",
"=",
"false",
";",
"}"
] | Stops this beacon from advertising | [
"Stops",
"this",
"beacon",
"from",
"advertising"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconTransmitter.java#L224-L238 |
25,122 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconTransmitter.java | BeaconTransmitter.checkTransmissionSupported | public static int checkTransmissionSupported(Context context) {
int returnCode = SUPPORTED;
if (android.os.Build.VERSION.SDK_INT < 21) {
returnCode = NOT_SUPPORTED_MIN_SDK;
}
else if (!context.getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
returnCode = NOT_SUPPORTED_BLE;
}
else {
try {
// Check to see if the getBluetoothLeAdvertiser is available. If not, this will throw an exception indicating we are not running Android L
if (((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().getBluetoothLeAdvertiser() == null) {
if (!((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().isMultipleAdvertisementSupported()) {
returnCode = NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS;
}
else {
returnCode = NOT_SUPPORTED_CANNOT_GET_ADVERTISER;
}
}
} catch (Exception e) {
returnCode = NOT_SUPPORTED_CANNOT_GET_ADVERTISER;
}
}
return returnCode;
} | java | public static int checkTransmissionSupported(Context context) {
int returnCode = SUPPORTED;
if (android.os.Build.VERSION.SDK_INT < 21) {
returnCode = NOT_SUPPORTED_MIN_SDK;
}
else if (!context.getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
returnCode = NOT_SUPPORTED_BLE;
}
else {
try {
// Check to see if the getBluetoothLeAdvertiser is available. If not, this will throw an exception indicating we are not running Android L
if (((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().getBluetoothLeAdvertiser() == null) {
if (!((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().isMultipleAdvertisementSupported()) {
returnCode = NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS;
}
else {
returnCode = NOT_SUPPORTED_CANNOT_GET_ADVERTISER;
}
}
} catch (Exception e) {
returnCode = NOT_SUPPORTED_CANNOT_GET_ADVERTISER;
}
}
return returnCode;
} | [
"public",
"static",
"int",
"checkTransmissionSupported",
"(",
"Context",
"context",
")",
"{",
"int",
"returnCode",
"=",
"SUPPORTED",
";",
"if",
"(",
"android",
".",
"os",
".",
"Build",
".",
"VERSION",
".",
"SDK_INT",
"<",
"21",
")",
"{",
"returnCode",
"=",
"NOT_SUPPORTED_MIN_SDK",
";",
"}",
"else",
"if",
"(",
"!",
"context",
".",
"getApplicationContext",
"(",
")",
".",
"getPackageManager",
"(",
")",
".",
"hasSystemFeature",
"(",
"PackageManager",
".",
"FEATURE_BLUETOOTH_LE",
")",
")",
"{",
"returnCode",
"=",
"NOT_SUPPORTED_BLE",
";",
"}",
"else",
"{",
"try",
"{",
"// Check to see if the getBluetoothLeAdvertiser is available. If not, this will throw an exception indicating we are not running Android L",
"if",
"(",
"(",
"(",
"BluetoothManager",
")",
"context",
".",
"getSystemService",
"(",
"Context",
".",
"BLUETOOTH_SERVICE",
")",
")",
".",
"getAdapter",
"(",
")",
".",
"getBluetoothLeAdvertiser",
"(",
")",
"==",
"null",
")",
"{",
"if",
"(",
"!",
"(",
"(",
"BluetoothManager",
")",
"context",
".",
"getSystemService",
"(",
"Context",
".",
"BLUETOOTH_SERVICE",
")",
")",
".",
"getAdapter",
"(",
")",
".",
"isMultipleAdvertisementSupported",
"(",
")",
")",
"{",
"returnCode",
"=",
"NOT_SUPPORTED_CANNOT_GET_ADVERTISER_MULTIPLE_ADVERTISEMENTS",
";",
"}",
"else",
"{",
"returnCode",
"=",
"NOT_SUPPORTED_CANNOT_GET_ADVERTISER",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"returnCode",
"=",
"NOT_SUPPORTED_CANNOT_GET_ADVERTISER",
";",
"}",
"}",
"return",
"returnCode",
";",
"}"
] | Checks to see if this device supports beacon advertising
@return SUPPORTED if yes, otherwise:
NOT_SUPPORTED_MIN_SDK
NOT_SUPPORTED_BLE
NOT_SUPPORTED_MULTIPLE_ADVERTISEMENTS
NOT_SUPPORTED_CANNOT_GET_ADVERTISER | [
"Checks",
"to",
"see",
"if",
"this",
"device",
"supports",
"beacon",
"advertising"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconTransmitter.java#L248-L274 |
25,123 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/service/RangedBeacon.java | RangedBeacon.commitMeasurements | public void commitMeasurements() {
if (!getFilter().noMeasurementsAvailable()) {
double runningAverage = getFilter().calculateRssi();
mBeacon.setRunningAverageRssi(runningAverage);
mBeacon.setRssiMeasurementCount(getFilter().getMeasurementCount());
LogManager.d(TAG, "calculated new runningAverageRssi: %s", runningAverage);
}
else {
LogManager.d(TAG, "No measurements available to calculate running average");
}
mBeacon.setPacketCount(packetCount);
packetCount = 0;
} | java | public void commitMeasurements() {
if (!getFilter().noMeasurementsAvailable()) {
double runningAverage = getFilter().calculateRssi();
mBeacon.setRunningAverageRssi(runningAverage);
mBeacon.setRssiMeasurementCount(getFilter().getMeasurementCount());
LogManager.d(TAG, "calculated new runningAverageRssi: %s", runningAverage);
}
else {
LogManager.d(TAG, "No measurements available to calculate running average");
}
mBeacon.setPacketCount(packetCount);
packetCount = 0;
} | [
"public",
"void",
"commitMeasurements",
"(",
")",
"{",
"if",
"(",
"!",
"getFilter",
"(",
")",
".",
"noMeasurementsAvailable",
"(",
")",
")",
"{",
"double",
"runningAverage",
"=",
"getFilter",
"(",
")",
".",
"calculateRssi",
"(",
")",
";",
"mBeacon",
".",
"setRunningAverageRssi",
"(",
"runningAverage",
")",
";",
"mBeacon",
".",
"setRssiMeasurementCount",
"(",
"getFilter",
"(",
")",
".",
"getMeasurementCount",
"(",
")",
")",
";",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"calculated new runningAverageRssi: %s\"",
",",
"runningAverage",
")",
";",
"}",
"else",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"No measurements available to calculate running average\"",
")",
";",
"}",
"mBeacon",
".",
"setPacketCount",
"(",
"packetCount",
")",
";",
"packetCount",
"=",
"0",
";",
"}"
] | Done at the end of each cycle before data are sent to the client | [
"Done",
"at",
"the",
"end",
"of",
"each",
"cycle",
"before",
"data",
"are",
"sent",
"to",
"the",
"client"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/RangedBeacon.java#L49-L61 |
25,124 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/service/scanner/CycledLeScanner.java | CycledLeScanner.setScanPeriods | @MainThread
public void setScanPeriods(long scanPeriod, long betweenScanPeriod, boolean backgroundFlag) {
LogManager.d(TAG, "Set scan periods called with %s, %s Background mode must have changed.",
scanPeriod, betweenScanPeriod);
if (mBackgroundFlag != backgroundFlag) {
mRestartNeeded = true;
}
mBackgroundFlag = backgroundFlag;
mScanPeriod = scanPeriod;
mBetweenScanPeriod = betweenScanPeriod;
if (mBackgroundFlag) {
LogManager.d(TAG, "We are in the background. Setting wakeup alarm");
setWakeUpAlarm();
} else {
LogManager.d(TAG, "We are not in the background. Cancelling wakeup alarm");
cancelWakeUpAlarm();
}
long now = SystemClock.elapsedRealtime();
if (mNextScanCycleStartTime > now) {
// We are waiting to start scanning. We may need to adjust the next start time
// only do an adjustment if we need to make it happen sooner. Otherwise, it will
// take effect on the next cycle.
long proposedNextScanStartTime = (mLastScanCycleEndTime + betweenScanPeriod);
if (proposedNextScanStartTime < mNextScanCycleStartTime) {
mNextScanCycleStartTime = proposedNextScanStartTime;
LogManager.i(TAG, "Adjusted nextScanStartTime to be %s",
new Date(mNextScanCycleStartTime - SystemClock.elapsedRealtime() + System.currentTimeMillis()));
}
}
if (mScanCycleStopTime > now) {
// we are waiting to stop scanning. We may need to adjust the stop time
// only do an adjustment if we need to make it happen sooner. Otherwise, it will
// take effect on the next cycle.
long proposedScanStopTime = (mLastScanCycleStartTime + scanPeriod);
if (proposedScanStopTime < mScanCycleStopTime) {
mScanCycleStopTime = proposedScanStopTime;
LogManager.i(TAG, "Adjusted scanStopTime to be %s", mScanCycleStopTime);
}
}
} | java | @MainThread
public void setScanPeriods(long scanPeriod, long betweenScanPeriod, boolean backgroundFlag) {
LogManager.d(TAG, "Set scan periods called with %s, %s Background mode must have changed.",
scanPeriod, betweenScanPeriod);
if (mBackgroundFlag != backgroundFlag) {
mRestartNeeded = true;
}
mBackgroundFlag = backgroundFlag;
mScanPeriod = scanPeriod;
mBetweenScanPeriod = betweenScanPeriod;
if (mBackgroundFlag) {
LogManager.d(TAG, "We are in the background. Setting wakeup alarm");
setWakeUpAlarm();
} else {
LogManager.d(TAG, "We are not in the background. Cancelling wakeup alarm");
cancelWakeUpAlarm();
}
long now = SystemClock.elapsedRealtime();
if (mNextScanCycleStartTime > now) {
// We are waiting to start scanning. We may need to adjust the next start time
// only do an adjustment if we need to make it happen sooner. Otherwise, it will
// take effect on the next cycle.
long proposedNextScanStartTime = (mLastScanCycleEndTime + betweenScanPeriod);
if (proposedNextScanStartTime < mNextScanCycleStartTime) {
mNextScanCycleStartTime = proposedNextScanStartTime;
LogManager.i(TAG, "Adjusted nextScanStartTime to be %s",
new Date(mNextScanCycleStartTime - SystemClock.elapsedRealtime() + System.currentTimeMillis()));
}
}
if (mScanCycleStopTime > now) {
// we are waiting to stop scanning. We may need to adjust the stop time
// only do an adjustment if we need to make it happen sooner. Otherwise, it will
// take effect on the next cycle.
long proposedScanStopTime = (mLastScanCycleStartTime + scanPeriod);
if (proposedScanStopTime < mScanCycleStopTime) {
mScanCycleStopTime = proposedScanStopTime;
LogManager.i(TAG, "Adjusted scanStopTime to be %s", mScanCycleStopTime);
}
}
} | [
"@",
"MainThread",
"public",
"void",
"setScanPeriods",
"(",
"long",
"scanPeriod",
",",
"long",
"betweenScanPeriod",
",",
"boolean",
"backgroundFlag",
")",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Set scan periods called with %s, %s Background mode must have changed.\"",
",",
"scanPeriod",
",",
"betweenScanPeriod",
")",
";",
"if",
"(",
"mBackgroundFlag",
"!=",
"backgroundFlag",
")",
"{",
"mRestartNeeded",
"=",
"true",
";",
"}",
"mBackgroundFlag",
"=",
"backgroundFlag",
";",
"mScanPeriod",
"=",
"scanPeriod",
";",
"mBetweenScanPeriod",
"=",
"betweenScanPeriod",
";",
"if",
"(",
"mBackgroundFlag",
")",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"We are in the background. Setting wakeup alarm\"",
")",
";",
"setWakeUpAlarm",
"(",
")",
";",
"}",
"else",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"We are not in the background. Cancelling wakeup alarm\"",
")",
";",
"cancelWakeUpAlarm",
"(",
")",
";",
"}",
"long",
"now",
"=",
"SystemClock",
".",
"elapsedRealtime",
"(",
")",
";",
"if",
"(",
"mNextScanCycleStartTime",
">",
"now",
")",
"{",
"// We are waiting to start scanning. We may need to adjust the next start time",
"// only do an adjustment if we need to make it happen sooner. Otherwise, it will",
"// take effect on the next cycle.",
"long",
"proposedNextScanStartTime",
"=",
"(",
"mLastScanCycleEndTime",
"+",
"betweenScanPeriod",
")",
";",
"if",
"(",
"proposedNextScanStartTime",
"<",
"mNextScanCycleStartTime",
")",
"{",
"mNextScanCycleStartTime",
"=",
"proposedNextScanStartTime",
";",
"LogManager",
".",
"i",
"(",
"TAG",
",",
"\"Adjusted nextScanStartTime to be %s\"",
",",
"new",
"Date",
"(",
"mNextScanCycleStartTime",
"-",
"SystemClock",
".",
"elapsedRealtime",
"(",
")",
"+",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"mScanCycleStopTime",
">",
"now",
")",
"{",
"// we are waiting to stop scanning. We may need to adjust the stop time",
"// only do an adjustment if we need to make it happen sooner. Otherwise, it will",
"// take effect on the next cycle.",
"long",
"proposedScanStopTime",
"=",
"(",
"mLastScanCycleStartTime",
"+",
"scanPeriod",
")",
";",
"if",
"(",
"proposedScanStopTime",
"<",
"mScanCycleStopTime",
")",
"{",
"mScanCycleStopTime",
"=",
"proposedScanStopTime",
";",
"LogManager",
".",
"i",
"(",
"TAG",
",",
"\"Adjusted scanStopTime to be %s\"",
",",
"mScanCycleStopTime",
")",
";",
"}",
"}",
"}"
] | Tells the cycler the scan rate and whether it is in operating in background mode.
Background mode flag is used only with the Android 5.0 scanning implementations to switch
between LOW_POWER_MODE vs. LOW_LATENCY_MODE
@param backgroundFlag | [
"Tells",
"the",
"cycler",
"the",
"scan",
"rate",
"and",
"whether",
"it",
"is",
"in",
"operating",
"in",
"background",
"mode",
".",
"Background",
"mode",
"flag",
"is",
"used",
"only",
"with",
"the",
"Android",
"5",
".",
"0",
"scanning",
"implementations",
"to",
"switch",
"between",
"LOW_POWER_MODE",
"vs",
".",
"LOW_LATENCY_MODE"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/scanner/CycledLeScanner.java#L173-L212 |
25,125 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/service/scanner/CycledLeScanner.java | CycledLeScanner.setWakeUpAlarm | protected void setWakeUpAlarm() {
// wake up time will be the maximum of 5 minutes, the scan period, the between scan period
long milliseconds = 1000l * 60 * 5; /* five minutes */
if (milliseconds < mBetweenScanPeriod) {
milliseconds = mBetweenScanPeriod;
}
if (milliseconds < mScanPeriod) {
milliseconds = mScanPeriod;
}
AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + milliseconds, getWakeUpOperation());
LogManager.d(TAG, "Set a wakeup alarm to go off in %s ms: %s", milliseconds, getWakeUpOperation());
} | java | protected void setWakeUpAlarm() {
// wake up time will be the maximum of 5 minutes, the scan period, the between scan period
long milliseconds = 1000l * 60 * 5; /* five minutes */
if (milliseconds < mBetweenScanPeriod) {
milliseconds = mBetweenScanPeriod;
}
if (milliseconds < mScanPeriod) {
milliseconds = mScanPeriod;
}
AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + milliseconds, getWakeUpOperation());
LogManager.d(TAG, "Set a wakeup alarm to go off in %s ms: %s", milliseconds, getWakeUpOperation());
} | [
"protected",
"void",
"setWakeUpAlarm",
"(",
")",
"{",
"// wake up time will be the maximum of 5 minutes, the scan period, the between scan period",
"long",
"milliseconds",
"=",
"1000l",
"*",
"60",
"*",
"5",
";",
"/* five minutes */",
"if",
"(",
"milliseconds",
"<",
"mBetweenScanPeriod",
")",
"{",
"milliseconds",
"=",
"mBetweenScanPeriod",
";",
"}",
"if",
"(",
"milliseconds",
"<",
"mScanPeriod",
")",
"{",
"milliseconds",
"=",
"mScanPeriod",
";",
"}",
"AlarmManager",
"alarmManager",
"=",
"(",
"AlarmManager",
")",
"mContext",
".",
"getSystemService",
"(",
"Context",
".",
"ALARM_SERVICE",
")",
";",
"alarmManager",
".",
"set",
"(",
"AlarmManager",
".",
"ELAPSED_REALTIME_WAKEUP",
",",
"SystemClock",
".",
"elapsedRealtime",
"(",
")",
"+",
"milliseconds",
",",
"getWakeUpOperation",
"(",
")",
")",
";",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Set a wakeup alarm to go off in %s ms: %s\"",
",",
"milliseconds",
",",
"getWakeUpOperation",
"(",
")",
")",
";",
"}"
] | off the scan cycle again | [
"off",
"the",
"scan",
"cycle",
"again"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/scanner/CycledLeScanner.java#L478-L491 |
25,126 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/service/ScanHelper.java | ScanHelper.getScanCallbackIntent | PendingIntent getScanCallbackIntent() {
Intent intent = new Intent(mContext, StartupBroadcastReceiver.class);
intent.putExtra("o-scan", true);
return PendingIntent.getBroadcast(mContext,0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
} | java | PendingIntent getScanCallbackIntent() {
Intent intent = new Intent(mContext, StartupBroadcastReceiver.class);
intent.putExtra("o-scan", true);
return PendingIntent.getBroadcast(mContext,0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
} | [
"PendingIntent",
"getScanCallbackIntent",
"(",
")",
"{",
"Intent",
"intent",
"=",
"new",
"Intent",
"(",
"mContext",
",",
"StartupBroadcastReceiver",
".",
"class",
")",
";",
"intent",
".",
"putExtra",
"(",
"\"o-scan\"",
",",
"true",
")",
";",
"return",
"PendingIntent",
".",
"getBroadcast",
"(",
"mContext",
",",
"0",
",",
"intent",
",",
"PendingIntent",
".",
"FLAG_UPDATE_CURRENT",
")",
";",
"}"
] | Low power scan results in the background will be delivered via Intent | [
"Low",
"power",
"scan",
"results",
"in",
"the",
"background",
"will",
"be",
"delivered",
"via",
"Intent"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/ScanHelper.java#L250-L254 |
25,127 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/startup/RegionBootstrap.java | RegionBootstrap.disable | public void disable() {
if (disabled) {
return;
}
disabled = true;
try {
for (Region region : regions) {
beaconManager.stopMonitoringBeaconsInRegion(region);
}
} catch (RemoteException e) {
LogManager.e(e, TAG, "Can't stop bootstrap regions");
}
beaconManager.unbind(beaconConsumer);
} | java | public void disable() {
if (disabled) {
return;
}
disabled = true;
try {
for (Region region : regions) {
beaconManager.stopMonitoringBeaconsInRegion(region);
}
} catch (RemoteException e) {
LogManager.e(e, TAG, "Can't stop bootstrap regions");
}
beaconManager.unbind(beaconConsumer);
} | [
"public",
"void",
"disable",
"(",
")",
"{",
"if",
"(",
"disabled",
")",
"{",
"return",
";",
"}",
"disabled",
"=",
"true",
";",
"try",
"{",
"for",
"(",
"Region",
"region",
":",
"regions",
")",
"{",
"beaconManager",
".",
"stopMonitoringBeaconsInRegion",
"(",
"region",
")",
";",
"}",
"}",
"catch",
"(",
"RemoteException",
"e",
")",
"{",
"LogManager",
".",
"e",
"(",
"e",
",",
"TAG",
",",
"\"Can't stop bootstrap regions\"",
")",
";",
"}",
"beaconManager",
".",
"unbind",
"(",
"beaconConsumer",
")",
";",
"}"
] | Used to disable additional bootstrap callbacks after the first is received. Unless this is called,
your application will be get additional calls as the supplied regions are entered or exited. | [
"Used",
"to",
"disable",
"additional",
"bootstrap",
"callbacks",
"after",
"the",
"first",
"is",
"received",
".",
"Unless",
"this",
"is",
"called",
"your",
"application",
"will",
"be",
"get",
"additional",
"calls",
"as",
"the",
"supplied",
"regions",
"are",
"entered",
"or",
"exited",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/startup/RegionBootstrap.java#L133-L146 |
25,128 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/startup/RegionBootstrap.java | RegionBootstrap.addRegion | public void addRegion(Region region) {
if (!regions.contains(region)) {
if (serviceConnected) {
try {
beaconManager.startMonitoringBeaconsInRegion(region);
} catch (RemoteException e) {
LogManager.e(e, TAG, "Can't add bootstrap region");
}
} else {
LogManager.w(TAG, "Adding a region: service not yet Connected");
}
regions.add(region);
}
} | java | public void addRegion(Region region) {
if (!regions.contains(region)) {
if (serviceConnected) {
try {
beaconManager.startMonitoringBeaconsInRegion(region);
} catch (RemoteException e) {
LogManager.e(e, TAG, "Can't add bootstrap region");
}
} else {
LogManager.w(TAG, "Adding a region: service not yet Connected");
}
regions.add(region);
}
} | [
"public",
"void",
"addRegion",
"(",
"Region",
"region",
")",
"{",
"if",
"(",
"!",
"regions",
".",
"contains",
"(",
"region",
")",
")",
"{",
"if",
"(",
"serviceConnected",
")",
"{",
"try",
"{",
"beaconManager",
".",
"startMonitoringBeaconsInRegion",
"(",
"region",
")",
";",
"}",
"catch",
"(",
"RemoteException",
"e",
")",
"{",
"LogManager",
".",
"e",
"(",
"e",
",",
"TAG",
",",
"\"Can't add bootstrap region\"",
")",
";",
"}",
"}",
"else",
"{",
"LogManager",
".",
"w",
"(",
"TAG",
",",
"\"Adding a region: service not yet Connected\"",
")",
";",
"}",
"regions",
".",
"add",
"(",
"region",
")",
";",
"}",
"}"
] | Add a new region
@param region | [
"Add",
"a",
"new",
"region"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/startup/RegionBootstrap.java#L153-L166 |
25,129 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/startup/RegionBootstrap.java | RegionBootstrap.removeRegion | public void removeRegion(Region region) {
if (regions.contains(region)) {
if (serviceConnected) {
try {
beaconManager.stopMonitoringBeaconsInRegion(region);
} catch (RemoteException e) {
LogManager.e(e, TAG, "Can't stop bootstrap region");
}
} else {
LogManager.w(TAG, "Removing a region: service not yet Connected");
}
regions.remove(region);
}
} | java | public void removeRegion(Region region) {
if (regions.contains(region)) {
if (serviceConnected) {
try {
beaconManager.stopMonitoringBeaconsInRegion(region);
} catch (RemoteException e) {
LogManager.e(e, TAG, "Can't stop bootstrap region");
}
} else {
LogManager.w(TAG, "Removing a region: service not yet Connected");
}
regions.remove(region);
}
} | [
"public",
"void",
"removeRegion",
"(",
"Region",
"region",
")",
"{",
"if",
"(",
"regions",
".",
"contains",
"(",
"region",
")",
")",
"{",
"if",
"(",
"serviceConnected",
")",
"{",
"try",
"{",
"beaconManager",
".",
"stopMonitoringBeaconsInRegion",
"(",
"region",
")",
";",
"}",
"catch",
"(",
"RemoteException",
"e",
")",
"{",
"LogManager",
".",
"e",
"(",
"e",
",",
"TAG",
",",
"\"Can't stop bootstrap region\"",
")",
";",
"}",
"}",
"else",
"{",
"LogManager",
".",
"w",
"(",
"TAG",
",",
"\"Removing a region: service not yet Connected\"",
")",
";",
"}",
"regions",
".",
"remove",
"(",
"region",
")",
";",
"}",
"}"
] | Remove a given region
@param region | [
"Remove",
"a",
"given",
"region"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/startup/RegionBootstrap.java#L173-L186 |
25,130 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/service/RangeState.java | RangeState.finalizeBeacons | public synchronized Collection<Beacon> finalizeBeacons() {
Map<Beacon,RangedBeacon> newRangedBeacons = new HashMap<Beacon,RangedBeacon>();
ArrayList<Beacon> finalizedBeacons = new ArrayList<Beacon>();
synchronized (mRangedBeacons) {
for (Beacon beacon : mRangedBeacons.keySet()) {
RangedBeacon rangedBeacon = mRangedBeacons.get(beacon);
if (rangedBeacon != null) {
if (rangedBeacon.isTracked()) {
rangedBeacon.commitMeasurements(); // calculates accuracy
if (!rangedBeacon.noMeasurementsAvailable()) {
finalizedBeacons.add(rangedBeacon.getBeacon());
}
}
// If we still have useful measurements, keep it around but mark it as not
// tracked anymore so we don't pass it on as visible unless it is seen again
if (!rangedBeacon.noMeasurementsAvailable() == true) {
//if TrackingCache is enabled, allow beacon to not receive
//measurements for a certain amount of time
if (!sUseTrackingCache || rangedBeacon.isExpired())
rangedBeacon.setTracked(false);
newRangedBeacons.put(beacon, rangedBeacon);
}
else {
LogManager.d(TAG, "Dumping beacon from RangeState because it has no recent measurements.");
}
}
}
mRangedBeacons = newRangedBeacons;
}
return finalizedBeacons;
} | java | public synchronized Collection<Beacon> finalizeBeacons() {
Map<Beacon,RangedBeacon> newRangedBeacons = new HashMap<Beacon,RangedBeacon>();
ArrayList<Beacon> finalizedBeacons = new ArrayList<Beacon>();
synchronized (mRangedBeacons) {
for (Beacon beacon : mRangedBeacons.keySet()) {
RangedBeacon rangedBeacon = mRangedBeacons.get(beacon);
if (rangedBeacon != null) {
if (rangedBeacon.isTracked()) {
rangedBeacon.commitMeasurements(); // calculates accuracy
if (!rangedBeacon.noMeasurementsAvailable()) {
finalizedBeacons.add(rangedBeacon.getBeacon());
}
}
// If we still have useful measurements, keep it around but mark it as not
// tracked anymore so we don't pass it on as visible unless it is seen again
if (!rangedBeacon.noMeasurementsAvailable() == true) {
//if TrackingCache is enabled, allow beacon to not receive
//measurements for a certain amount of time
if (!sUseTrackingCache || rangedBeacon.isExpired())
rangedBeacon.setTracked(false);
newRangedBeacons.put(beacon, rangedBeacon);
}
else {
LogManager.d(TAG, "Dumping beacon from RangeState because it has no recent measurements.");
}
}
}
mRangedBeacons = newRangedBeacons;
}
return finalizedBeacons;
} | [
"public",
"synchronized",
"Collection",
"<",
"Beacon",
">",
"finalizeBeacons",
"(",
")",
"{",
"Map",
"<",
"Beacon",
",",
"RangedBeacon",
">",
"newRangedBeacons",
"=",
"new",
"HashMap",
"<",
"Beacon",
",",
"RangedBeacon",
">",
"(",
")",
";",
"ArrayList",
"<",
"Beacon",
">",
"finalizedBeacons",
"=",
"new",
"ArrayList",
"<",
"Beacon",
">",
"(",
")",
";",
"synchronized",
"(",
"mRangedBeacons",
")",
"{",
"for",
"(",
"Beacon",
"beacon",
":",
"mRangedBeacons",
".",
"keySet",
"(",
")",
")",
"{",
"RangedBeacon",
"rangedBeacon",
"=",
"mRangedBeacons",
".",
"get",
"(",
"beacon",
")",
";",
"if",
"(",
"rangedBeacon",
"!=",
"null",
")",
"{",
"if",
"(",
"rangedBeacon",
".",
"isTracked",
"(",
")",
")",
"{",
"rangedBeacon",
".",
"commitMeasurements",
"(",
")",
";",
"// calculates accuracy",
"if",
"(",
"!",
"rangedBeacon",
".",
"noMeasurementsAvailable",
"(",
")",
")",
"{",
"finalizedBeacons",
".",
"add",
"(",
"rangedBeacon",
".",
"getBeacon",
"(",
")",
")",
";",
"}",
"}",
"// If we still have useful measurements, keep it around but mark it as not",
"// tracked anymore so we don't pass it on as visible unless it is seen again",
"if",
"(",
"!",
"rangedBeacon",
".",
"noMeasurementsAvailable",
"(",
")",
"==",
"true",
")",
"{",
"//if TrackingCache is enabled, allow beacon to not receive",
"//measurements for a certain amount of time",
"if",
"(",
"!",
"sUseTrackingCache",
"||",
"rangedBeacon",
".",
"isExpired",
"(",
")",
")",
"rangedBeacon",
".",
"setTracked",
"(",
"false",
")",
";",
"newRangedBeacons",
".",
"put",
"(",
"beacon",
",",
"rangedBeacon",
")",
";",
"}",
"else",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Dumping beacon from RangeState because it has no recent measurements.\"",
")",
";",
"}",
"}",
"}",
"mRangedBeacons",
"=",
"newRangedBeacons",
";",
"}",
"return",
"finalizedBeacons",
";",
"}"
] | be there for the next cycle | [
"be",
"there",
"for",
"the",
"next",
"cycle"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/RangeState.java#L67-L99 |
25,131 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java | ScanJob.initialzeScanHelper | private boolean initialzeScanHelper() {
mScanHelper = new ScanHelper(this);
mScanState = ScanState.restore(ScanJob.this);
mScanState.setLastScanStartTimeMillis(System.currentTimeMillis());
mScanHelper.setMonitoringStatus(mScanState.getMonitoringStatus());
mScanHelper.setRangedRegionState(mScanState.getRangedRegionState());
mScanHelper.setBeaconParsers(mScanState.getBeaconParsers());
mScanHelper.setExtraDataBeaconTracker(mScanState.getExtraBeaconDataTracker());
if (mScanHelper.getCycledScanner() == null) {
try {
mScanHelper.createCycledLeScanner(mScanState.getBackgroundMode(), null);
}
catch (OutOfMemoryError e) {
LogManager.w(TAG, "Failed to create CycledLeScanner thread.");
return false;
}
}
return true;
} | java | private boolean initialzeScanHelper() {
mScanHelper = new ScanHelper(this);
mScanState = ScanState.restore(ScanJob.this);
mScanState.setLastScanStartTimeMillis(System.currentTimeMillis());
mScanHelper.setMonitoringStatus(mScanState.getMonitoringStatus());
mScanHelper.setRangedRegionState(mScanState.getRangedRegionState());
mScanHelper.setBeaconParsers(mScanState.getBeaconParsers());
mScanHelper.setExtraDataBeaconTracker(mScanState.getExtraBeaconDataTracker());
if (mScanHelper.getCycledScanner() == null) {
try {
mScanHelper.createCycledLeScanner(mScanState.getBackgroundMode(), null);
}
catch (OutOfMemoryError e) {
LogManager.w(TAG, "Failed to create CycledLeScanner thread.");
return false;
}
}
return true;
} | [
"private",
"boolean",
"initialzeScanHelper",
"(",
")",
"{",
"mScanHelper",
"=",
"new",
"ScanHelper",
"(",
"this",
")",
";",
"mScanState",
"=",
"ScanState",
".",
"restore",
"(",
"ScanJob",
".",
"this",
")",
";",
"mScanState",
".",
"setLastScanStartTimeMillis",
"(",
"System",
".",
"currentTimeMillis",
"(",
")",
")",
";",
"mScanHelper",
".",
"setMonitoringStatus",
"(",
"mScanState",
".",
"getMonitoringStatus",
"(",
")",
")",
";",
"mScanHelper",
".",
"setRangedRegionState",
"(",
"mScanState",
".",
"getRangedRegionState",
"(",
")",
")",
";",
"mScanHelper",
".",
"setBeaconParsers",
"(",
"mScanState",
".",
"getBeaconParsers",
"(",
")",
")",
";",
"mScanHelper",
".",
"setExtraDataBeaconTracker",
"(",
"mScanState",
".",
"getExtraBeaconDataTracker",
"(",
")",
")",
";",
"if",
"(",
"mScanHelper",
".",
"getCycledScanner",
"(",
")",
"==",
"null",
")",
"{",
"try",
"{",
"mScanHelper",
".",
"createCycledLeScanner",
"(",
"mScanState",
".",
"getBackgroundMode",
"(",
")",
",",
"null",
")",
";",
"}",
"catch",
"(",
"OutOfMemoryError",
"e",
")",
"{",
"LogManager",
".",
"w",
"(",
"TAG",
",",
"\"Failed to create CycledLeScanner thread.\"",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Returns false if cycle thread cannot be allocated | [
"Returns",
"false",
"if",
"cycle",
"thread",
"cannot",
"be",
"allocated"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/ScanJob.java#L182-L200 |
25,132 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconManager.java | BeaconManager.setDebug | public static void setDebug(boolean debug) {
if (debug) {
LogManager.setLogger(Loggers.verboseLogger());
LogManager.setVerboseLoggingEnabled(true);
} else {
LogManager.setLogger(Loggers.empty());
LogManager.setVerboseLoggingEnabled(false);
}
} | java | public static void setDebug(boolean debug) {
if (debug) {
LogManager.setLogger(Loggers.verboseLogger());
LogManager.setVerboseLoggingEnabled(true);
} else {
LogManager.setLogger(Loggers.empty());
LogManager.setVerboseLoggingEnabled(false);
}
} | [
"public",
"static",
"void",
"setDebug",
"(",
"boolean",
"debug",
")",
"{",
"if",
"(",
"debug",
")",
"{",
"LogManager",
".",
"setLogger",
"(",
"Loggers",
".",
"verboseLogger",
"(",
")",
")",
";",
"LogManager",
".",
"setVerboseLoggingEnabled",
"(",
"true",
")",
";",
"}",
"else",
"{",
"LogManager",
".",
"setLogger",
"(",
"Loggers",
".",
"empty",
"(",
")",
")",
";",
"LogManager",
".",
"setVerboseLoggingEnabled",
"(",
"false",
")",
";",
"}",
"}"
] | Set to true if you want to show library debugging.
@param debug True turn on all logs for this library to be printed out to logcat. False turns
off detailed logging..
This is a convenience method that calls setLogger to a verbose logger and enables verbose
logging. For more fine grained control, use:
{@link org.altbeacon.beacon.logging.LogManager#setLogger(org.altbeacon.beacon.logging.Logger)}
instead. | [
"Set",
"to",
"true",
"if",
"you",
"want",
"to",
"show",
"library",
"debugging",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconManager.java#L187-L195 |
25,133 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconManager.java | BeaconManager.setRegionExitPeriod | public static void setRegionExitPeriod(long regionExitPeriod){
sExitRegionPeriod = regionExitPeriod;
BeaconManager instance = sInstance;
if (instance != null) {
instance.applySettings();
}
} | java | public static void setRegionExitPeriod(long regionExitPeriod){
sExitRegionPeriod = regionExitPeriod;
BeaconManager instance = sInstance;
if (instance != null) {
instance.applySettings();
}
} | [
"public",
"static",
"void",
"setRegionExitPeriod",
"(",
"long",
"regionExitPeriod",
")",
"{",
"sExitRegionPeriod",
"=",
"regionExitPeriod",
";",
"BeaconManager",
"instance",
"=",
"sInstance",
";",
"if",
"(",
"instance",
"!=",
"null",
")",
"{",
"instance",
".",
"applySettings",
"(",
")",
";",
"}",
"}"
] | Set region exit period in milliseconds
@param regionExitPeriod | [
"Set",
"region",
"exit",
"period",
"in",
"milliseconds"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconManager.java#L280-L286 |
25,134 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconManager.java | BeaconManager.checkAvailability | @TargetApi(18)
public boolean checkAvailability() throws BleNotAvailableException {
if (!isBleAvailableOrSimulated()) {
throw new BleNotAvailableException("Bluetooth LE not supported by this device");
}
return ((BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().isEnabled();
} | java | @TargetApi(18)
public boolean checkAvailability() throws BleNotAvailableException {
if (!isBleAvailableOrSimulated()) {
throw new BleNotAvailableException("Bluetooth LE not supported by this device");
}
return ((BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter().isEnabled();
} | [
"@",
"TargetApi",
"(",
"18",
")",
"public",
"boolean",
"checkAvailability",
"(",
")",
"throws",
"BleNotAvailableException",
"{",
"if",
"(",
"!",
"isBleAvailableOrSimulated",
"(",
")",
")",
"{",
"throw",
"new",
"BleNotAvailableException",
"(",
"\"Bluetooth LE not supported by this device\"",
")",
";",
"}",
"return",
"(",
"(",
"BluetoothManager",
")",
"mContext",
".",
"getSystemService",
"(",
"Context",
".",
"BLUETOOTH_SERVICE",
")",
")",
".",
"getAdapter",
"(",
")",
".",
"isEnabled",
"(",
")",
";",
"}"
] | Check if Bluetooth LE is supported by this Android device, and if so, make sure it is enabled.
@return false if it is supported and not enabled
@throws BleNotAvailableException if Bluetooth LE is not supported. (Note: The Android emulator will do this) | [
"Check",
"if",
"Bluetooth",
"LE",
"is",
"supported",
"by",
"this",
"Android",
"device",
"and",
"if",
"so",
"make",
"sure",
"it",
"is",
"enabled",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconManager.java#L395-L401 |
25,135 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconManager.java | BeaconManager.setBackgroundMode | public void setBackgroundMode(boolean backgroundMode) {
if (!isBleAvailableOrSimulated()) {
LogManager.w(TAG, "Method invocation will be ignored.");
return;
}
mBackgroundModeUninitialized = false;
if (backgroundMode != mBackgroundMode) {
mBackgroundMode = backgroundMode;
try {
this.updateScanPeriods();
} catch (RemoteException e) {
LogManager.e(TAG, "Cannot contact service to set scan periods");
}
}
} | java | public void setBackgroundMode(boolean backgroundMode) {
if (!isBleAvailableOrSimulated()) {
LogManager.w(TAG, "Method invocation will be ignored.");
return;
}
mBackgroundModeUninitialized = false;
if (backgroundMode != mBackgroundMode) {
mBackgroundMode = backgroundMode;
try {
this.updateScanPeriods();
} catch (RemoteException e) {
LogManager.e(TAG, "Cannot contact service to set scan periods");
}
}
} | [
"public",
"void",
"setBackgroundMode",
"(",
"boolean",
"backgroundMode",
")",
"{",
"if",
"(",
"!",
"isBleAvailableOrSimulated",
"(",
")",
")",
"{",
"LogManager",
".",
"w",
"(",
"TAG",
",",
"\"Method invocation will be ignored.\"",
")",
";",
"return",
";",
"}",
"mBackgroundModeUninitialized",
"=",
"false",
";",
"if",
"(",
"backgroundMode",
"!=",
"mBackgroundMode",
")",
"{",
"mBackgroundMode",
"=",
"backgroundMode",
";",
"try",
"{",
"this",
".",
"updateScanPeriods",
"(",
")",
";",
"}",
"catch",
"(",
"RemoteException",
"e",
")",
"{",
"LogManager",
".",
"e",
"(",
"TAG",
",",
"\"Cannot contact service to set scan periods\"",
")",
";",
"}",
"}",
"}"
] | This method notifies the beacon service that the application is either moving to background
mode or foreground mode. When in background mode, BluetoothLE scans to look for beacons are
executed less frequently in order to save battery life. The specific scan rates for
background and foreground operation are set by the defaults below, but may be customized.
When ranging in the background, the time between updates will be much less frequent than in
the foreground. Updates will come every time interval equal to the sum total of the
BackgroundScanPeriod and the BackgroundBetweenScanPeriod.
@param backgroundMode true indicates the app is in the background
@see #DEFAULT_FOREGROUND_SCAN_PERIOD
@see #DEFAULT_FOREGROUND_BETWEEN_SCAN_PERIOD;
@see #DEFAULT_BACKGROUND_SCAN_PERIOD;
@see #DEFAULT_BACKGROUND_BETWEEN_SCAN_PERIOD;
@see #setForegroundScanPeriod(long p)
@see #setForegroundBetweenScanPeriod(long p)
@see #setBackgroundScanPeriod(long p)
@see #setBackgroundBetweenScanPeriod(long p) | [
"This",
"method",
"notifies",
"the",
"beacon",
"service",
"that",
"the",
"application",
"is",
"either",
"moving",
"to",
"background",
"mode",
"or",
"foreground",
"mode",
".",
"When",
"in",
"background",
"mode",
"BluetoothLE",
"scans",
"to",
"look",
"for",
"beacons",
"are",
"executed",
"less",
"frequently",
"in",
"order",
"to",
"save",
"battery",
"life",
".",
"The",
"specific",
"scan",
"rates",
"for",
"background",
"and",
"foreground",
"operation",
"are",
"set",
"by",
"the",
"defaults",
"below",
"but",
"may",
"be",
"customized",
".",
"When",
"ranging",
"in",
"the",
"background",
"the",
"time",
"between",
"updates",
"will",
"be",
"much",
"less",
"frequent",
"than",
"in",
"the",
"foreground",
".",
"Updates",
"will",
"come",
"every",
"time",
"interval",
"equal",
"to",
"the",
"sum",
"total",
"of",
"the",
"BackgroundScanPeriod",
"and",
"the",
"BackgroundBetweenScanPeriod",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconManager.java#L547-L561 |
25,136 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconManager.java | BeaconManager.setEnableScheduledScanJobs | public void setEnableScheduledScanJobs(boolean enabled) {
if (isAnyConsumerBound()) {
LogManager.e(TAG, "ScanJob may not be configured because a consumer is" +
" already bound.");
throw new IllegalStateException("Method must be called before calling bind()");
}
if (enabled && android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
LogManager.e(TAG, "ScanJob may not be configured because JobScheduler is not" +
" availble prior to Android 5.0");
return;
}
if (!enabled && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LogManager.w(TAG, "Disabling ScanJobs on Android 8+ may disable delivery of "+
"beacon callbacks in the background unless a foreground service is active.");
}
if(!enabled && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ScanJobScheduler.getInstance().cancelSchedule(mContext);
}
mScheduledScanJobsEnabled = enabled;
} | java | public void setEnableScheduledScanJobs(boolean enabled) {
if (isAnyConsumerBound()) {
LogManager.e(TAG, "ScanJob may not be configured because a consumer is" +
" already bound.");
throw new IllegalStateException("Method must be called before calling bind()");
}
if (enabled && android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
LogManager.e(TAG, "ScanJob may not be configured because JobScheduler is not" +
" availble prior to Android 5.0");
return;
}
if (!enabled && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LogManager.w(TAG, "Disabling ScanJobs on Android 8+ may disable delivery of "+
"beacon callbacks in the background unless a foreground service is active.");
}
if(!enabled && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ScanJobScheduler.getInstance().cancelSchedule(mContext);
}
mScheduledScanJobsEnabled = enabled;
} | [
"public",
"void",
"setEnableScheduledScanJobs",
"(",
"boolean",
"enabled",
")",
"{",
"if",
"(",
"isAnyConsumerBound",
"(",
")",
")",
"{",
"LogManager",
".",
"e",
"(",
"TAG",
",",
"\"ScanJob may not be configured because a consumer is\"",
"+",
"\" already bound.\"",
")",
";",
"throw",
"new",
"IllegalStateException",
"(",
"\"Method must be called before calling bind()\"",
")",
";",
"}",
"if",
"(",
"enabled",
"&&",
"android",
".",
"os",
".",
"Build",
".",
"VERSION",
".",
"SDK_INT",
"<",
"Build",
".",
"VERSION_CODES",
".",
"LOLLIPOP",
")",
"{",
"LogManager",
".",
"e",
"(",
"TAG",
",",
"\"ScanJob may not be configured because JobScheduler is not\"",
"+",
"\" availble prior to Android 5.0\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"enabled",
"&&",
"android",
".",
"os",
".",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"Build",
".",
"VERSION_CODES",
".",
"O",
")",
"{",
"LogManager",
".",
"w",
"(",
"TAG",
",",
"\"Disabling ScanJobs on Android 8+ may disable delivery of \"",
"+",
"\"beacon callbacks in the background unless a foreground service is active.\"",
")",
";",
"}",
"if",
"(",
"!",
"enabled",
"&&",
"android",
".",
"os",
".",
"Build",
".",
"VERSION",
".",
"SDK_INT",
">=",
"Build",
".",
"VERSION_CODES",
".",
"LOLLIPOP",
")",
"{",
"ScanJobScheduler",
".",
"getInstance",
"(",
")",
".",
"cancelSchedule",
"(",
"mContext",
")",
";",
"}",
"mScheduledScanJobsEnabled",
"=",
"enabled",
";",
"}"
] | Configures using a `ScanJob` run with the `JobScheduler` to perform scans rather than using a
long-running `BeaconService` to do so.
Calling with true on devices older than Android L (5.0) will not apply the change
as the JobScheduler is not available.
This value defaults to true on Android O+ and false on devices with older OS versions.
Accepting the default value of false is recommended on Android N and earlier because
otherwise beacon scans may be run only once every 15 minutes in the background, and no low
power scans may be performed between scanning cycles.
Setting this value to false will disable ScanJobs when the app is run on Android 8+, which
can prohibit delivery of callbacks when the app is in the background unless the scanning
process is running in a foreground service.
This method may only be called if bind() has not yet been called, otherwise an
`IllegalStateException` is thown.
@param enabled | [
"Configures",
"using",
"a",
"ScanJob",
"run",
"with",
"the",
"JobScheduler",
"to",
"perform",
"scans",
"rather",
"than",
"using",
"a",
"long",
"-",
"running",
"BeaconService",
"to",
"do",
"so",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconManager.java#L584-L603 |
25,137 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconManager.java | BeaconManager.setRegionStatePersistenceEnabled | public void setRegionStatePersistenceEnabled(boolean enabled) {
mRegionStatePersistenceEnabled = enabled;
if (!isScannerInDifferentProcess()) {
if (enabled) {
MonitoringStatus.getInstanceForApplication(mContext).startStatusPreservation();
} else {
MonitoringStatus.getInstanceForApplication(mContext).stopStatusPreservation();
}
}
this.applySettings();
} | java | public void setRegionStatePersistenceEnabled(boolean enabled) {
mRegionStatePersistenceEnabled = enabled;
if (!isScannerInDifferentProcess()) {
if (enabled) {
MonitoringStatus.getInstanceForApplication(mContext).startStatusPreservation();
} else {
MonitoringStatus.getInstanceForApplication(mContext).stopStatusPreservation();
}
}
this.applySettings();
} | [
"public",
"void",
"setRegionStatePersistenceEnabled",
"(",
"boolean",
"enabled",
")",
"{",
"mRegionStatePersistenceEnabled",
"=",
"enabled",
";",
"if",
"(",
"!",
"isScannerInDifferentProcess",
"(",
")",
")",
"{",
"if",
"(",
"enabled",
")",
"{",
"MonitoringStatus",
".",
"getInstanceForApplication",
"(",
"mContext",
")",
".",
"startStatusPreservation",
"(",
")",
";",
"}",
"else",
"{",
"MonitoringStatus",
".",
"getInstanceForApplication",
"(",
"mContext",
")",
".",
"stopStatusPreservation",
"(",
")",
";",
"}",
"}",
"this",
".",
"applySettings",
"(",
")",
";",
"}"
] | Turns off saving the state of monitored regions to persistent storage so it is retained over
app restarts. Defaults to enabled. When enabled, there will not be an "extra" region entry
event when the app starts up and a beacon for a monitored region was previously visible
within the past 15 minutes. Note that there is a limit to 50 monitored regions that may be
persisted. If more than 50 regions are monitored, state is not persisted for any.
@param enabled true to enable the region state persistence, false to disable it. | [
"Turns",
"off",
"saving",
"the",
"state",
"of",
"monitored",
"regions",
"to",
"persistent",
"storage",
"so",
"it",
"is",
"retained",
"over",
"app",
"restarts",
".",
"Defaults",
"to",
"enabled",
".",
"When",
"enabled",
"there",
"will",
"not",
"be",
"an",
"extra",
"region",
"entry",
"event",
"when",
"the",
"app",
"starts",
"up",
"and",
"a",
"beacon",
"for",
"a",
"monitored",
"region",
"was",
"previously",
"visible",
"within",
"the",
"past",
"15",
"minutes",
".",
"Note",
"that",
"there",
"is",
"a",
"limit",
"to",
"50",
"monitored",
"regions",
"that",
"may",
"be",
"persisted",
".",
"If",
"more",
"than",
"50",
"regions",
"are",
"monitored",
"state",
"is",
"not",
"persisted",
"for",
"any",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconManager.java#L787-L797 |
25,138 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconManager.java | BeaconManager.applySettings | public void applySettings() {
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
if (!isAnyConsumerBound()) {
LogManager.d(TAG, "Not synchronizing settings to service, as it has not started up yet");
} else if (isScannerInDifferentProcess()) {
LogManager.d(TAG, "Synchronizing settings to service");
syncSettingsToService();
} else {
LogManager.d(TAG, "Not synchronizing settings to service, as it is in the same process");
}
} | java | public void applySettings() {
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
if (!isAnyConsumerBound()) {
LogManager.d(TAG, "Not synchronizing settings to service, as it has not started up yet");
} else if (isScannerInDifferentProcess()) {
LogManager.d(TAG, "Synchronizing settings to service");
syncSettingsToService();
} else {
LogManager.d(TAG, "Not synchronizing settings to service, as it is in the same process");
}
} | [
"public",
"void",
"applySettings",
"(",
")",
"{",
"if",
"(",
"determineIfCalledFromSeparateScannerProcess",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"isAnyConsumerBound",
"(",
")",
")",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Not synchronizing settings to service, as it has not started up yet\"",
")",
";",
"}",
"else",
"if",
"(",
"isScannerInDifferentProcess",
"(",
")",
")",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Synchronizing settings to service\"",
")",
";",
"syncSettingsToService",
"(",
")",
";",
"}",
"else",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Not synchronizing settings to service, as it is in the same process\"",
")",
";",
"}",
"}"
] | Call this method if you are running the scanner service in a different process in order to
synchronize any configuration settings, including BeaconParsers to the scanner
@see #isScannerInDifferentProcess() | [
"Call",
"this",
"method",
"if",
"you",
"are",
"running",
"the",
"scanner",
"service",
"in",
"a",
"different",
"process",
"in",
"order",
"to",
"synchronize",
"any",
"configuration",
"settings",
"including",
"BeaconParsers",
"to",
"the",
"scanner"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconManager.java#L891-L903 |
25,139 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/BeaconManager.java | BeaconManager.enableForegroundServiceScanning | public void enableForegroundServiceScanning(Notification notification, int notificationId)
throws IllegalStateException {
if (isAnyConsumerBound()) {
throw new IllegalStateException("May not be called after consumers are already bound.");
}
if (notification == null) {
throw new NullPointerException("Notification cannot be null");
}
setEnableScheduledScanJobs(false);
mForegroundServiceNotification = notification;
mForegroundServiceNotificationId = notificationId;
} | java | public void enableForegroundServiceScanning(Notification notification, int notificationId)
throws IllegalStateException {
if (isAnyConsumerBound()) {
throw new IllegalStateException("May not be called after consumers are already bound.");
}
if (notification == null) {
throw new NullPointerException("Notification cannot be null");
}
setEnableScheduledScanJobs(false);
mForegroundServiceNotification = notification;
mForegroundServiceNotificationId = notificationId;
} | [
"public",
"void",
"enableForegroundServiceScanning",
"(",
"Notification",
"notification",
",",
"int",
"notificationId",
")",
"throws",
"IllegalStateException",
"{",
"if",
"(",
"isAnyConsumerBound",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"May not be called after consumers are already bound.\"",
")",
";",
"}",
"if",
"(",
"notification",
"==",
"null",
")",
"{",
"throw",
"new",
"NullPointerException",
"(",
"\"Notification cannot be null\"",
")",
";",
"}",
"setEnableScheduledScanJobs",
"(",
"false",
")",
";",
"mForegroundServiceNotification",
"=",
"notification",
";",
"mForegroundServiceNotificationId",
"=",
"notificationId",
";",
"}"
] | Configures the library to use a foreground service for bacon scanning. This allows nearly
constant scanning on most Android versions to get around background limits, and displays an
icon to the user to indicate that the app is doing something in the background, even on
Android 8+. This will disable the user of the JobScheduler on Android 8 to do scans. Note
that this method does not by itself enable constant scanning. The scan intervals will work
as normal and must be configurd to specific values depending on how often you wish to scan.
@see #setForegroundScanPeriod(long)
@see #setForegroundBetweenScanPeriod(long)
This method requires a notification to display a message to the user about why the app is
scanning in the background. The notification must include an icon that will be displayed
in the top bar whenever the scanning service is running.
If the BeaconService is configured to run in a different process, this call will have no
effect.
@param notification - the notification that will be displayed when beacon scanning is active,
along with the icon that shows up in the status bar.
@throws IllegalStateException if called after consumers are already bound to the scanning
service | [
"Configures",
"the",
"library",
"to",
"use",
"a",
"foreground",
"service",
"for",
"bacon",
"scanning",
".",
"This",
"allows",
"nearly",
"constant",
"scanning",
"on",
"most",
"Android",
"versions",
"to",
"get",
"around",
"background",
"limits",
"and",
"displays",
"an",
"icon",
"to",
"the",
"user",
"to",
"indicate",
"that",
"the",
"app",
"is",
"doing",
"something",
"in",
"the",
"background",
"even",
"on",
"Android",
"8",
"+",
".",
"This",
"will",
"disable",
"the",
"user",
"of",
"the",
"JobScheduler",
"on",
"Android",
"8",
"to",
"do",
"scans",
".",
"Note",
"that",
"this",
"method",
"does",
"not",
"by",
"itself",
"enable",
"constant",
"scanning",
".",
"The",
"scan",
"intervals",
"will",
"work",
"as",
"normal",
"and",
"must",
"be",
"configurd",
"to",
"specific",
"values",
"depending",
"on",
"how",
"often",
"you",
"wish",
"to",
"scan",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/BeaconManager.java#L1393-L1404 |
25,140 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/distance/CurveFittedDistanceCalculator.java | CurveFittedDistanceCalculator.calculateDistance | @Override
public double calculateDistance(int txPower, double rssi) {
if (rssi == 0) {
return -1.0; // if we cannot determine accuracy, return -1.
}
LogManager.d(TAG, "calculating distance based on mRssi of %s and txPower of %s", rssi, txPower);
double ratio = rssi*1.0/txPower;
double distance;
if (ratio < 1.0) {
distance = Math.pow(ratio,10);
}
else {
distance = (mCoefficient1)*Math.pow(ratio,mCoefficient2) + mCoefficient3;
}
LogManager.d(TAG, "avg mRssi: %s distance: %s", rssi, distance);
return distance;
} | java | @Override
public double calculateDistance(int txPower, double rssi) {
if (rssi == 0) {
return -1.0; // if we cannot determine accuracy, return -1.
}
LogManager.d(TAG, "calculating distance based on mRssi of %s and txPower of %s", rssi, txPower);
double ratio = rssi*1.0/txPower;
double distance;
if (ratio < 1.0) {
distance = Math.pow(ratio,10);
}
else {
distance = (mCoefficient1)*Math.pow(ratio,mCoefficient2) + mCoefficient3;
}
LogManager.d(TAG, "avg mRssi: %s distance: %s", rssi, distance);
return distance;
} | [
"@",
"Override",
"public",
"double",
"calculateDistance",
"(",
"int",
"txPower",
",",
"double",
"rssi",
")",
"{",
"if",
"(",
"rssi",
"==",
"0",
")",
"{",
"return",
"-",
"1.0",
";",
"// if we cannot determine accuracy, return -1.",
"}",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"calculating distance based on mRssi of %s and txPower of %s\"",
",",
"rssi",
",",
"txPower",
")",
";",
"double",
"ratio",
"=",
"rssi",
"*",
"1.0",
"/",
"txPower",
";",
"double",
"distance",
";",
"if",
"(",
"ratio",
"<",
"1.0",
")",
"{",
"distance",
"=",
"Math",
".",
"pow",
"(",
"ratio",
",",
"10",
")",
";",
"}",
"else",
"{",
"distance",
"=",
"(",
"mCoefficient1",
")",
"*",
"Math",
".",
"pow",
"(",
"ratio",
",",
"mCoefficient2",
")",
"+",
"mCoefficient3",
";",
"}",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"avg mRssi: %s distance: %s\"",
",",
"rssi",
",",
"distance",
")",
";",
"return",
"distance",
";",
"}"
] | Calculated the estimated distance in meters to the beacon based on a reference rssi at 1m
and the known actual rssi at the current location
@param txPower
@param rssi
@return estimated distance | [
"Calculated",
"the",
"estimated",
"distance",
"in",
"meters",
"to",
"the",
"beacon",
"based",
"on",
"a",
"reference",
"rssi",
"at",
"1m",
"and",
"the",
"known",
"actual",
"rssi",
"at",
"the",
"current",
"location"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/distance/CurveFittedDistanceCalculator.java#L45-L64 |
25,141 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/bluetooth/BluetoothCrashResolver.java | BluetoothCrashResolver.notifyScannedDevice | @TargetApi(18)
public void notifyScannedDevice(BluetoothDevice device, BluetoothAdapter.LeScanCallback scanner) {
int oldSize, newSize;
oldSize = distinctBluetoothAddresses.size();
synchronized(distinctBluetoothAddresses) {
distinctBluetoothAddresses.add(device.getAddress());
}
newSize = distinctBluetoothAddresses.size();
if (oldSize != newSize && newSize % 100 == 0) {
LogManager.d(TAG, "Distinct Bluetooth devices seen: %s", distinctBluetoothAddresses.size());
}
if (distinctBluetoothAddresses.size() > getCrashRiskDeviceCount()) {
if (PREEMPTIVE_ACTION_ENABLED && !recoveryInProgress) {
LogManager.w(TAG, "Large number of Bluetooth devices detected: %s Proactively "
+ "attempting to clear out address list to prevent a crash",
distinctBluetoothAddresses.size());
LogManager.w(TAG, "Stopping LE Scan");
BluetoothAdapter.getDefaultAdapter().stopLeScan(scanner);
startRecovery();
processStateChange();
}
}
} | java | @TargetApi(18)
public void notifyScannedDevice(BluetoothDevice device, BluetoothAdapter.LeScanCallback scanner) {
int oldSize, newSize;
oldSize = distinctBluetoothAddresses.size();
synchronized(distinctBluetoothAddresses) {
distinctBluetoothAddresses.add(device.getAddress());
}
newSize = distinctBluetoothAddresses.size();
if (oldSize != newSize && newSize % 100 == 0) {
LogManager.d(TAG, "Distinct Bluetooth devices seen: %s", distinctBluetoothAddresses.size());
}
if (distinctBluetoothAddresses.size() > getCrashRiskDeviceCount()) {
if (PREEMPTIVE_ACTION_ENABLED && !recoveryInProgress) {
LogManager.w(TAG, "Large number of Bluetooth devices detected: %s Proactively "
+ "attempting to clear out address list to prevent a crash",
distinctBluetoothAddresses.size());
LogManager.w(TAG, "Stopping LE Scan");
BluetoothAdapter.getDefaultAdapter().stopLeScan(scanner);
startRecovery();
processStateChange();
}
}
} | [
"@",
"TargetApi",
"(",
"18",
")",
"public",
"void",
"notifyScannedDevice",
"(",
"BluetoothDevice",
"device",
",",
"BluetoothAdapter",
".",
"LeScanCallback",
"scanner",
")",
"{",
"int",
"oldSize",
",",
"newSize",
";",
"oldSize",
"=",
"distinctBluetoothAddresses",
".",
"size",
"(",
")",
";",
"synchronized",
"(",
"distinctBluetoothAddresses",
")",
"{",
"distinctBluetoothAddresses",
".",
"add",
"(",
"device",
".",
"getAddress",
"(",
")",
")",
";",
"}",
"newSize",
"=",
"distinctBluetoothAddresses",
".",
"size",
"(",
")",
";",
"if",
"(",
"oldSize",
"!=",
"newSize",
"&&",
"newSize",
"%",
"100",
"==",
"0",
")",
"{",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"Distinct Bluetooth devices seen: %s\"",
",",
"distinctBluetoothAddresses",
".",
"size",
"(",
")",
")",
";",
"}",
"if",
"(",
"distinctBluetoothAddresses",
".",
"size",
"(",
")",
">",
"getCrashRiskDeviceCount",
"(",
")",
")",
"{",
"if",
"(",
"PREEMPTIVE_ACTION_ENABLED",
"&&",
"!",
"recoveryInProgress",
")",
"{",
"LogManager",
".",
"w",
"(",
"TAG",
",",
"\"Large number of Bluetooth devices detected: %s Proactively \"",
"+",
"\"attempting to clear out address list to prevent a crash\"",
",",
"distinctBluetoothAddresses",
".",
"size",
"(",
")",
")",
";",
"LogManager",
".",
"w",
"(",
"TAG",
",",
"\"Stopping LE Scan\"",
")",
";",
"BluetoothAdapter",
".",
"getDefaultAdapter",
"(",
")",
".",
"stopLeScan",
"(",
"scanner",
")",
";",
"startRecovery",
"(",
")",
";",
"processStateChange",
"(",
")",
";",
"}",
"}",
"}"
] | Call this method from your BluetoothAdapter.LeScanCallback method.
Doing so is optional, but if you do, this class will be able to count the number of
distinct Bluetooth devices scanned, and prevent crashes before they happen.
This works very well if the app containing this class is the only one running bluetooth
LE scans on the device, or it is constantly doing scans (e.g. is in the foreground for
extended periods of time.)
This will not work well if the application using this class is only scanning periodically
(e.g. when in the background to save battery) and another application is also scanning on
the same device, because this class will only get the counts from this application.
Future augmentation of this class may improve this by somehow centralizing the list of
unique scanned devices.
@param device | [
"Call",
"this",
"method",
"from",
"your",
"BluetoothAdapter",
".",
"LeScanCallback",
"method",
".",
"Doing",
"so",
"is",
"optional",
"but",
"if",
"you",
"do",
"this",
"class",
"will",
"be",
"able",
"to",
"count",
"the",
"number",
"of",
"distinct",
"Bluetooth",
"devices",
"scanned",
"and",
"prevent",
"crashes",
"before",
"they",
"happen",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/bluetooth/BluetoothCrashResolver.java#L175-L200 |
25,142 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/AltBeaconParser.java | AltBeaconParser.fromScanData | @Override
public Beacon fromScanData(byte[] scanData, int rssi, BluetoothDevice device) {
return fromScanData(scanData, rssi, device, new AltBeacon());
} | java | @Override
public Beacon fromScanData(byte[] scanData, int rssi, BluetoothDevice device) {
return fromScanData(scanData, rssi, device, new AltBeacon());
} | [
"@",
"Override",
"public",
"Beacon",
"fromScanData",
"(",
"byte",
"[",
"]",
"scanData",
",",
"int",
"rssi",
",",
"BluetoothDevice",
"device",
")",
"{",
"return",
"fromScanData",
"(",
"scanData",
",",
"rssi",
",",
"device",
",",
"new",
"AltBeacon",
"(",
")",
")",
";",
"}"
] | Construct an AltBeacon from a Bluetooth LE packet collected by Android's Bluetooth APIs,
including the raw Bluetooth device info
@param scanData The actual packet bytes
@param rssi The measured signal strength of the packet
@param device The Bluetooth device that was detected
@return An instance of an <code>Beacon</code> | [
"Construct",
"an",
"AltBeacon",
"from",
"a",
"Bluetooth",
"LE",
"packet",
"collected",
"by",
"Android",
"s",
"Bluetooth",
"APIs",
"including",
"the",
"raw",
"Bluetooth",
"device",
"info"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/AltBeaconParser.java#L65-L68 |
25,143 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/utils/EddystoneTelemetryAccessor.java | EddystoneTelemetryAccessor.getTelemetryBytes | public byte[] getTelemetryBytes(Beacon beacon) {
if (beacon.getExtraDataFields().size() >= 5) {
Beacon telemetryBeacon = new Beacon.Builder()
.setDataFields(beacon.getExtraDataFields())
.build();
BeaconParser telemetryParser = new BeaconParser()
.setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT);
byte[] telemetryBytes = telemetryParser.getBeaconAdvertisementData(telemetryBeacon);
Log.d(TAG, "Rehydrated telemetry bytes are :" + byteArrayToString(telemetryBytes));
return telemetryBytes;
}
else {
return null;
}
} | java | public byte[] getTelemetryBytes(Beacon beacon) {
if (beacon.getExtraDataFields().size() >= 5) {
Beacon telemetryBeacon = new Beacon.Builder()
.setDataFields(beacon.getExtraDataFields())
.build();
BeaconParser telemetryParser = new BeaconParser()
.setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT);
byte[] telemetryBytes = telemetryParser.getBeaconAdvertisementData(telemetryBeacon);
Log.d(TAG, "Rehydrated telemetry bytes are :" + byteArrayToString(telemetryBytes));
return telemetryBytes;
}
else {
return null;
}
} | [
"public",
"byte",
"[",
"]",
"getTelemetryBytes",
"(",
"Beacon",
"beacon",
")",
"{",
"if",
"(",
"beacon",
".",
"getExtraDataFields",
"(",
")",
".",
"size",
"(",
")",
">=",
"5",
")",
"{",
"Beacon",
"telemetryBeacon",
"=",
"new",
"Beacon",
".",
"Builder",
"(",
")",
".",
"setDataFields",
"(",
"beacon",
".",
"getExtraDataFields",
"(",
")",
")",
".",
"build",
"(",
")",
";",
"BeaconParser",
"telemetryParser",
"=",
"new",
"BeaconParser",
"(",
")",
".",
"setBeaconLayout",
"(",
"BeaconParser",
".",
"EDDYSTONE_TLM_LAYOUT",
")",
";",
"byte",
"[",
"]",
"telemetryBytes",
"=",
"telemetryParser",
".",
"getBeaconAdvertisementData",
"(",
"telemetryBeacon",
")",
";",
"Log",
".",
"d",
"(",
"TAG",
",",
"\"Rehydrated telemetry bytes are :\"",
"+",
"byteArrayToString",
"(",
"telemetryBytes",
")",
")",
";",
"return",
"telemetryBytes",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Extracts the raw Eddystone telemetry bytes from the extra data fields of an associated beacon.
This is useful for passing the telemetry to Google's backend services.
@param beacon
@return the bytes of the telemetry frame | [
"Extracts",
"the",
"raw",
"Eddystone",
"telemetry",
"bytes",
"from",
"the",
"extra",
"data",
"fields",
"of",
"an",
"associated",
"beacon",
".",
"This",
"is",
"useful",
"for",
"passing",
"the",
"telemetry",
"to",
"Google",
"s",
"backend",
"services",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/utils/EddystoneTelemetryAccessor.java#L23-L37 |
25,144 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/utils/EddystoneTelemetryAccessor.java | EddystoneTelemetryAccessor.getBase64EncodedTelemetry | @TargetApi(Build.VERSION_CODES.FROYO)
public String getBase64EncodedTelemetry(Beacon beacon) {
byte[] bytes = getTelemetryBytes(beacon);
if (bytes != null) {
String base64EncodedTelemetry = Base64.encodeToString(bytes, Base64.DEFAULT);
// 12-21 00:17:18.844 20180-20180/? D/EddystoneTLMAccessor: Rehydrated telemetry bytes are :20 00 00 00 88 29 18 4d 00 00 18 4d 00 00
// 12-21 00:17:18.844 20180-20180/? D/EddystoneTLMAccessor: Base64 telemetry bytes are :IAAAAIgpGE0AABhNAAA=
Log.d(TAG, "Base64 telemetry bytes are :"+base64EncodedTelemetry);
return base64EncodedTelemetry;
}
else {
return null;
}
} | java | @TargetApi(Build.VERSION_CODES.FROYO)
public String getBase64EncodedTelemetry(Beacon beacon) {
byte[] bytes = getTelemetryBytes(beacon);
if (bytes != null) {
String base64EncodedTelemetry = Base64.encodeToString(bytes, Base64.DEFAULT);
// 12-21 00:17:18.844 20180-20180/? D/EddystoneTLMAccessor: Rehydrated telemetry bytes are :20 00 00 00 88 29 18 4d 00 00 18 4d 00 00
// 12-21 00:17:18.844 20180-20180/? D/EddystoneTLMAccessor: Base64 telemetry bytes are :IAAAAIgpGE0AABhNAAA=
Log.d(TAG, "Base64 telemetry bytes are :"+base64EncodedTelemetry);
return base64EncodedTelemetry;
}
else {
return null;
}
} | [
"@",
"TargetApi",
"(",
"Build",
".",
"VERSION_CODES",
".",
"FROYO",
")",
"public",
"String",
"getBase64EncodedTelemetry",
"(",
"Beacon",
"beacon",
")",
"{",
"byte",
"[",
"]",
"bytes",
"=",
"getTelemetryBytes",
"(",
"beacon",
")",
";",
"if",
"(",
"bytes",
"!=",
"null",
")",
"{",
"String",
"base64EncodedTelemetry",
"=",
"Base64",
".",
"encodeToString",
"(",
"bytes",
",",
"Base64",
".",
"DEFAULT",
")",
";",
"// 12-21 00:17:18.844 20180-20180/? D/EddystoneTLMAccessor: Rehydrated telemetry bytes are :20 00 00 00 88 29 18 4d 00 00 18 4d 00 00",
"// 12-21 00:17:18.844 20180-20180/? D/EddystoneTLMAccessor: Base64 telemetry bytes are :IAAAAIgpGE0AABhNAAA=",
"Log",
".",
"d",
"(",
"TAG",
",",
"\"Base64 telemetry bytes are :\"",
"+",
"base64EncodedTelemetry",
")",
";",
"return",
"base64EncodedTelemetry",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Extracts the raw Eddystone telemetry bytes from the extra data fields of an associated beacon
and base64 encodes them. This is useful for passing the telemetry to Google's backend
services.
@param beacon
@return base64 encoded telemetry bytes | [
"Extracts",
"the",
"raw",
"Eddystone",
"telemetry",
"bytes",
"from",
"the",
"extra",
"data",
"fields",
"of",
"an",
"associated",
"beacon",
"and",
"base64",
"encodes",
"them",
".",
"This",
"is",
"useful",
"for",
"passing",
"the",
"telemetry",
"to",
"Google",
"s",
"backend",
"services",
"."
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/utils/EddystoneTelemetryAccessor.java#L46-L59 |
25,145 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/beacon/service/Callback.java | Callback.call | public boolean call(Context context, String dataName, Bundle data) {
boolean useLocalBroadcast = BeaconManager.getInstanceForApplication(context).isMainProcess();
boolean success = false;
if(useLocalBroadcast) {
String action = null;
if (dataName == "rangingData") {
action = BeaconLocalBroadcastProcessor.RANGE_NOTIFICATION;
}
else {
action = BeaconLocalBroadcastProcessor.MONITOR_NOTIFICATION;
}
Intent intent = new Intent(action);
intent.putExtra(dataName, data);
LogManager.d(TAG, "attempting callback via local broadcast intent: %s",action);
success = LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
else {
Intent intent = new Intent();
intent.setComponent(new ComponentName(context.getPackageName(), "org.altbeacon.beacon.BeaconIntentProcessor"));
intent.putExtra(dataName, data);
LogManager.d(TAG, "attempting callback via global broadcast intent: %s",intent.getComponent());
try {
context.startService(intent);
success = true;
} catch (Exception e) {
LogManager.e(
TAG,
"Failed attempting to start service: " + intent.getComponent().flattenToString(),
e
);
}
}
return success;
} | java | public boolean call(Context context, String dataName, Bundle data) {
boolean useLocalBroadcast = BeaconManager.getInstanceForApplication(context).isMainProcess();
boolean success = false;
if(useLocalBroadcast) {
String action = null;
if (dataName == "rangingData") {
action = BeaconLocalBroadcastProcessor.RANGE_NOTIFICATION;
}
else {
action = BeaconLocalBroadcastProcessor.MONITOR_NOTIFICATION;
}
Intent intent = new Intent(action);
intent.putExtra(dataName, data);
LogManager.d(TAG, "attempting callback via local broadcast intent: %s",action);
success = LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
else {
Intent intent = new Intent();
intent.setComponent(new ComponentName(context.getPackageName(), "org.altbeacon.beacon.BeaconIntentProcessor"));
intent.putExtra(dataName, data);
LogManager.d(TAG, "attempting callback via global broadcast intent: %s",intent.getComponent());
try {
context.startService(intent);
success = true;
} catch (Exception e) {
LogManager.e(
TAG,
"Failed attempting to start service: " + intent.getComponent().flattenToString(),
e
);
}
}
return success;
} | [
"public",
"boolean",
"call",
"(",
"Context",
"context",
",",
"String",
"dataName",
",",
"Bundle",
"data",
")",
"{",
"boolean",
"useLocalBroadcast",
"=",
"BeaconManager",
".",
"getInstanceForApplication",
"(",
"context",
")",
".",
"isMainProcess",
"(",
")",
";",
"boolean",
"success",
"=",
"false",
";",
"if",
"(",
"useLocalBroadcast",
")",
"{",
"String",
"action",
"=",
"null",
";",
"if",
"(",
"dataName",
"==",
"\"rangingData\"",
")",
"{",
"action",
"=",
"BeaconLocalBroadcastProcessor",
".",
"RANGE_NOTIFICATION",
";",
"}",
"else",
"{",
"action",
"=",
"BeaconLocalBroadcastProcessor",
".",
"MONITOR_NOTIFICATION",
";",
"}",
"Intent",
"intent",
"=",
"new",
"Intent",
"(",
"action",
")",
";",
"intent",
".",
"putExtra",
"(",
"dataName",
",",
"data",
")",
";",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"attempting callback via local broadcast intent: %s\"",
",",
"action",
")",
";",
"success",
"=",
"LocalBroadcastManager",
".",
"getInstance",
"(",
"context",
")",
".",
"sendBroadcast",
"(",
"intent",
")",
";",
"}",
"else",
"{",
"Intent",
"intent",
"=",
"new",
"Intent",
"(",
")",
";",
"intent",
".",
"setComponent",
"(",
"new",
"ComponentName",
"(",
"context",
".",
"getPackageName",
"(",
")",
",",
"\"org.altbeacon.beacon.BeaconIntentProcessor\"",
")",
")",
";",
"intent",
".",
"putExtra",
"(",
"dataName",
",",
"data",
")",
";",
"LogManager",
".",
"d",
"(",
"TAG",
",",
"\"attempting callback via global broadcast intent: %s\"",
",",
"intent",
".",
"getComponent",
"(",
")",
")",
";",
"try",
"{",
"context",
".",
"startService",
"(",
"intent",
")",
";",
"success",
"=",
"true",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LogManager",
".",
"e",
"(",
"TAG",
",",
"\"Failed attempting to start service: \"",
"+",
"intent",
".",
"getComponent",
"(",
")",
".",
"flattenToString",
"(",
")",
",",
"e",
")",
";",
"}",
"}",
"return",
"success",
";",
"}"
] | Tries making the callback, first via messenger, then via intent
@param context
@param dataName
@param data
@return false if it callback cannot be made | [
"Tries",
"making",
"the",
"callback",
"first",
"via",
"messenger",
"then",
"via",
"intent"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/beacon/service/Callback.java#L54-L88 |
25,146 | AltBeacon/android-beacon-library | lib/src/main/java/org/altbeacon/bluetooth/Pdu.java | Pdu.parse | @TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static Pdu parse(byte[] bytes, int startIndex) {
Pdu pdu = null;
if (bytes.length-startIndex >= 2) {
byte length = bytes[startIndex];
if (length > 0) {
byte type = bytes[startIndex + 1];
int firstIndex = startIndex + 2;
if (firstIndex < bytes.length) {
pdu = new Pdu();
// The End index is the startIndex + the length, because the first byte is the
// length field and the length field does not include the length field itself in
// the count
pdu.mEndIndex = startIndex + length;
if (pdu.mEndIndex >= bytes.length) {
pdu.mEndIndex = bytes.length - 1;
}
pdu.mType = type;
pdu.mDeclaredLength = length;
pdu.mStartIndex = firstIndex;
pdu.mBytes = bytes;
}
}
}
return pdu;
} | java | @TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static Pdu parse(byte[] bytes, int startIndex) {
Pdu pdu = null;
if (bytes.length-startIndex >= 2) {
byte length = bytes[startIndex];
if (length > 0) {
byte type = bytes[startIndex + 1];
int firstIndex = startIndex + 2;
if (firstIndex < bytes.length) {
pdu = new Pdu();
// The End index is the startIndex + the length, because the first byte is the
// length field and the length field does not include the length field itself in
// the count
pdu.mEndIndex = startIndex + length;
if (pdu.mEndIndex >= bytes.length) {
pdu.mEndIndex = bytes.length - 1;
}
pdu.mType = type;
pdu.mDeclaredLength = length;
pdu.mStartIndex = firstIndex;
pdu.mBytes = bytes;
}
}
}
return pdu;
} | [
"@",
"TargetApi",
"(",
"Build",
".",
"VERSION_CODES",
".",
"GINGERBREAD",
")",
"public",
"static",
"Pdu",
"parse",
"(",
"byte",
"[",
"]",
"bytes",
",",
"int",
"startIndex",
")",
"{",
"Pdu",
"pdu",
"=",
"null",
";",
"if",
"(",
"bytes",
".",
"length",
"-",
"startIndex",
">=",
"2",
")",
"{",
"byte",
"length",
"=",
"bytes",
"[",
"startIndex",
"]",
";",
"if",
"(",
"length",
">",
"0",
")",
"{",
"byte",
"type",
"=",
"bytes",
"[",
"startIndex",
"+",
"1",
"]",
";",
"int",
"firstIndex",
"=",
"startIndex",
"+",
"2",
";",
"if",
"(",
"firstIndex",
"<",
"bytes",
".",
"length",
")",
"{",
"pdu",
"=",
"new",
"Pdu",
"(",
")",
";",
"// The End index is the startIndex + the length, because the first byte is the",
"// length field and the length field does not include the length field itself in",
"// the count",
"pdu",
".",
"mEndIndex",
"=",
"startIndex",
"+",
"length",
";",
"if",
"(",
"pdu",
".",
"mEndIndex",
">=",
"bytes",
".",
"length",
")",
"{",
"pdu",
".",
"mEndIndex",
"=",
"bytes",
".",
"length",
"-",
"1",
";",
"}",
"pdu",
".",
"mType",
"=",
"type",
";",
"pdu",
".",
"mDeclaredLength",
"=",
"length",
";",
"pdu",
".",
"mStartIndex",
"=",
"firstIndex",
";",
"pdu",
".",
"mBytes",
"=",
"bytes",
";",
"}",
"}",
"}",
"return",
"pdu",
";",
"}"
] | Parse a PDU from a byte array looking offset by startIndex
@param bytes
@param startIndex
@return | [
"Parse",
"a",
"PDU",
"from",
"a",
"byte",
"array",
"looking",
"offset",
"by",
"startIndex"
] | f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3 | https://github.com/AltBeacon/android-beacon-library/blob/f7f3a323ea7415d53e7bd695ff6a01f1501d5dc3/lib/src/main/java/org/altbeacon/bluetooth/Pdu.java#L28-L53 |
25,147 | vdurmont/emoji-java | src/main/java/com/vdurmont/emoji/EmojiParser.java | EmojiParser.replaceAllEmojis | public static String replaceAllEmojis(String str, final String replacementString) {
EmojiParser.EmojiTransformer emojiTransformer = new EmojiParser.EmojiTransformer() {
public String transform(EmojiParser.UnicodeCandidate unicodeCandidate) {
return replacementString;
}
};
return parseFromUnicode(str, emojiTransformer);
} | java | public static String replaceAllEmojis(String str, final String replacementString) {
EmojiParser.EmojiTransformer emojiTransformer = new EmojiParser.EmojiTransformer() {
public String transform(EmojiParser.UnicodeCandidate unicodeCandidate) {
return replacementString;
}
};
return parseFromUnicode(str, emojiTransformer);
} | [
"public",
"static",
"String",
"replaceAllEmojis",
"(",
"String",
"str",
",",
"final",
"String",
"replacementString",
")",
"{",
"EmojiParser",
".",
"EmojiTransformer",
"emojiTransformer",
"=",
"new",
"EmojiParser",
".",
"EmojiTransformer",
"(",
")",
"{",
"public",
"String",
"transform",
"(",
"EmojiParser",
".",
"UnicodeCandidate",
"unicodeCandidate",
")",
"{",
"return",
"replacementString",
";",
"}",
"}",
";",
"return",
"parseFromUnicode",
"(",
"str",
",",
"emojiTransformer",
")",
";",
"}"
] | Replace all emojis with character
@param str the string to process
@param replacementString replacement the string that will replace all the emojis
@return the string with replaced character | [
"Replace",
"all",
"emojis",
"with",
"character"
] | 8cf5fbe0d7c1020b926791f2b342a263ed07bb0f | https://github.com/vdurmont/emoji-java/blob/8cf5fbe0d7c1020b926791f2b342a263ed07bb0f/src/main/java/com/vdurmont/emoji/EmojiParser.java#L94-L102 |
25,148 | vdurmont/emoji-java | src/main/java/com/vdurmont/emoji/EmojiParser.java | EmojiParser.removeAllEmojis | public static String removeAllEmojis(String str) {
EmojiTransformer emojiTransformer = new EmojiTransformer() {
public String transform(UnicodeCandidate unicodeCandidate) {
return "";
}
};
return parseFromUnicode(str, emojiTransformer);
} | java | public static String removeAllEmojis(String str) {
EmojiTransformer emojiTransformer = new EmojiTransformer() {
public String transform(UnicodeCandidate unicodeCandidate) {
return "";
}
};
return parseFromUnicode(str, emojiTransformer);
} | [
"public",
"static",
"String",
"removeAllEmojis",
"(",
"String",
"str",
")",
"{",
"EmojiTransformer",
"emojiTransformer",
"=",
"new",
"EmojiTransformer",
"(",
")",
"{",
"public",
"String",
"transform",
"(",
"UnicodeCandidate",
"unicodeCandidate",
")",
"{",
"return",
"\"\"",
";",
"}",
"}",
";",
"return",
"parseFromUnicode",
"(",
"str",
",",
"emojiTransformer",
")",
";",
"}"
] | Removes all emojis from a String
@param str the string to process
@return the string without any emoji | [
"Removes",
"all",
"emojis",
"from",
"a",
"String"
] | 8cf5fbe0d7c1020b926791f2b342a263ed07bb0f | https://github.com/vdurmont/emoji-java/blob/8cf5fbe0d7c1020b926791f2b342a263ed07bb0f/src/main/java/com/vdurmont/emoji/EmojiParser.java#L289-L297 |
25,149 | vdurmont/emoji-java | src/main/java/com/vdurmont/emoji/EmojiParser.java | EmojiParser.removeEmojis | public static String removeEmojis(
String str,
final Collection<Emoji> emojisToRemove
) {
EmojiTransformer emojiTransformer = new EmojiTransformer() {
public String transform(UnicodeCandidate unicodeCandidate) {
if (!emojisToRemove.contains(unicodeCandidate.getEmoji())) {
return unicodeCandidate.getEmoji().getUnicode() +
unicodeCandidate.getFitzpatrickUnicode();
}
return "";
}
};
return parseFromUnicode(str, emojiTransformer);
} | java | public static String removeEmojis(
String str,
final Collection<Emoji> emojisToRemove
) {
EmojiTransformer emojiTransformer = new EmojiTransformer() {
public String transform(UnicodeCandidate unicodeCandidate) {
if (!emojisToRemove.contains(unicodeCandidate.getEmoji())) {
return unicodeCandidate.getEmoji().getUnicode() +
unicodeCandidate.getFitzpatrickUnicode();
}
return "";
}
};
return parseFromUnicode(str, emojiTransformer);
} | [
"public",
"static",
"String",
"removeEmojis",
"(",
"String",
"str",
",",
"final",
"Collection",
"<",
"Emoji",
">",
"emojisToRemove",
")",
"{",
"EmojiTransformer",
"emojiTransformer",
"=",
"new",
"EmojiTransformer",
"(",
")",
"{",
"public",
"String",
"transform",
"(",
"UnicodeCandidate",
"unicodeCandidate",
")",
"{",
"if",
"(",
"!",
"emojisToRemove",
".",
"contains",
"(",
"unicodeCandidate",
".",
"getEmoji",
"(",
")",
")",
")",
"{",
"return",
"unicodeCandidate",
".",
"getEmoji",
"(",
")",
".",
"getUnicode",
"(",
")",
"+",
"unicodeCandidate",
".",
"getFitzpatrickUnicode",
"(",
")",
";",
"}",
"return",
"\"\"",
";",
"}",
"}",
";",
"return",
"parseFromUnicode",
"(",
"str",
",",
"emojiTransformer",
")",
";",
"}"
] | Removes a set of emojis from a String
@param str the string to process
@param emojisToRemove the emojis to remove from this string
@return the string without the emojis that were removed | [
"Removes",
"a",
"set",
"of",
"emojis",
"from",
"a",
"String"
] | 8cf5fbe0d7c1020b926791f2b342a263ed07bb0f | https://github.com/vdurmont/emoji-java/blob/8cf5fbe0d7c1020b926791f2b342a263ed07bb0f/src/main/java/com/vdurmont/emoji/EmojiParser.java#L308-L323 |
25,150 | vdurmont/emoji-java | src/main/java/com/vdurmont/emoji/EmojiParser.java | EmojiParser.removeAllEmojisExcept | public static String removeAllEmojisExcept(
String str,
final Collection<Emoji> emojisToKeep
) {
EmojiTransformer emojiTransformer = new EmojiTransformer() {
public String transform(UnicodeCandidate unicodeCandidate) {
if (emojisToKeep.contains(unicodeCandidate.getEmoji())) {
return unicodeCandidate.getEmoji().getUnicode() +
unicodeCandidate.getFitzpatrickUnicode();
}
return "";
}
};
return parseFromUnicode(str, emojiTransformer);
} | java | public static String removeAllEmojisExcept(
String str,
final Collection<Emoji> emojisToKeep
) {
EmojiTransformer emojiTransformer = new EmojiTransformer() {
public String transform(UnicodeCandidate unicodeCandidate) {
if (emojisToKeep.contains(unicodeCandidate.getEmoji())) {
return unicodeCandidate.getEmoji().getUnicode() +
unicodeCandidate.getFitzpatrickUnicode();
}
return "";
}
};
return parseFromUnicode(str, emojiTransformer);
} | [
"public",
"static",
"String",
"removeAllEmojisExcept",
"(",
"String",
"str",
",",
"final",
"Collection",
"<",
"Emoji",
">",
"emojisToKeep",
")",
"{",
"EmojiTransformer",
"emojiTransformer",
"=",
"new",
"EmojiTransformer",
"(",
")",
"{",
"public",
"String",
"transform",
"(",
"UnicodeCandidate",
"unicodeCandidate",
")",
"{",
"if",
"(",
"emojisToKeep",
".",
"contains",
"(",
"unicodeCandidate",
".",
"getEmoji",
"(",
")",
")",
")",
"{",
"return",
"unicodeCandidate",
".",
"getEmoji",
"(",
")",
".",
"getUnicode",
"(",
")",
"+",
"unicodeCandidate",
".",
"getFitzpatrickUnicode",
"(",
")",
";",
"}",
"return",
"\"\"",
";",
"}",
"}",
";",
"return",
"parseFromUnicode",
"(",
"str",
",",
"emojiTransformer",
")",
";",
"}"
] | Removes all the emojis in a String except a provided set
@param str the string to process
@param emojisToKeep the emojis to keep in this string
@return the string without the emojis that were removed | [
"Removes",
"all",
"the",
"emojis",
"in",
"a",
"String",
"except",
"a",
"provided",
"set"
] | 8cf5fbe0d7c1020b926791f2b342a263ed07bb0f | https://github.com/vdurmont/emoji-java/blob/8cf5fbe0d7c1020b926791f2b342a263ed07bb0f/src/main/java/com/vdurmont/emoji/EmojiParser.java#L333-L348 |
25,151 | vdurmont/emoji-java | src/main/java/com/vdurmont/emoji/EmojiParser.java | EmojiParser.getNextUnicodeCandidate | protected static UnicodeCandidate getNextUnicodeCandidate(char[] chars, int start) {
for (int i = start; i < chars.length; i++) {
int emojiEnd = getEmojiEndPos(chars, i);
if (emojiEnd != -1) {
Emoji emoji = EmojiManager.getByUnicode(new String(chars, i, emojiEnd - i));
String fitzpatrickString = (emojiEnd + 2 <= chars.length) ?
new String(chars, emojiEnd, 2) :
null;
return new UnicodeCandidate(
emoji,
fitzpatrickString,
i
);
}
}
return null;
} | java | protected static UnicodeCandidate getNextUnicodeCandidate(char[] chars, int start) {
for (int i = start; i < chars.length; i++) {
int emojiEnd = getEmojiEndPos(chars, i);
if (emojiEnd != -1) {
Emoji emoji = EmojiManager.getByUnicode(new String(chars, i, emojiEnd - i));
String fitzpatrickString = (emojiEnd + 2 <= chars.length) ?
new String(chars, emojiEnd, 2) :
null;
return new UnicodeCandidate(
emoji,
fitzpatrickString,
i
);
}
}
return null;
} | [
"protected",
"static",
"UnicodeCandidate",
"getNextUnicodeCandidate",
"(",
"char",
"[",
"]",
"chars",
",",
"int",
"start",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"start",
";",
"i",
"<",
"chars",
".",
"length",
";",
"i",
"++",
")",
"{",
"int",
"emojiEnd",
"=",
"getEmojiEndPos",
"(",
"chars",
",",
"i",
")",
";",
"if",
"(",
"emojiEnd",
"!=",
"-",
"1",
")",
"{",
"Emoji",
"emoji",
"=",
"EmojiManager",
".",
"getByUnicode",
"(",
"new",
"String",
"(",
"chars",
",",
"i",
",",
"emojiEnd",
"-",
"i",
")",
")",
";",
"String",
"fitzpatrickString",
"=",
"(",
"emojiEnd",
"+",
"2",
"<=",
"chars",
".",
"length",
")",
"?",
"new",
"String",
"(",
"chars",
",",
"emojiEnd",
",",
"2",
")",
":",
"null",
";",
"return",
"new",
"UnicodeCandidate",
"(",
"emoji",
",",
"fitzpatrickString",
",",
"i",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Finds the next UnicodeCandidate after a given starting index
@param chars char array to find UnicodeCandidate in
@param start starting index for search
@return the next UnicodeCandidate or null if no UnicodeCandidate is found after start index | [
"Finds",
"the",
"next",
"UnicodeCandidate",
"after",
"a",
"given",
"starting",
"index"
] | 8cf5fbe0d7c1020b926791f2b342a263ed07bb0f | https://github.com/vdurmont/emoji-java/blob/8cf5fbe0d7c1020b926791f2b342a263ed07bb0f/src/main/java/com/vdurmont/emoji/EmojiParser.java#L416-L434 |
25,152 | vdurmont/emoji-java | src/main/java/com/vdurmont/emoji/EmojiTrie.java | EmojiTrie.isEmoji | public Matches isEmoji(char[] sequence) {
if (sequence == null) {
return Matches.POSSIBLY;
}
Node tree = root;
for (char c : sequence) {
if (!tree.hasChild(c)) {
return Matches.IMPOSSIBLE;
}
tree = tree.getChild(c);
}
return tree.isEndOfEmoji() ? Matches.EXACTLY : Matches.POSSIBLY;
} | java | public Matches isEmoji(char[] sequence) {
if (sequence == null) {
return Matches.POSSIBLY;
}
Node tree = root;
for (char c : sequence) {
if (!tree.hasChild(c)) {
return Matches.IMPOSSIBLE;
}
tree = tree.getChild(c);
}
return tree.isEndOfEmoji() ? Matches.EXACTLY : Matches.POSSIBLY;
} | [
"public",
"Matches",
"isEmoji",
"(",
"char",
"[",
"]",
"sequence",
")",
"{",
"if",
"(",
"sequence",
"==",
"null",
")",
"{",
"return",
"Matches",
".",
"POSSIBLY",
";",
"}",
"Node",
"tree",
"=",
"root",
";",
"for",
"(",
"char",
"c",
":",
"sequence",
")",
"{",
"if",
"(",
"!",
"tree",
".",
"hasChild",
"(",
"c",
")",
")",
"{",
"return",
"Matches",
".",
"IMPOSSIBLE",
";",
"}",
"tree",
"=",
"tree",
".",
"getChild",
"(",
"c",
")",
";",
"}",
"return",
"tree",
".",
"isEndOfEmoji",
"(",
")",
"?",
"Matches",
".",
"EXACTLY",
":",
"Matches",
".",
"POSSIBLY",
";",
"}"
] | Checks if sequence of chars contain an emoji.
@param sequence Sequence of char that may contain emoji in full or
partially.
@return
<li>
Matches.EXACTLY if char sequence in its entirety is an emoji
</li>
<li>
Matches.POSSIBLY if char sequence matches prefix of an emoji
</li>
<li>
Matches.IMPOSSIBLE if char sequence matches no emoji or prefix of an
emoji
</li> | [
"Checks",
"if",
"sequence",
"of",
"chars",
"contain",
"an",
"emoji",
"."
] | 8cf5fbe0d7c1020b926791f2b342a263ed07bb0f | https://github.com/vdurmont/emoji-java/blob/8cf5fbe0d7c1020b926791f2b342a263ed07bb0f/src/main/java/com/vdurmont/emoji/EmojiTrie.java#L42-L56 |
25,153 | vdurmont/emoji-java | src/main/java/com/vdurmont/emoji/EmojiTrie.java | EmojiTrie.getEmoji | public Emoji getEmoji(String unicode) {
Node tree = root;
for (char c : unicode.toCharArray()) {
if (!tree.hasChild(c)) {
return null;
}
tree = tree.getChild(c);
}
return tree.getEmoji();
} | java | public Emoji getEmoji(String unicode) {
Node tree = root;
for (char c : unicode.toCharArray()) {
if (!tree.hasChild(c)) {
return null;
}
tree = tree.getChild(c);
}
return tree.getEmoji();
} | [
"public",
"Emoji",
"getEmoji",
"(",
"String",
"unicode",
")",
"{",
"Node",
"tree",
"=",
"root",
";",
"for",
"(",
"char",
"c",
":",
"unicode",
".",
"toCharArray",
"(",
")",
")",
"{",
"if",
"(",
"!",
"tree",
".",
"hasChild",
"(",
"c",
")",
")",
"{",
"return",
"null",
";",
"}",
"tree",
"=",
"tree",
".",
"getChild",
"(",
"c",
")",
";",
"}",
"return",
"tree",
".",
"getEmoji",
"(",
")",
";",
"}"
] | Finds Emoji instance from emoji unicode
@param unicode unicode of emoji to get
@return Emoji instance if unicode matches and emoji, null otherwise. | [
"Finds",
"Emoji",
"instance",
"from",
"emoji",
"unicode"
] | 8cf5fbe0d7c1020b926791f2b342a263ed07bb0f | https://github.com/vdurmont/emoji-java/blob/8cf5fbe0d7c1020b926791f2b342a263ed07bb0f/src/main/java/com/vdurmont/emoji/EmojiTrie.java#L64-L73 |
25,154 | vdurmont/emoji-java | src/main/java/com/vdurmont/emoji/Emoji.java | Emoji.stringJoin | private String stringJoin(String[] array, int count){
String joined = "";
for(int i = 0; i < count; i++)
joined += array[i];
return joined;
} | java | private String stringJoin(String[] array, int count){
String joined = "";
for(int i = 0; i < count; i++)
joined += array[i];
return joined;
} | [
"private",
"String",
"stringJoin",
"(",
"String",
"[",
"]",
"array",
",",
"int",
"count",
")",
"{",
"String",
"joined",
"=",
"\"\"",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"joined",
"+=",
"array",
"[",
"i",
"]",
";",
"return",
"joined",
";",
"}"
] | Method to replace String.join, since it was only introduced in java8
@param array the array to be concatenated
@return concatenated String | [
"Method",
"to",
"replace",
"String",
".",
"join",
"since",
"it",
"was",
"only",
"introduced",
"in",
"java8"
] | 8cf5fbe0d7c1020b926791f2b342a263ed07bb0f | https://github.com/vdurmont/emoji-java/blob/8cf5fbe0d7c1020b926791f2b342a263ed07bb0f/src/main/java/com/vdurmont/emoji/Emoji.java#L71-L76 |
25,155 | vdurmont/emoji-java | src/main/java/com/vdurmont/emoji/EmojiManager.java | EmojiManager.isEmoji | public static boolean isEmoji(String string) {
if (string == null) return false;
EmojiParser.UnicodeCandidate unicodeCandidate = EmojiParser.getNextUnicodeCandidate(string.toCharArray(), 0);
return unicodeCandidate != null &&
unicodeCandidate.getEmojiStartIndex() == 0 &&
unicodeCandidate.getFitzpatrickEndIndex() == string.length();
} | java | public static boolean isEmoji(String string) {
if (string == null) return false;
EmojiParser.UnicodeCandidate unicodeCandidate = EmojiParser.getNextUnicodeCandidate(string.toCharArray(), 0);
return unicodeCandidate != null &&
unicodeCandidate.getEmojiStartIndex() == 0 &&
unicodeCandidate.getFitzpatrickEndIndex() == string.length();
} | [
"public",
"static",
"boolean",
"isEmoji",
"(",
"String",
"string",
")",
"{",
"if",
"(",
"string",
"==",
"null",
")",
"return",
"false",
";",
"EmojiParser",
".",
"UnicodeCandidate",
"unicodeCandidate",
"=",
"EmojiParser",
".",
"getNextUnicodeCandidate",
"(",
"string",
".",
"toCharArray",
"(",
")",
",",
"0",
")",
";",
"return",
"unicodeCandidate",
"!=",
"null",
"&&",
"unicodeCandidate",
".",
"getEmojiStartIndex",
"(",
")",
"==",
"0",
"&&",
"unicodeCandidate",
".",
"getFitzpatrickEndIndex",
"(",
")",
"==",
"string",
".",
"length",
"(",
")",
";",
"}"
] | Tests if a given String is an emoji.
@param string the string to test
@return true if the string is an emoji's unicode, false else | [
"Tests",
"if",
"a",
"given",
"String",
"is",
"an",
"emoji",
"."
] | 8cf5fbe0d7c1020b926791f2b342a263ed07bb0f | https://github.com/vdurmont/emoji-java/blob/8cf5fbe0d7c1020b926791f2b342a263ed07bb0f/src/main/java/com/vdurmont/emoji/EmojiManager.java#L128-L135 |
25,156 | alibaba/jstorm | jstorm-core/src/main/java/backtype/storm/topology/base/BaseWindowedBolt.java | BaseWindowedBolt.withWindow | public BaseWindowedBolt withWindow(Count windowLength, Duration slidingInterval) {
return withWindowLength(windowLength).withSlidingInterval(slidingInterval);
} | java | public BaseWindowedBolt withWindow(Count windowLength, Duration slidingInterval) {
return withWindowLength(windowLength).withSlidingInterval(slidingInterval);
} | [
"public",
"BaseWindowedBolt",
"withWindow",
"(",
"Count",
"windowLength",
",",
"Duration",
"slidingInterval",
")",
"{",
"return",
"withWindowLength",
"(",
"windowLength",
")",
".",
"withSlidingInterval",
"(",
"slidingInterval",
")",
";",
"}"
] | Tuple count and time duration based sliding window configuration.
@param windowLength the number of tuples in the window
@param slidingInterval the time duration after which the window slides | [
"Tuple",
"count",
"and",
"time",
"duration",
"based",
"sliding",
"window",
"configuration",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/backtype/storm/topology/base/BaseWindowedBolt.java#L100-L102 |
25,157 | alibaba/jstorm | jstorm-core/src/main/java/storm/trident/topology/state/RotatingTransactionalState.java | RotatingTransactionalState.getStateOrCreate | public Object getStateOrCreate(long txid, StateInitializer init) {
if(_curr.containsKey(txid)) {
return _curr.get(txid);
} else {
getState(txid, init);
return null;
}
} | java | public Object getStateOrCreate(long txid, StateInitializer init) {
if(_curr.containsKey(txid)) {
return _curr.get(txid);
} else {
getState(txid, init);
return null;
}
} | [
"public",
"Object",
"getStateOrCreate",
"(",
"long",
"txid",
",",
"StateInitializer",
"init",
")",
"{",
"if",
"(",
"_curr",
".",
"containsKey",
"(",
"txid",
")",
")",
"{",
"return",
"_curr",
".",
"get",
"(",
"txid",
")",
";",
"}",
"else",
"{",
"getState",
"(",
"txid",
",",
"init",
")",
";",
"return",
"null",
";",
"}",
"}"
] | Returns null if it was created, the value otherwise. | [
"Returns",
"null",
"if",
"it",
"was",
"created",
"the",
"value",
"otherwise",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/storm/trident/topology/state/RotatingTransactionalState.java#L105-L112 |
25,158 | alibaba/jstorm | jstorm-core/src/main/java/backtype/storm/spout/CheckPointState.java | CheckPointState.nextState | public CheckPointState nextState(boolean recovering) {
CheckPointState nextState;
switch (state) {
case PREPARING:
nextState = recovering ? new CheckPointState(txid - 1, State.COMMITTED) : new CheckPointState(txid, State.COMMITTING);
break;
case COMMITTING:
nextState = new CheckPointState(txid, State.COMMITTED);
break;
case COMMITTED:
nextState = recovering ? this : new CheckPointState(txid + 1, State.PREPARING);
break;
default:
throw new IllegalStateException("Unknown state " + state);
}
return nextState;
} | java | public CheckPointState nextState(boolean recovering) {
CheckPointState nextState;
switch (state) {
case PREPARING:
nextState = recovering ? new CheckPointState(txid - 1, State.COMMITTED) : new CheckPointState(txid, State.COMMITTING);
break;
case COMMITTING:
nextState = new CheckPointState(txid, State.COMMITTED);
break;
case COMMITTED:
nextState = recovering ? this : new CheckPointState(txid + 1, State.PREPARING);
break;
default:
throw new IllegalStateException("Unknown state " + state);
}
return nextState;
} | [
"public",
"CheckPointState",
"nextState",
"(",
"boolean",
"recovering",
")",
"{",
"CheckPointState",
"nextState",
";",
"switch",
"(",
"state",
")",
"{",
"case",
"PREPARING",
":",
"nextState",
"=",
"recovering",
"?",
"new",
"CheckPointState",
"(",
"txid",
"-",
"1",
",",
"State",
".",
"COMMITTED",
")",
":",
"new",
"CheckPointState",
"(",
"txid",
",",
"State",
".",
"COMMITTING",
")",
";",
"break",
";",
"case",
"COMMITTING",
":",
"nextState",
"=",
"new",
"CheckPointState",
"(",
"txid",
",",
"State",
".",
"COMMITTED",
")",
";",
"break",
";",
"case",
"COMMITTED",
":",
"nextState",
"=",
"recovering",
"?",
"this",
":",
"new",
"CheckPointState",
"(",
"txid",
"+",
"1",
",",
"State",
".",
"PREPARING",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"IllegalStateException",
"(",
"\"Unknown state \"",
"+",
"state",
")",
";",
"}",
"return",
"nextState",
";",
"}"
] | Get the next state based on this checkpoint state.
@param recovering if in recovering phase
@return the next checkpoint state based on this state. | [
"Get",
"the",
"next",
"state",
"based",
"on",
"this",
"checkpoint",
"state",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/backtype/storm/spout/CheckPointState.java#L100-L116 |
25,159 | alibaba/jstorm | jstorm-core/src/main/java/backtype/storm/spout/CheckPointState.java | CheckPointState.nextAction | public Action nextAction(boolean recovering) {
Action action;
switch (state) {
case PREPARING:
action = recovering ? Action.ROLLBACK : Action.PREPARE;
break;
case COMMITTING:
action = Action.COMMIT;
break;
case COMMITTED:
action = recovering ? Action.INITSTATE : Action.PREPARE;
break;
default:
throw new IllegalStateException("Unknown state " + state);
}
return action;
} | java | public Action nextAction(boolean recovering) {
Action action;
switch (state) {
case PREPARING:
action = recovering ? Action.ROLLBACK : Action.PREPARE;
break;
case COMMITTING:
action = Action.COMMIT;
break;
case COMMITTED:
action = recovering ? Action.INITSTATE : Action.PREPARE;
break;
default:
throw new IllegalStateException("Unknown state " + state);
}
return action;
} | [
"public",
"Action",
"nextAction",
"(",
"boolean",
"recovering",
")",
"{",
"Action",
"action",
";",
"switch",
"(",
"state",
")",
"{",
"case",
"PREPARING",
":",
"action",
"=",
"recovering",
"?",
"Action",
".",
"ROLLBACK",
":",
"Action",
".",
"PREPARE",
";",
"break",
";",
"case",
"COMMITTING",
":",
"action",
"=",
"Action",
".",
"COMMIT",
";",
"break",
";",
"case",
"COMMITTED",
":",
"action",
"=",
"recovering",
"?",
"Action",
".",
"INITSTATE",
":",
"Action",
".",
"PREPARE",
";",
"break",
";",
"default",
":",
"throw",
"new",
"IllegalStateException",
"(",
"\"Unknown state \"",
"+",
"state",
")",
";",
"}",
"return",
"action",
";",
"}"
] | Get the next action to perform based on this checkpoint state.
@param recovering if in recovering phase
@return the next action to perform based on this state | [
"Get",
"the",
"next",
"action",
"to",
"perform",
"based",
"on",
"this",
"checkpoint",
"state",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/backtype/storm/spout/CheckPointState.java#L124-L140 |
25,160 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/daemon/worker/WorkerData.java | WorkerData.updateKryoSerializer | public void updateKryoSerializer() {
WorkerTopologyContext workerTopologyContext = contextMaker.makeWorkerTopologyContext(sysTopology);
KryoTupleDeserializer kryoTupleDeserializer = new KryoTupleDeserializer(stormConf, workerTopologyContext, workerTopologyContext.getRawTopology());
KryoTupleSerializer kryoTupleSerializer = new KryoTupleSerializer(stormConf, workerTopologyContext.getRawTopology());
atomKryoDeserializer.getAndSet(kryoTupleDeserializer);
atomKryoSerializer.getAndSet(kryoTupleSerializer);
} | java | public void updateKryoSerializer() {
WorkerTopologyContext workerTopologyContext = contextMaker.makeWorkerTopologyContext(sysTopology);
KryoTupleDeserializer kryoTupleDeserializer = new KryoTupleDeserializer(stormConf, workerTopologyContext, workerTopologyContext.getRawTopology());
KryoTupleSerializer kryoTupleSerializer = new KryoTupleSerializer(stormConf, workerTopologyContext.getRawTopology());
atomKryoDeserializer.getAndSet(kryoTupleDeserializer);
atomKryoSerializer.getAndSet(kryoTupleSerializer);
} | [
"public",
"void",
"updateKryoSerializer",
"(",
")",
"{",
"WorkerTopologyContext",
"workerTopologyContext",
"=",
"contextMaker",
".",
"makeWorkerTopologyContext",
"(",
"sysTopology",
")",
";",
"KryoTupleDeserializer",
"kryoTupleDeserializer",
"=",
"new",
"KryoTupleDeserializer",
"(",
"stormConf",
",",
"workerTopologyContext",
",",
"workerTopologyContext",
".",
"getRawTopology",
"(",
")",
")",
";",
"KryoTupleSerializer",
"kryoTupleSerializer",
"=",
"new",
"KryoTupleSerializer",
"(",
"stormConf",
",",
"workerTopologyContext",
".",
"getRawTopology",
"(",
")",
")",
";",
"atomKryoDeserializer",
".",
"getAndSet",
"(",
"kryoTupleDeserializer",
")",
";",
"atomKryoSerializer",
".",
"getAndSet",
"(",
"kryoTupleSerializer",
")",
";",
"}"
] | create kryo serializer | [
"create",
"kryo",
"serializer"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/daemon/worker/WorkerData.java#L470-L477 |
25,161 | alibaba/jstorm | jstorm-utility/transaction_meta_spout/src/main/java/com/alibaba/jstorm/batch/meta/MetaSimpleClient.java | MetaSimpleClient.rebalanceMqList | public void rebalanceMqList() throws Exception {
LOG.info("Begin to do rebalance operation");
Set<MessageQueue> newMqs = getMQ();
Set<MessageQueue> oldMqs = currentOffsets.keySet();
if (oldMqs.equals(newMqs) == true) {
LOG.info("No change of meta queues " + newMqs);
return ;
}
Set<MessageQueue> removeMqs = new HashSet<MessageQueue>();
removeMqs.addAll(oldMqs);
removeMqs.removeAll(newMqs);
Set<MessageQueue> addMqs = new HashSet<MessageQueue>();
addMqs.addAll(newMqs);
addMqs.removeAll(oldMqs);
LOG.info("Remove " + removeMqs);
for (MessageQueue mq : removeMqs) {
Long offset = frontOffsets.remove(mq);
updateOffsetToZk(mq, offset);
backendOffset.remove(mq);
}
LOG.info("Add " + addMqs);
for (MessageQueue mq : addMqs) {
long offset = getOffsetFromZk(mq);
frontOffsets.put(mq, offset);
backendOffset.put(mq, offset);
}
} | java | public void rebalanceMqList() throws Exception {
LOG.info("Begin to do rebalance operation");
Set<MessageQueue> newMqs = getMQ();
Set<MessageQueue> oldMqs = currentOffsets.keySet();
if (oldMqs.equals(newMqs) == true) {
LOG.info("No change of meta queues " + newMqs);
return ;
}
Set<MessageQueue> removeMqs = new HashSet<MessageQueue>();
removeMqs.addAll(oldMqs);
removeMqs.removeAll(newMqs);
Set<MessageQueue> addMqs = new HashSet<MessageQueue>();
addMqs.addAll(newMqs);
addMqs.removeAll(oldMqs);
LOG.info("Remove " + removeMqs);
for (MessageQueue mq : removeMqs) {
Long offset = frontOffsets.remove(mq);
updateOffsetToZk(mq, offset);
backendOffset.remove(mq);
}
LOG.info("Add " + addMqs);
for (MessageQueue mq : addMqs) {
long offset = getOffsetFromZk(mq);
frontOffsets.put(mq, offset);
backendOffset.put(mq, offset);
}
} | [
"public",
"void",
"rebalanceMqList",
"(",
")",
"throws",
"Exception",
"{",
"LOG",
".",
"info",
"(",
"\"Begin to do rebalance operation\"",
")",
";",
"Set",
"<",
"MessageQueue",
">",
"newMqs",
"=",
"getMQ",
"(",
")",
";",
"Set",
"<",
"MessageQueue",
">",
"oldMqs",
"=",
"currentOffsets",
".",
"keySet",
"(",
")",
";",
"if",
"(",
"oldMqs",
".",
"equals",
"(",
"newMqs",
")",
"==",
"true",
")",
"{",
"LOG",
".",
"info",
"(",
"\"No change of meta queues \"",
"+",
"newMqs",
")",
";",
"return",
";",
"}",
"Set",
"<",
"MessageQueue",
">",
"removeMqs",
"=",
"new",
"HashSet",
"<",
"MessageQueue",
">",
"(",
")",
";",
"removeMqs",
".",
"addAll",
"(",
"oldMqs",
")",
";",
"removeMqs",
".",
"removeAll",
"(",
"newMqs",
")",
";",
"Set",
"<",
"MessageQueue",
">",
"addMqs",
"=",
"new",
"HashSet",
"<",
"MessageQueue",
">",
"(",
")",
";",
"addMqs",
".",
"addAll",
"(",
"newMqs",
")",
";",
"addMqs",
".",
"removeAll",
"(",
"oldMqs",
")",
";",
"LOG",
".",
"info",
"(",
"\"Remove \"",
"+",
"removeMqs",
")",
";",
"for",
"(",
"MessageQueue",
"mq",
":",
"removeMqs",
")",
"{",
"Long",
"offset",
"=",
"frontOffsets",
".",
"remove",
"(",
"mq",
")",
";",
"updateOffsetToZk",
"(",
"mq",
",",
"offset",
")",
";",
"backendOffset",
".",
"remove",
"(",
"mq",
")",
";",
"}",
"LOG",
".",
"info",
"(",
"\"Add \"",
"+",
"addMqs",
")",
";",
"for",
"(",
"MessageQueue",
"mq",
":",
"addMqs",
")",
"{",
"long",
"offset",
"=",
"getOffsetFromZk",
"(",
"mq",
")",
";",
"frontOffsets",
".",
"put",
"(",
"mq",
",",
"offset",
")",
";",
"backendOffset",
".",
"put",
"(",
"mq",
",",
"offset",
")",
";",
"}",
"}"
] | rebalanceMqList must run after commit
@throws MQClientException | [
"rebalanceMqList",
"must",
"run",
"after",
"commit"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-utility/transaction_meta_spout/src/main/java/com/alibaba/jstorm/batch/meta/MetaSimpleClient.java#L270-L304 |
25,162 | alibaba/jstorm | jstorm-utility/jstorm-flux/flux-core/src/main/java/com/alibaba/jstorm/flux/model/TopologyDef.java | TopologyDef.addAllBolts | public void addAllBolts(List<BoltDef> bolts, boolean override){
for(BoltDef bolt : bolts){
String id = bolt.getId();
if(this.boltMap.get(id) == null || override) {
this.boltMap.put(bolt.getId(), bolt);
} else {
LOG.warn("Ignoring attempt to create bolt '{}' with override == false.", id);
}
}
} | java | public void addAllBolts(List<BoltDef> bolts, boolean override){
for(BoltDef bolt : bolts){
String id = bolt.getId();
if(this.boltMap.get(id) == null || override) {
this.boltMap.put(bolt.getId(), bolt);
} else {
LOG.warn("Ignoring attempt to create bolt '{}' with override == false.", id);
}
}
} | [
"public",
"void",
"addAllBolts",
"(",
"List",
"<",
"BoltDef",
">",
"bolts",
",",
"boolean",
"override",
")",
"{",
"for",
"(",
"BoltDef",
"bolt",
":",
"bolts",
")",
"{",
"String",
"id",
"=",
"bolt",
".",
"getId",
"(",
")",
";",
"if",
"(",
"this",
".",
"boltMap",
".",
"get",
"(",
"id",
")",
"==",
"null",
"||",
"override",
")",
"{",
"this",
".",
"boltMap",
".",
"put",
"(",
"bolt",
".",
"getId",
"(",
")",
",",
"bolt",
")",
";",
"}",
"else",
"{",
"LOG",
".",
"warn",
"(",
"\"Ignoring attempt to create bolt '{}' with override == false.\"",
",",
"id",
")",
";",
"}",
"}",
"}"
] | used by includes implementation | [
"used",
"by",
"includes",
"implementation"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-utility/jstorm-flux/flux-core/src/main/java/com/alibaba/jstorm/flux/model/TopologyDef.java#L150-L159 |
25,163 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/window/EventTimeTrigger.java | EventTimeTrigger.onElement | @Override
public TriggerResult onElement(Object element, long timestamp, TimeWindow window, TriggerContext ctx) {
ctx.registerEventTimeTimer(window.getEnd() + ctx.getMaxLagMs(), window);
return TriggerResult.CONTINUE;
} | java | @Override
public TriggerResult onElement(Object element, long timestamp, TimeWindow window, TriggerContext ctx) {
ctx.registerEventTimeTimer(window.getEnd() + ctx.getMaxLagMs(), window);
return TriggerResult.CONTINUE;
} | [
"@",
"Override",
"public",
"TriggerResult",
"onElement",
"(",
"Object",
"element",
",",
"long",
"timestamp",
",",
"TimeWindow",
"window",
",",
"TriggerContext",
"ctx",
")",
"{",
"ctx",
".",
"registerEventTimeTimer",
"(",
"window",
".",
"getEnd",
"(",
")",
"+",
"ctx",
".",
"getMaxLagMs",
"(",
")",
",",
"window",
")",
";",
"return",
"TriggerResult",
".",
"CONTINUE",
";",
"}"
] | If a watermark arrives, we need to check all pending windows.
If any of the pending window suffices, we should fire immediately by registering a timer without delay.
Otherwise we register a timer whose time is the window end plus max lag time | [
"If",
"a",
"watermark",
"arrives",
"we",
"need",
"to",
"check",
"all",
"pending",
"windows",
".",
"If",
"any",
"of",
"the",
"pending",
"window",
"suffices",
"we",
"should",
"fire",
"immediately",
"by",
"registering",
"a",
"timer",
"without",
"delay",
".",
"Otherwise",
"we",
"register",
"a",
"timer",
"whose",
"time",
"is",
"the",
"window",
"end",
"plus",
"max",
"lag",
"time"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/window/EventTimeTrigger.java#L32-L36 |
25,164 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/cluster/StormConfig.java | StormConfig.drpcPids | public static String drpcPids(Map conf) throws IOException {
String ret = drpc_local_dir(conf) + FILE_SEPERATEOR + "pids";
try {
FileUtils.forceMkdir(new File(ret));
} catch (IOException e) {
LOG.error("Failed to create dir " + ret, e);
throw e;
}
return ret;
} | java | public static String drpcPids(Map conf) throws IOException {
String ret = drpc_local_dir(conf) + FILE_SEPERATEOR + "pids";
try {
FileUtils.forceMkdir(new File(ret));
} catch (IOException e) {
LOG.error("Failed to create dir " + ret, e);
throw e;
}
return ret;
} | [
"public",
"static",
"String",
"drpcPids",
"(",
"Map",
"conf",
")",
"throws",
"IOException",
"{",
"String",
"ret",
"=",
"drpc_local_dir",
"(",
"conf",
")",
"+",
"FILE_SEPERATEOR",
"+",
"\"pids\"",
";",
"try",
"{",
"FileUtils",
".",
"forceMkdir",
"(",
"new",
"File",
"(",
"ret",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"LOG",
".",
"error",
"(",
"\"Failed to create dir \"",
"+",
"ret",
",",
"e",
")",
";",
"throw",
"e",
";",
"}",
"return",
"ret",
";",
"}"
] | Return drpc's pid dir | [
"Return",
"drpc",
"s",
"pid",
"dir"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/cluster/StormConfig.java#L224-L233 |
25,165 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/cluster/StormConfig.java | StormConfig.read_supervisor_topology_conf | public static Map read_supervisor_topology_conf(Map conf, String topologyId) throws IOException {
String topologyRoot = StormConfig.supervisor_stormdist_root(conf, topologyId);
String confPath = StormConfig.stormconf_path(topologyRoot);
return (Map) readLocalObject(topologyId, confPath);
} | java | public static Map read_supervisor_topology_conf(Map conf, String topologyId) throws IOException {
String topologyRoot = StormConfig.supervisor_stormdist_root(conf, topologyId);
String confPath = StormConfig.stormconf_path(topologyRoot);
return (Map) readLocalObject(topologyId, confPath);
} | [
"public",
"static",
"Map",
"read_supervisor_topology_conf",
"(",
"Map",
"conf",
",",
"String",
"topologyId",
")",
"throws",
"IOException",
"{",
"String",
"topologyRoot",
"=",
"StormConfig",
".",
"supervisor_stormdist_root",
"(",
"conf",
",",
"topologyId",
")",
";",
"String",
"confPath",
"=",
"StormConfig",
".",
"stormconf_path",
"(",
"topologyRoot",
")",
";",
"return",
"(",
"Map",
")",
"readLocalObject",
"(",
"topologyId",
",",
"confPath",
")",
";",
"}"
] | merge storm conf into cluster conf | [
"merge",
"storm",
"conf",
"into",
"cluster",
"conf"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/cluster/StormConfig.java#L449-L453 |
25,166 | alibaba/jstorm | jstorm-core/src/main/java/backtype/storm/scheduler/multitenant/IsolatedPool.java | IsolatedPool.getNodesForIsolatedTop | private int getNodesForIsolatedTop(TopologyDetails td, Set<Node> allNodes, NodePool[] lesserPools, int nodesRequested) {
String topId = td.getId();
LOG.debug("Topology {} is isolated", topId);
int nodesFromUsAvailable = nodesAvailable();
int nodesFromOthersAvailable = NodePool.nodesAvailable(lesserPools);
int nodesUsed = _topologyIdToNodes.get(topId).size();
int nodesNeeded = nodesRequested - nodesUsed;
LOG.debug("Nodes... requested {} used {} available from us {} " + "avail from other {} needed {}",
new Object[]{nodesRequested, nodesUsed, nodesFromUsAvailable, nodesFromOthersAvailable, nodesNeeded});
if ((nodesNeeded - nodesFromUsAvailable) > (_maxNodes - _usedNodes)) {
_cluster.setStatus(topId, "Max Nodes(" + _maxNodes + ") for this user would be exceeded. "
+ ((nodesNeeded - nodesFromUsAvailable) - (_maxNodes - _usedNodes)) + " more nodes needed to run topology.");
return 0;
}
// In order to avoid going over _maxNodes I may need to steal from
// myself even though other pools have free nodes. so figure out how
// much each group should provide
int nodesNeededFromOthers = Math.min(Math.min(_maxNodes - _usedNodes, nodesFromOthersAvailable), nodesNeeded);
int nodesNeededFromUs = nodesNeeded - nodesNeededFromOthers;
LOG.debug("Nodes... needed from us {} needed from others {}", nodesNeededFromUs, nodesNeededFromOthers);
if (nodesNeededFromUs > nodesFromUsAvailable) {
_cluster.setStatus(topId, "Not Enough Nodes Available to Schedule Topology");
return 0;
}
// Get the nodes
Collection<Node> found = NodePool.takeNodes(nodesNeededFromOthers, lesserPools);
_usedNodes += found.size();
allNodes.addAll(found);
Collection<Node> foundMore = takeNodes(nodesNeededFromUs);
_usedNodes += foundMore.size();
allNodes.addAll(foundMore);
int totalTasks = td.getExecutors().size();
int origRequest = td.getNumWorkers();
int slotsRequested = Math.min(totalTasks, origRequest);
int slotsUsed = Node.countSlotsUsed(allNodes);
int slotsFree = Node.countFreeSlotsAlive(allNodes);
int slotsToUse = Math.min(slotsRequested - slotsUsed, slotsFree);
if (slotsToUse <= 0) {
_cluster.setStatus(topId, "Node has partially crashed, if this situation persists rebalance the topology.");
}
return slotsToUse;
} | java | private int getNodesForIsolatedTop(TopologyDetails td, Set<Node> allNodes, NodePool[] lesserPools, int nodesRequested) {
String topId = td.getId();
LOG.debug("Topology {} is isolated", topId);
int nodesFromUsAvailable = nodesAvailable();
int nodesFromOthersAvailable = NodePool.nodesAvailable(lesserPools);
int nodesUsed = _topologyIdToNodes.get(topId).size();
int nodesNeeded = nodesRequested - nodesUsed;
LOG.debug("Nodes... requested {} used {} available from us {} " + "avail from other {} needed {}",
new Object[]{nodesRequested, nodesUsed, nodesFromUsAvailable, nodesFromOthersAvailable, nodesNeeded});
if ((nodesNeeded - nodesFromUsAvailable) > (_maxNodes - _usedNodes)) {
_cluster.setStatus(topId, "Max Nodes(" + _maxNodes + ") for this user would be exceeded. "
+ ((nodesNeeded - nodesFromUsAvailable) - (_maxNodes - _usedNodes)) + " more nodes needed to run topology.");
return 0;
}
// In order to avoid going over _maxNodes I may need to steal from
// myself even though other pools have free nodes. so figure out how
// much each group should provide
int nodesNeededFromOthers = Math.min(Math.min(_maxNodes - _usedNodes, nodesFromOthersAvailable), nodesNeeded);
int nodesNeededFromUs = nodesNeeded - nodesNeededFromOthers;
LOG.debug("Nodes... needed from us {} needed from others {}", nodesNeededFromUs, nodesNeededFromOthers);
if (nodesNeededFromUs > nodesFromUsAvailable) {
_cluster.setStatus(topId, "Not Enough Nodes Available to Schedule Topology");
return 0;
}
// Get the nodes
Collection<Node> found = NodePool.takeNodes(nodesNeededFromOthers, lesserPools);
_usedNodes += found.size();
allNodes.addAll(found);
Collection<Node> foundMore = takeNodes(nodesNeededFromUs);
_usedNodes += foundMore.size();
allNodes.addAll(foundMore);
int totalTasks = td.getExecutors().size();
int origRequest = td.getNumWorkers();
int slotsRequested = Math.min(totalTasks, origRequest);
int slotsUsed = Node.countSlotsUsed(allNodes);
int slotsFree = Node.countFreeSlotsAlive(allNodes);
int slotsToUse = Math.min(slotsRequested - slotsUsed, slotsFree);
if (slotsToUse <= 0) {
_cluster.setStatus(topId, "Node has partially crashed, if this situation persists rebalance the topology.");
}
return slotsToUse;
} | [
"private",
"int",
"getNodesForIsolatedTop",
"(",
"TopologyDetails",
"td",
",",
"Set",
"<",
"Node",
">",
"allNodes",
",",
"NodePool",
"[",
"]",
"lesserPools",
",",
"int",
"nodesRequested",
")",
"{",
"String",
"topId",
"=",
"td",
".",
"getId",
"(",
")",
";",
"LOG",
".",
"debug",
"(",
"\"Topology {} is isolated\"",
",",
"topId",
")",
";",
"int",
"nodesFromUsAvailable",
"=",
"nodesAvailable",
"(",
")",
";",
"int",
"nodesFromOthersAvailable",
"=",
"NodePool",
".",
"nodesAvailable",
"(",
"lesserPools",
")",
";",
"int",
"nodesUsed",
"=",
"_topologyIdToNodes",
".",
"get",
"(",
"topId",
")",
".",
"size",
"(",
")",
";",
"int",
"nodesNeeded",
"=",
"nodesRequested",
"-",
"nodesUsed",
";",
"LOG",
".",
"debug",
"(",
"\"Nodes... requested {} used {} available from us {} \"",
"+",
"\"avail from other {} needed {}\"",
",",
"new",
"Object",
"[",
"]",
"{",
"nodesRequested",
",",
"nodesUsed",
",",
"nodesFromUsAvailable",
",",
"nodesFromOthersAvailable",
",",
"nodesNeeded",
"}",
")",
";",
"if",
"(",
"(",
"nodesNeeded",
"-",
"nodesFromUsAvailable",
")",
">",
"(",
"_maxNodes",
"-",
"_usedNodes",
")",
")",
"{",
"_cluster",
".",
"setStatus",
"(",
"topId",
",",
"\"Max Nodes(\"",
"+",
"_maxNodes",
"+",
"\") for this user would be exceeded. \"",
"+",
"(",
"(",
"nodesNeeded",
"-",
"nodesFromUsAvailable",
")",
"-",
"(",
"_maxNodes",
"-",
"_usedNodes",
")",
")",
"+",
"\" more nodes needed to run topology.\"",
")",
";",
"return",
"0",
";",
"}",
"// In order to avoid going over _maxNodes I may need to steal from",
"// myself even though other pools have free nodes. so figure out how",
"// much each group should provide",
"int",
"nodesNeededFromOthers",
"=",
"Math",
".",
"min",
"(",
"Math",
".",
"min",
"(",
"_maxNodes",
"-",
"_usedNodes",
",",
"nodesFromOthersAvailable",
")",
",",
"nodesNeeded",
")",
";",
"int",
"nodesNeededFromUs",
"=",
"nodesNeeded",
"-",
"nodesNeededFromOthers",
";",
"LOG",
".",
"debug",
"(",
"\"Nodes... needed from us {} needed from others {}\"",
",",
"nodesNeededFromUs",
",",
"nodesNeededFromOthers",
")",
";",
"if",
"(",
"nodesNeededFromUs",
">",
"nodesFromUsAvailable",
")",
"{",
"_cluster",
".",
"setStatus",
"(",
"topId",
",",
"\"Not Enough Nodes Available to Schedule Topology\"",
")",
";",
"return",
"0",
";",
"}",
"// Get the nodes",
"Collection",
"<",
"Node",
">",
"found",
"=",
"NodePool",
".",
"takeNodes",
"(",
"nodesNeededFromOthers",
",",
"lesserPools",
")",
";",
"_usedNodes",
"+=",
"found",
".",
"size",
"(",
")",
";",
"allNodes",
".",
"addAll",
"(",
"found",
")",
";",
"Collection",
"<",
"Node",
">",
"foundMore",
"=",
"takeNodes",
"(",
"nodesNeededFromUs",
")",
";",
"_usedNodes",
"+=",
"foundMore",
".",
"size",
"(",
")",
";",
"allNodes",
".",
"addAll",
"(",
"foundMore",
")",
";",
"int",
"totalTasks",
"=",
"td",
".",
"getExecutors",
"(",
")",
".",
"size",
"(",
")",
";",
"int",
"origRequest",
"=",
"td",
".",
"getNumWorkers",
"(",
")",
";",
"int",
"slotsRequested",
"=",
"Math",
".",
"min",
"(",
"totalTasks",
",",
"origRequest",
")",
";",
"int",
"slotsUsed",
"=",
"Node",
".",
"countSlotsUsed",
"(",
"allNodes",
")",
";",
"int",
"slotsFree",
"=",
"Node",
".",
"countFreeSlotsAlive",
"(",
"allNodes",
")",
";",
"int",
"slotsToUse",
"=",
"Math",
".",
"min",
"(",
"slotsRequested",
"-",
"slotsUsed",
",",
"slotsFree",
")",
";",
"if",
"(",
"slotsToUse",
"<=",
"0",
")",
"{",
"_cluster",
".",
"setStatus",
"(",
"topId",
",",
"\"Node has partially crashed, if this situation persists rebalance the topology.\"",
")",
";",
"}",
"return",
"slotsToUse",
";",
"}"
] | Get the nodes needed to schedule an isolated topology.
@param td the topology to be scheduled
@param allNodes the nodes already scheduled for this topology. This will be updated to include new nodes if needed.
@param lesserPools node pools we can steal nodes from
@return the number of additional slots that should be used for scheduling. | [
"Get",
"the",
"nodes",
"needed",
"to",
"schedule",
"an",
"isolated",
"topology",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/backtype/storm/scheduler/multitenant/IsolatedPool.java#L146-L192 |
25,167 | alibaba/jstorm | jstorm-core/src/main/java/backtype/storm/scheduler/multitenant/IsolatedPool.java | IsolatedPool.getNodesForNotIsolatedTop | private int getNodesForNotIsolatedTop(TopologyDetails td, Set<Node> allNodes, NodePool[] lesserPools) {
String topId = td.getId();
LOG.debug("Topology {} is not isolated", topId);
int totalTasks = td.getExecutors().size();
int origRequest = td.getNumWorkers();
int slotsRequested = Math.min(totalTasks, origRequest);
int slotsUsed = Node.countSlotsUsed(topId, allNodes);
int slotsFree = Node.countFreeSlotsAlive(allNodes);
// Check to see if we have enough slots before trying to get them
int slotsAvailable = 0;
if (slotsRequested > slotsFree) {
slotsAvailable = NodePool.slotsAvailable(lesserPools);
}
int slotsToUse = Math.min(slotsRequested - slotsUsed, slotsFree + slotsAvailable);
LOG.debug("Slots... requested {} used {} free {} available {} to be used {}",
new Object[]{slotsRequested, slotsUsed, slotsFree, slotsAvailable, slotsToUse});
if (slotsToUse <= 0) {
_cluster.setStatus(topId, "Not Enough Slots Available to Schedule Topology");
return 0;
}
int slotsNeeded = slotsToUse - slotsFree;
int numNewNodes = NodePool.getNodeCountIfSlotsWereTaken(slotsNeeded, lesserPools);
LOG.debug("Nodes... new {} used {} max {}", new Object[]{numNewNodes, _usedNodes, _maxNodes});
if ((numNewNodes + _usedNodes) > _maxNodes) {
_cluster.setStatus(topId, "Max Nodes(" + _maxNodes + ") for this user would be exceeded. " + (numNewNodes - (_maxNodes - _usedNodes))
+ " more nodes needed to run topology.");
return 0;
}
Collection<Node> found = NodePool.takeNodesBySlot(slotsNeeded, lesserPools);
_usedNodes += found.size();
allNodes.addAll(found);
return slotsToUse;
} | java | private int getNodesForNotIsolatedTop(TopologyDetails td, Set<Node> allNodes, NodePool[] lesserPools) {
String topId = td.getId();
LOG.debug("Topology {} is not isolated", topId);
int totalTasks = td.getExecutors().size();
int origRequest = td.getNumWorkers();
int slotsRequested = Math.min(totalTasks, origRequest);
int slotsUsed = Node.countSlotsUsed(topId, allNodes);
int slotsFree = Node.countFreeSlotsAlive(allNodes);
// Check to see if we have enough slots before trying to get them
int slotsAvailable = 0;
if (slotsRequested > slotsFree) {
slotsAvailable = NodePool.slotsAvailable(lesserPools);
}
int slotsToUse = Math.min(slotsRequested - slotsUsed, slotsFree + slotsAvailable);
LOG.debug("Slots... requested {} used {} free {} available {} to be used {}",
new Object[]{slotsRequested, slotsUsed, slotsFree, slotsAvailable, slotsToUse});
if (slotsToUse <= 0) {
_cluster.setStatus(topId, "Not Enough Slots Available to Schedule Topology");
return 0;
}
int slotsNeeded = slotsToUse - slotsFree;
int numNewNodes = NodePool.getNodeCountIfSlotsWereTaken(slotsNeeded, lesserPools);
LOG.debug("Nodes... new {} used {} max {}", new Object[]{numNewNodes, _usedNodes, _maxNodes});
if ((numNewNodes + _usedNodes) > _maxNodes) {
_cluster.setStatus(topId, "Max Nodes(" + _maxNodes + ") for this user would be exceeded. " + (numNewNodes - (_maxNodes - _usedNodes))
+ " more nodes needed to run topology.");
return 0;
}
Collection<Node> found = NodePool.takeNodesBySlot(slotsNeeded, lesserPools);
_usedNodes += found.size();
allNodes.addAll(found);
return slotsToUse;
} | [
"private",
"int",
"getNodesForNotIsolatedTop",
"(",
"TopologyDetails",
"td",
",",
"Set",
"<",
"Node",
">",
"allNodes",
",",
"NodePool",
"[",
"]",
"lesserPools",
")",
"{",
"String",
"topId",
"=",
"td",
".",
"getId",
"(",
")",
";",
"LOG",
".",
"debug",
"(",
"\"Topology {} is not isolated\"",
",",
"topId",
")",
";",
"int",
"totalTasks",
"=",
"td",
".",
"getExecutors",
"(",
")",
".",
"size",
"(",
")",
";",
"int",
"origRequest",
"=",
"td",
".",
"getNumWorkers",
"(",
")",
";",
"int",
"slotsRequested",
"=",
"Math",
".",
"min",
"(",
"totalTasks",
",",
"origRequest",
")",
";",
"int",
"slotsUsed",
"=",
"Node",
".",
"countSlotsUsed",
"(",
"topId",
",",
"allNodes",
")",
";",
"int",
"slotsFree",
"=",
"Node",
".",
"countFreeSlotsAlive",
"(",
"allNodes",
")",
";",
"// Check to see if we have enough slots before trying to get them",
"int",
"slotsAvailable",
"=",
"0",
";",
"if",
"(",
"slotsRequested",
">",
"slotsFree",
")",
"{",
"slotsAvailable",
"=",
"NodePool",
".",
"slotsAvailable",
"(",
"lesserPools",
")",
";",
"}",
"int",
"slotsToUse",
"=",
"Math",
".",
"min",
"(",
"slotsRequested",
"-",
"slotsUsed",
",",
"slotsFree",
"+",
"slotsAvailable",
")",
";",
"LOG",
".",
"debug",
"(",
"\"Slots... requested {} used {} free {} available {} to be used {}\"",
",",
"new",
"Object",
"[",
"]",
"{",
"slotsRequested",
",",
"slotsUsed",
",",
"slotsFree",
",",
"slotsAvailable",
",",
"slotsToUse",
"}",
")",
";",
"if",
"(",
"slotsToUse",
"<=",
"0",
")",
"{",
"_cluster",
".",
"setStatus",
"(",
"topId",
",",
"\"Not Enough Slots Available to Schedule Topology\"",
")",
";",
"return",
"0",
";",
"}",
"int",
"slotsNeeded",
"=",
"slotsToUse",
"-",
"slotsFree",
";",
"int",
"numNewNodes",
"=",
"NodePool",
".",
"getNodeCountIfSlotsWereTaken",
"(",
"slotsNeeded",
",",
"lesserPools",
")",
";",
"LOG",
".",
"debug",
"(",
"\"Nodes... new {} used {} max {}\"",
",",
"new",
"Object",
"[",
"]",
"{",
"numNewNodes",
",",
"_usedNodes",
",",
"_maxNodes",
"}",
")",
";",
"if",
"(",
"(",
"numNewNodes",
"+",
"_usedNodes",
")",
">",
"_maxNodes",
")",
"{",
"_cluster",
".",
"setStatus",
"(",
"topId",
",",
"\"Max Nodes(\"",
"+",
"_maxNodes",
"+",
"\") for this user would be exceeded. \"",
"+",
"(",
"numNewNodes",
"-",
"(",
"_maxNodes",
"-",
"_usedNodes",
")",
")",
"+",
"\" more nodes needed to run topology.\"",
")",
";",
"return",
"0",
";",
"}",
"Collection",
"<",
"Node",
">",
"found",
"=",
"NodePool",
".",
"takeNodesBySlot",
"(",
"slotsNeeded",
",",
"lesserPools",
")",
";",
"_usedNodes",
"+=",
"found",
".",
"size",
"(",
")",
";",
"allNodes",
".",
"addAll",
"(",
"found",
")",
";",
"return",
"slotsToUse",
";",
"}"
] | Get the nodes needed to schedule a non-isolated topology.
@param td the topology to be scheduled
@param allNodes the nodes already scheduled for this topology. This will be updated to include new nodes if needed.
@param lesserPools node pools we can steal nodes from
@return the number of additional slots that should be used for scheduling. | [
"Get",
"the",
"nodes",
"needed",
"to",
"schedule",
"a",
"non",
"-",
"isolated",
"topology",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/backtype/storm/scheduler/multitenant/IsolatedPool.java#L202-L235 |
25,168 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/message/netty/MessageBatch.java | MessageBatch.tryAdd | boolean tryAdd(TaskMessage taskMsg) {
if ((encodedLength + msgEncodeLength(taskMsg)) > buffer_size)
return false;
add(taskMsg);
return true;
} | java | boolean tryAdd(TaskMessage taskMsg) {
if ((encodedLength + msgEncodeLength(taskMsg)) > buffer_size)
return false;
add(taskMsg);
return true;
} | [
"boolean",
"tryAdd",
"(",
"TaskMessage",
"taskMsg",
")",
"{",
"if",
"(",
"(",
"encodedLength",
"+",
"msgEncodeLength",
"(",
"taskMsg",
")",
")",
">",
"buffer_size",
")",
"return",
"false",
";",
"add",
"(",
"taskMsg",
")",
";",
"return",
"true",
";",
"}"
] | try to add a TaskMessage to a batch
@param taskMsg task message
@return false if the msg could not be added due to buffer size limit; true otherwise | [
"try",
"to",
"add",
"a",
"TaskMessage",
"to",
"a",
"batch"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/message/netty/MessageBatch.java#L129-L134 |
25,169 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/message/netty/MessageBatch.java | MessageBatch.writeTaskMessage | private void writeTaskMessage(ChannelBufferOutputStream bout, TaskMessage message) throws Exception {
int payload_len = 0;
if (message.message() != null)
payload_len = message.message().length;
short type = message.get_type();
bout.writeShort(type);
int task_id = message.task();
if (task_id > Short.MAX_VALUE)
throw new RuntimeException("Task ID should not exceed " + Short.MAX_VALUE);
bout.writeShort((short) task_id);
bout.writeInt(payload_len);
if (payload_len > 0)
bout.write(message.message());
// LOG.info("Write one message taskid:{}, len:{}, data:{}", taskId
// , payload_len, JStormUtils.toPrintableString(message.message()) );
} | java | private void writeTaskMessage(ChannelBufferOutputStream bout, TaskMessage message) throws Exception {
int payload_len = 0;
if (message.message() != null)
payload_len = message.message().length;
short type = message.get_type();
bout.writeShort(type);
int task_id = message.task();
if (task_id > Short.MAX_VALUE)
throw new RuntimeException("Task ID should not exceed " + Short.MAX_VALUE);
bout.writeShort((short) task_id);
bout.writeInt(payload_len);
if (payload_len > 0)
bout.write(message.message());
// LOG.info("Write one message taskid:{}, len:{}, data:{}", taskId
// , payload_len, JStormUtils.toPrintableString(message.message()) );
} | [
"private",
"void",
"writeTaskMessage",
"(",
"ChannelBufferOutputStream",
"bout",
",",
"TaskMessage",
"message",
")",
"throws",
"Exception",
"{",
"int",
"payload_len",
"=",
"0",
";",
"if",
"(",
"message",
".",
"message",
"(",
")",
"!=",
"null",
")",
"payload_len",
"=",
"message",
".",
"message",
"(",
")",
".",
"length",
";",
"short",
"type",
"=",
"message",
".",
"get_type",
"(",
")",
";",
"bout",
".",
"writeShort",
"(",
"type",
")",
";",
"int",
"task_id",
"=",
"message",
".",
"task",
"(",
")",
";",
"if",
"(",
"task_id",
">",
"Short",
".",
"MAX_VALUE",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"Task ID should not exceed \"",
"+",
"Short",
".",
"MAX_VALUE",
")",
";",
"bout",
".",
"writeShort",
"(",
"(",
"short",
")",
"task_id",
")",
";",
"bout",
".",
"writeInt",
"(",
"payload_len",
")",
";",
"if",
"(",
"payload_len",
">",
"0",
")",
"bout",
".",
"write",
"(",
"message",
".",
"message",
"(",
")",
")",
";",
"// LOG.info(\"Write one message taskid:{}, len:{}, data:{}\", taskId",
"// , payload_len, JStormUtils.toPrintableString(message.message()) );",
"}"
] | write a TaskMessage into a stream
Each TaskMessage is encoded as: task ... short(2) len ... int(4) payload ... byte[] * | [
"write",
"a",
"TaskMessage",
"into",
"a",
"stream"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/message/netty/MessageBatch.java#L205-L224 |
25,170 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/ClientBlobStore.java | ClientBlobStore.createBlob | public final AtomicOutputStream createBlob(String key, SettableBlobMeta meta) throws KeyAlreadyExistsException {
return createBlobToExtend(key, meta);
} | java | public final AtomicOutputStream createBlob(String key, SettableBlobMeta meta) throws KeyAlreadyExistsException {
return createBlobToExtend(key, meta);
} | [
"public",
"final",
"AtomicOutputStream",
"createBlob",
"(",
"String",
"key",
",",
"SettableBlobMeta",
"meta",
")",
"throws",
"KeyAlreadyExistsException",
"{",
"return",
"createBlobToExtend",
"(",
"key",
",",
"meta",
")",
";",
"}"
] | Client facing API to create a blob.
@param key blob key name.
@param meta contains ACL information.
@return AtomicOutputStream returns an output stream into which data can be written.
@throws AuthorizationException
@throws KeyAlreadyExistsException | [
"Client",
"facing",
"API",
"to",
"create",
"a",
"blob",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/ClientBlobStore.java#L157-L159 |
25,171 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/ClientBlobStore.java | ClientBlobStore.setBlobMeta | public final void setBlobMeta(String key, SettableBlobMeta meta) throws AuthorizationException, KeyNotFoundException {
setBlobMetaToExtend(key, meta);
} | java | public final void setBlobMeta(String key, SettableBlobMeta meta) throws AuthorizationException, KeyNotFoundException {
setBlobMetaToExtend(key, meta);
} | [
"public",
"final",
"void",
"setBlobMeta",
"(",
"String",
"key",
",",
"SettableBlobMeta",
"meta",
")",
"throws",
"AuthorizationException",
",",
"KeyNotFoundException",
"{",
"setBlobMetaToExtend",
"(",
"key",
",",
"meta",
")",
";",
"}"
] | Client facing API to set the metadata for a blob.
@param key blob key name.
@param meta contains ACL information.
@throws AuthorizationException
@throws KeyNotFoundException | [
"Client",
"facing",
"API",
"to",
"set",
"the",
"metadata",
"for",
"a",
"blob",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/ClientBlobStore.java#L168-L170 |
25,172 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java | BlobStoreUtils.downloadMissingBlob | public static boolean downloadMissingBlob(Map conf, BlobStore blobStore, String key, Set<NimbusInfo> nimbusInfos)
throws TTransportException {
NimbusClient client;
ReadableBlobMeta rbm;
ClientBlobStore remoteBlobStore;
InputStreamWithMeta in;
boolean isSuccess = false;
LOG.debug("Download blob NimbusInfos {}", nimbusInfos);
for (NimbusInfo nimbusInfo : nimbusInfos) {
if (isSuccess) {
break;
}
try {
client = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort(), null);
rbm = client.getClient().getBlobMeta(key);
remoteBlobStore = new NimbusBlobStore();
remoteBlobStore.setClient(conf, client);
in = remoteBlobStore.getBlob(key);
blobStore.createBlob(key, in, rbm.get_settable());
// if key already exists while creating the blob else update it
Iterator<String> keyIterator = blobStore.listKeys();
while (keyIterator.hasNext()) {
if (keyIterator.next().equals(key)) {
LOG.debug("Success creating key, {}", key);
isSuccess = true;
break;
}
}
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (KeyAlreadyExistsException kae) {
LOG.info("KeyAlreadyExistsException Key: {} {}", key, kae);
} catch (KeyNotFoundException knf) {
// Catching and logging KeyNotFoundException because, if
// there is a subsequent update and delete, the non-leader
// nimbodes might throw an exception.
LOG.info("KeyNotFoundException Key: {} {}", key, knf);
} catch (Exception exp) {
// Logging an exception while client is connecting
LOG.error("Exception ", exp);
}
}
if (!isSuccess) {
LOG.error("Could not download blob with key " + key);
}
return isSuccess;
} | java | public static boolean downloadMissingBlob(Map conf, BlobStore blobStore, String key, Set<NimbusInfo> nimbusInfos)
throws TTransportException {
NimbusClient client;
ReadableBlobMeta rbm;
ClientBlobStore remoteBlobStore;
InputStreamWithMeta in;
boolean isSuccess = false;
LOG.debug("Download blob NimbusInfos {}", nimbusInfos);
for (NimbusInfo nimbusInfo : nimbusInfos) {
if (isSuccess) {
break;
}
try {
client = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort(), null);
rbm = client.getClient().getBlobMeta(key);
remoteBlobStore = new NimbusBlobStore();
remoteBlobStore.setClient(conf, client);
in = remoteBlobStore.getBlob(key);
blobStore.createBlob(key, in, rbm.get_settable());
// if key already exists while creating the blob else update it
Iterator<String> keyIterator = blobStore.listKeys();
while (keyIterator.hasNext()) {
if (keyIterator.next().equals(key)) {
LOG.debug("Success creating key, {}", key);
isSuccess = true;
break;
}
}
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (KeyAlreadyExistsException kae) {
LOG.info("KeyAlreadyExistsException Key: {} {}", key, kae);
} catch (KeyNotFoundException knf) {
// Catching and logging KeyNotFoundException because, if
// there is a subsequent update and delete, the non-leader
// nimbodes might throw an exception.
LOG.info("KeyNotFoundException Key: {} {}", key, knf);
} catch (Exception exp) {
// Logging an exception while client is connecting
LOG.error("Exception ", exp);
}
}
if (!isSuccess) {
LOG.error("Could not download blob with key " + key);
}
return isSuccess;
} | [
"public",
"static",
"boolean",
"downloadMissingBlob",
"(",
"Map",
"conf",
",",
"BlobStore",
"blobStore",
",",
"String",
"key",
",",
"Set",
"<",
"NimbusInfo",
">",
"nimbusInfos",
")",
"throws",
"TTransportException",
"{",
"NimbusClient",
"client",
";",
"ReadableBlobMeta",
"rbm",
";",
"ClientBlobStore",
"remoteBlobStore",
";",
"InputStreamWithMeta",
"in",
";",
"boolean",
"isSuccess",
"=",
"false",
";",
"LOG",
".",
"debug",
"(",
"\"Download blob NimbusInfos {}\"",
",",
"nimbusInfos",
")",
";",
"for",
"(",
"NimbusInfo",
"nimbusInfo",
":",
"nimbusInfos",
")",
"{",
"if",
"(",
"isSuccess",
")",
"{",
"break",
";",
"}",
"try",
"{",
"client",
"=",
"new",
"NimbusClient",
"(",
"conf",
",",
"nimbusInfo",
".",
"getHost",
"(",
")",
",",
"nimbusInfo",
".",
"getPort",
"(",
")",
",",
"null",
")",
";",
"rbm",
"=",
"client",
".",
"getClient",
"(",
")",
".",
"getBlobMeta",
"(",
"key",
")",
";",
"remoteBlobStore",
"=",
"new",
"NimbusBlobStore",
"(",
")",
";",
"remoteBlobStore",
".",
"setClient",
"(",
"conf",
",",
"client",
")",
";",
"in",
"=",
"remoteBlobStore",
".",
"getBlob",
"(",
"key",
")",
";",
"blobStore",
".",
"createBlob",
"(",
"key",
",",
"in",
",",
"rbm",
".",
"get_settable",
"(",
")",
")",
";",
"// if key already exists while creating the blob else update it",
"Iterator",
"<",
"String",
">",
"keyIterator",
"=",
"blobStore",
".",
"listKeys",
"(",
")",
";",
"while",
"(",
"keyIterator",
".",
"hasNext",
"(",
")",
")",
"{",
"if",
"(",
"keyIterator",
".",
"next",
"(",
")",
".",
"equals",
"(",
"key",
")",
")",
"{",
"LOG",
".",
"debug",
"(",
"\"Success creating key, {}\"",
",",
"key",
")",
";",
"isSuccess",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"catch",
"(",
"IOException",
"exception",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"exception",
")",
";",
"}",
"catch",
"(",
"KeyAlreadyExistsException",
"kae",
")",
"{",
"LOG",
".",
"info",
"(",
"\"KeyAlreadyExistsException Key: {} {}\"",
",",
"key",
",",
"kae",
")",
";",
"}",
"catch",
"(",
"KeyNotFoundException",
"knf",
")",
"{",
"// Catching and logging KeyNotFoundException because, if",
"// there is a subsequent update and delete, the non-leader",
"// nimbodes might throw an exception.",
"LOG",
".",
"info",
"(",
"\"KeyNotFoundException Key: {} {}\"",
",",
"key",
",",
"knf",
")",
";",
"}",
"catch",
"(",
"Exception",
"exp",
")",
"{",
"// Logging an exception while client is connecting",
"LOG",
".",
"error",
"(",
"\"Exception \"",
",",
"exp",
")",
";",
"}",
"}",
"if",
"(",
"!",
"isSuccess",
")",
"{",
"LOG",
".",
"error",
"(",
"\"Could not download blob with key \"",
"+",
"key",
")",
";",
"}",
"return",
"isSuccess",
";",
"}"
] | Download missing blobs from potential nimbodes | [
"Download",
"missing",
"blobs",
"from",
"potential",
"nimbodes"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java#L124-L171 |
25,173 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java | BlobStoreUtils.downloadUpdatedBlob | public static boolean downloadUpdatedBlob(Map conf, BlobStore blobStore, String key, Set<NimbusInfo> nimbusInfos)
throws TTransportException {
NimbusClient client;
ClientBlobStore remoteBlobStore;
boolean isSuccess = false;
LOG.debug("Download blob NimbusInfos {}", nimbusInfos);
for (NimbusInfo nimbusInfo : nimbusInfos) {
if (isSuccess) {
break;
}
try {
client = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort(), null);
remoteBlobStore = new NimbusBlobStore();
remoteBlobStore.setClient(conf, client);
isSuccess = updateBlob(blobStore, key, remoteBlobStore.getBlob(key));
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (KeyNotFoundException knf) {
// Catching and logging KeyNotFoundException because, if
// there is a subsequent update and delete, the non-leader
// nimbodes might throw an exception.
LOG.info("KeyNotFoundException {}", knf);
} catch (Exception exp) {
// Logging an exception while client is connecting
LOG.error("Exception {}", exp);
}
}
if (!isSuccess) {
LOG.error("Could not update the blob with key" + key);
}
return isSuccess;
} | java | public static boolean downloadUpdatedBlob(Map conf, BlobStore blobStore, String key, Set<NimbusInfo> nimbusInfos)
throws TTransportException {
NimbusClient client;
ClientBlobStore remoteBlobStore;
boolean isSuccess = false;
LOG.debug("Download blob NimbusInfos {}", nimbusInfos);
for (NimbusInfo nimbusInfo : nimbusInfos) {
if (isSuccess) {
break;
}
try {
client = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort(), null);
remoteBlobStore = new NimbusBlobStore();
remoteBlobStore.setClient(conf, client);
isSuccess = updateBlob(blobStore, key, remoteBlobStore.getBlob(key));
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (KeyNotFoundException knf) {
// Catching and logging KeyNotFoundException because, if
// there is a subsequent update and delete, the non-leader
// nimbodes might throw an exception.
LOG.info("KeyNotFoundException {}", knf);
} catch (Exception exp) {
// Logging an exception while client is connecting
LOG.error("Exception {}", exp);
}
}
if (!isSuccess) {
LOG.error("Could not update the blob with key" + key);
}
return isSuccess;
} | [
"public",
"static",
"boolean",
"downloadUpdatedBlob",
"(",
"Map",
"conf",
",",
"BlobStore",
"blobStore",
",",
"String",
"key",
",",
"Set",
"<",
"NimbusInfo",
">",
"nimbusInfos",
")",
"throws",
"TTransportException",
"{",
"NimbusClient",
"client",
";",
"ClientBlobStore",
"remoteBlobStore",
";",
"boolean",
"isSuccess",
"=",
"false",
";",
"LOG",
".",
"debug",
"(",
"\"Download blob NimbusInfos {}\"",
",",
"nimbusInfos",
")",
";",
"for",
"(",
"NimbusInfo",
"nimbusInfo",
":",
"nimbusInfos",
")",
"{",
"if",
"(",
"isSuccess",
")",
"{",
"break",
";",
"}",
"try",
"{",
"client",
"=",
"new",
"NimbusClient",
"(",
"conf",
",",
"nimbusInfo",
".",
"getHost",
"(",
")",
",",
"nimbusInfo",
".",
"getPort",
"(",
")",
",",
"null",
")",
";",
"remoteBlobStore",
"=",
"new",
"NimbusBlobStore",
"(",
")",
";",
"remoteBlobStore",
".",
"setClient",
"(",
"conf",
",",
"client",
")",
";",
"isSuccess",
"=",
"updateBlob",
"(",
"blobStore",
",",
"key",
",",
"remoteBlobStore",
".",
"getBlob",
"(",
"key",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"exception",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"exception",
")",
";",
"}",
"catch",
"(",
"KeyNotFoundException",
"knf",
")",
"{",
"// Catching and logging KeyNotFoundException because, if",
"// there is a subsequent update and delete, the non-leader",
"// nimbodes might throw an exception.",
"LOG",
".",
"info",
"(",
"\"KeyNotFoundException {}\"",
",",
"knf",
")",
";",
"}",
"catch",
"(",
"Exception",
"exp",
")",
"{",
"// Logging an exception while client is connecting",
"LOG",
".",
"error",
"(",
"\"Exception {}\"",
",",
"exp",
")",
";",
"}",
"}",
"if",
"(",
"!",
"isSuccess",
")",
"{",
"LOG",
".",
"error",
"(",
"\"Could not update the blob with key\"",
"+",
"key",
")",
";",
"}",
"return",
"isSuccess",
";",
"}"
] | Download updated blobs from potential nimbodes | [
"Download",
"updated",
"blobs",
"from",
"potential",
"nimbodes"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java#L206-L238 |
25,174 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java | BlobStoreUtils.getKeyListFromBlobStore | public static List<String> getKeyListFromBlobStore(BlobStore blobStore) throws Exception {
Iterator<String> keys = blobStore.listKeys();
List<String> keyList = new ArrayList<String>();
if (keys != null) {
while (keys.hasNext()) {
keyList.add(keys.next());
}
}
LOG.debug("KeyList from blobstore {}", keyList);
return keyList;
} | java | public static List<String> getKeyListFromBlobStore(BlobStore blobStore) throws Exception {
Iterator<String> keys = blobStore.listKeys();
List<String> keyList = new ArrayList<String>();
if (keys != null) {
while (keys.hasNext()) {
keyList.add(keys.next());
}
}
LOG.debug("KeyList from blobstore {}", keyList);
return keyList;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"getKeyListFromBlobStore",
"(",
"BlobStore",
"blobStore",
")",
"throws",
"Exception",
"{",
"Iterator",
"<",
"String",
">",
"keys",
"=",
"blobStore",
".",
"listKeys",
"(",
")",
";",
"List",
"<",
"String",
">",
"keyList",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"if",
"(",
"keys",
"!=",
"null",
")",
"{",
"while",
"(",
"keys",
".",
"hasNext",
"(",
")",
")",
"{",
"keyList",
".",
"add",
"(",
"keys",
".",
"next",
"(",
")",
")",
";",
"}",
"}",
"LOG",
".",
"debug",
"(",
"\"KeyList from blobstore {}\"",
",",
"keyList",
")",
";",
"return",
"keyList",
";",
"}"
] | Get the list of keys from blobstore | [
"Get",
"the",
"list",
"of",
"keys",
"from",
"blobstore"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java#L241-L251 |
25,175 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java | BlobStoreUtils.filterAndListKeys | public static <R> Set<R> filterAndListKeys(Iterator<R> keys, KeyFilter<R> filter) {
Set<R> ret = new HashSet<R>();
while (keys.hasNext()) {
R key = keys.next();
R filtered = filter.filter(key);
if (filtered != null) {
ret.add(filtered);
}
}
return ret;
} | java | public static <R> Set<R> filterAndListKeys(Iterator<R> keys, KeyFilter<R> filter) {
Set<R> ret = new HashSet<R>();
while (keys.hasNext()) {
R key = keys.next();
R filtered = filter.filter(key);
if (filtered != null) {
ret.add(filtered);
}
}
return ret;
} | [
"public",
"static",
"<",
"R",
">",
"Set",
"<",
"R",
">",
"filterAndListKeys",
"(",
"Iterator",
"<",
"R",
">",
"keys",
",",
"KeyFilter",
"<",
"R",
">",
"filter",
")",
"{",
"Set",
"<",
"R",
">",
"ret",
"=",
"new",
"HashSet",
"<",
"R",
">",
"(",
")",
";",
"while",
"(",
"keys",
".",
"hasNext",
"(",
")",
")",
"{",
"R",
"key",
"=",
"keys",
".",
"next",
"(",
")",
";",
"R",
"filtered",
"=",
"filter",
".",
"filter",
"(",
"key",
")",
";",
"if",
"(",
"filtered",
"!=",
"null",
")",
"{",
"ret",
".",
"add",
"(",
"filtered",
")",
";",
"}",
"}",
"return",
"ret",
";",
"}"
] | Filters keys based on the KeyFilter
passed as the argument.
@param filter KeyFilter
@param <R> Type
@return Set of filtered keys | [
"Filters",
"keys",
"based",
"on",
"the",
"KeyFilter",
"passed",
"as",
"the",
"argument",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java#L449-L459 |
25,176 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java | BlobStoreUtils.cleanup_key | public static void cleanup_key(String blobKey, BlobStore blobStore, StormClusterState clusterState) {
// we skip to clean up the non-exist keys
if (blobKey.startsWith(JStormMetrics.NIMBUS_METRIC_KEY)
|| blobKey.startsWith(JStormMetrics.CLUSTER_METRIC_KEY)
|| blobKey.startsWith(JStormMetrics.SUPERVISOR_METRIC_KEY)) {
return;
}
try {
blobStore.deleteBlob(blobKey);
} catch (Exception e) {
LOG.warn("cleanup blob key {} error {}", blobKey, e);
}
try {
if (blobStore instanceof LocalFsBlobStore) {
clusterState.remove_blobstore_key(blobKey);
clusterState.remove_key_version(blobKey);
}
} catch (Exception e) {
LOG.warn("cleanup blob key {} error {}", blobKey, e);
}
} | java | public static void cleanup_key(String blobKey, BlobStore blobStore, StormClusterState clusterState) {
// we skip to clean up the non-exist keys
if (blobKey.startsWith(JStormMetrics.NIMBUS_METRIC_KEY)
|| blobKey.startsWith(JStormMetrics.CLUSTER_METRIC_KEY)
|| blobKey.startsWith(JStormMetrics.SUPERVISOR_METRIC_KEY)) {
return;
}
try {
blobStore.deleteBlob(blobKey);
} catch (Exception e) {
LOG.warn("cleanup blob key {} error {}", blobKey, e);
}
try {
if (blobStore instanceof LocalFsBlobStore) {
clusterState.remove_blobstore_key(blobKey);
clusterState.remove_key_version(blobKey);
}
} catch (Exception e) {
LOG.warn("cleanup blob key {} error {}", blobKey, e);
}
} | [
"public",
"static",
"void",
"cleanup_key",
"(",
"String",
"blobKey",
",",
"BlobStore",
"blobStore",
",",
"StormClusterState",
"clusterState",
")",
"{",
"// we skip to clean up the non-exist keys",
"if",
"(",
"blobKey",
".",
"startsWith",
"(",
"JStormMetrics",
".",
"NIMBUS_METRIC_KEY",
")",
"||",
"blobKey",
".",
"startsWith",
"(",
"JStormMetrics",
".",
"CLUSTER_METRIC_KEY",
")",
"||",
"blobKey",
".",
"startsWith",
"(",
"JStormMetrics",
".",
"SUPERVISOR_METRIC_KEY",
")",
")",
"{",
"return",
";",
"}",
"try",
"{",
"blobStore",
".",
"deleteBlob",
"(",
"blobKey",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"cleanup blob key {} error {}\"",
",",
"blobKey",
",",
"e",
")",
";",
"}",
"try",
"{",
"if",
"(",
"blobStore",
"instanceof",
"LocalFsBlobStore",
")",
"{",
"clusterState",
".",
"remove_blobstore_key",
"(",
"blobKey",
")",
";",
"clusterState",
".",
"remove_key_version",
"(",
"blobKey",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"cleanup blob key {} error {}\"",
",",
"blobKey",
",",
"e",
")",
";",
"}",
"}"
] | remove blob information in zk for the blobkey | [
"remove",
"blob",
"information",
"in",
"zk",
"for",
"the",
"blobkey"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java#L488-L509 |
25,177 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java | BlobStoreUtils.downloadDistributeStormCode | public static void downloadDistributeStormCode(Map conf, String topologyId, String masterCodeDir)
throws IOException, TException {
String tmpToot = null;
try {
// STORM_LOCAL_DIR/supervisor/tmp/(UUID)
tmpToot = StormConfig.supervisorTmpDir(conf) + File.separator + UUID.randomUUID().toString();
// STORM_LOCAL_DIR/supervisor/stormdist/topologyId
String stormRoot = StormConfig.supervisor_stormdist_root(conf, topologyId);
// JStormServerUtils.downloadCodeFromMaster(conf, tmproot, masterCodeDir, topologyId, true);
JStormServerUtils.downloadCodeFromBlobStore(conf, tmpToot, topologyId);
// tmproot/stormjar.jar
String localFileJarTmp = StormConfig.stormjar_path(tmpToot);
// extract dir from jar
JStormUtils.extractDirFromJar(localFileJarTmp, StormConfig.RESOURCES_SUBDIR, tmpToot);
File srcDir = new File(tmpToot);
File destDir = new File(stormRoot);
try {
FileUtils.moveDirectory(srcDir, destDir);
} catch (FileExistsException e) {
FileUtils.copyDirectory(srcDir, destDir);
FileUtils.deleteQuietly(srcDir);
}
} finally {
if (tmpToot != null) {
File srcDir = new File(tmpToot);
FileUtils.deleteQuietly(srcDir);
}
}
} | java | public static void downloadDistributeStormCode(Map conf, String topologyId, String masterCodeDir)
throws IOException, TException {
String tmpToot = null;
try {
// STORM_LOCAL_DIR/supervisor/tmp/(UUID)
tmpToot = StormConfig.supervisorTmpDir(conf) + File.separator + UUID.randomUUID().toString();
// STORM_LOCAL_DIR/supervisor/stormdist/topologyId
String stormRoot = StormConfig.supervisor_stormdist_root(conf, topologyId);
// JStormServerUtils.downloadCodeFromMaster(conf, tmproot, masterCodeDir, topologyId, true);
JStormServerUtils.downloadCodeFromBlobStore(conf, tmpToot, topologyId);
// tmproot/stormjar.jar
String localFileJarTmp = StormConfig.stormjar_path(tmpToot);
// extract dir from jar
JStormUtils.extractDirFromJar(localFileJarTmp, StormConfig.RESOURCES_SUBDIR, tmpToot);
File srcDir = new File(tmpToot);
File destDir = new File(stormRoot);
try {
FileUtils.moveDirectory(srcDir, destDir);
} catch (FileExistsException e) {
FileUtils.copyDirectory(srcDir, destDir);
FileUtils.deleteQuietly(srcDir);
}
} finally {
if (tmpToot != null) {
File srcDir = new File(tmpToot);
FileUtils.deleteQuietly(srcDir);
}
}
} | [
"public",
"static",
"void",
"downloadDistributeStormCode",
"(",
"Map",
"conf",
",",
"String",
"topologyId",
",",
"String",
"masterCodeDir",
")",
"throws",
"IOException",
",",
"TException",
"{",
"String",
"tmpToot",
"=",
"null",
";",
"try",
"{",
"// STORM_LOCAL_DIR/supervisor/tmp/(UUID)",
"tmpToot",
"=",
"StormConfig",
".",
"supervisorTmpDir",
"(",
"conf",
")",
"+",
"File",
".",
"separator",
"+",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toString",
"(",
")",
";",
"// STORM_LOCAL_DIR/supervisor/stormdist/topologyId",
"String",
"stormRoot",
"=",
"StormConfig",
".",
"supervisor_stormdist_root",
"(",
"conf",
",",
"topologyId",
")",
";",
"// JStormServerUtils.downloadCodeFromMaster(conf, tmproot, masterCodeDir, topologyId, true);",
"JStormServerUtils",
".",
"downloadCodeFromBlobStore",
"(",
"conf",
",",
"tmpToot",
",",
"topologyId",
")",
";",
"// tmproot/stormjar.jar",
"String",
"localFileJarTmp",
"=",
"StormConfig",
".",
"stormjar_path",
"(",
"tmpToot",
")",
";",
"// extract dir from jar",
"JStormUtils",
".",
"extractDirFromJar",
"(",
"localFileJarTmp",
",",
"StormConfig",
".",
"RESOURCES_SUBDIR",
",",
"tmpToot",
")",
";",
"File",
"srcDir",
"=",
"new",
"File",
"(",
"tmpToot",
")",
";",
"File",
"destDir",
"=",
"new",
"File",
"(",
"stormRoot",
")",
";",
"try",
"{",
"FileUtils",
".",
"moveDirectory",
"(",
"srcDir",
",",
"destDir",
")",
";",
"}",
"catch",
"(",
"FileExistsException",
"e",
")",
"{",
"FileUtils",
".",
"copyDirectory",
"(",
"srcDir",
",",
"destDir",
")",
";",
"FileUtils",
".",
"deleteQuietly",
"(",
"srcDir",
")",
";",
"}",
"}",
"finally",
"{",
"if",
"(",
"tmpToot",
"!=",
"null",
")",
"{",
"File",
"srcDir",
"=",
"new",
"File",
"(",
"tmpToot",
")",
";",
"FileUtils",
".",
"deleteQuietly",
"(",
"srcDir",
")",
";",
"}",
"}",
"}"
] | no need to synchronize, since EventManager will execute sequentially | [
"no",
"need",
"to",
"synchronize",
"since",
"EventManager",
"will",
"execute",
"sequentially"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/blobstore/BlobStoreUtils.java#L566-L599 |
25,178 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/utils/LogUtils.java | LogUtils.setLogBackLevel | public static boolean setLogBackLevel(String loggerName, String logLevel) {
String logLevelUpper = (logLevel == null) ? "OFF" : logLevel.toUpperCase();
try {
Package logbackPackage = Package.getPackage(LOGBACK_CLASSIC);
if (logbackPackage == null) {
LOG.warn("Logback is not in the classpath!");
return false;
}
// Use ROOT logger if given logger name is blank.
if ((loggerName == null) || loggerName.trim().isEmpty()) {
loggerName = (String) getFieldVaulue(LOGBACK_CLASSIC_LOGGER, "ROOT_LOGGER_NAME");
}
// Obtain logger by the name
Logger loggerObtained = LoggerFactory.getLogger(loggerName);
if (loggerObtained == null) {
// I don't know if this case occurs
LOG.warn("No logger for the name: {}", loggerName);
return false;
}
Object logLevelObj = getFieldVaulue(LOGBACK_CLASSIC_LEVEL, logLevelUpper);
if (logLevelObj == null) {
LOG.warn("No such log level: {}", logLevelUpper);
return false;
}
Class<?>[] paramTypes = {logLevelObj.getClass()};
Object[] params = {logLevelObj};
Class<?> clz = Class.forName(LOGBACK_CLASSIC_LOGGER);
Method method = clz.getMethod("setLevel", paramTypes);
method.invoke(loggerObtained, params);
LOG.info("LogBack level set to {} for the logger '{}'", logLevelUpper, loggerName);
return true;
} catch (NoClassDefFoundError e) {
LOG.warn("Couldn't set logback level to {} for the logger '{}'", logLevelUpper, loggerName, e);
return false;
} catch (Exception e) {
LOG.warn("Couldn't set logback level to {} for the logger '{}'", logLevelUpper, loggerName, e);
return false;
}
} | java | public static boolean setLogBackLevel(String loggerName, String logLevel) {
String logLevelUpper = (logLevel == null) ? "OFF" : logLevel.toUpperCase();
try {
Package logbackPackage = Package.getPackage(LOGBACK_CLASSIC);
if (logbackPackage == null) {
LOG.warn("Logback is not in the classpath!");
return false;
}
// Use ROOT logger if given logger name is blank.
if ((loggerName == null) || loggerName.trim().isEmpty()) {
loggerName = (String) getFieldVaulue(LOGBACK_CLASSIC_LOGGER, "ROOT_LOGGER_NAME");
}
// Obtain logger by the name
Logger loggerObtained = LoggerFactory.getLogger(loggerName);
if (loggerObtained == null) {
// I don't know if this case occurs
LOG.warn("No logger for the name: {}", loggerName);
return false;
}
Object logLevelObj = getFieldVaulue(LOGBACK_CLASSIC_LEVEL, logLevelUpper);
if (logLevelObj == null) {
LOG.warn("No such log level: {}", logLevelUpper);
return false;
}
Class<?>[] paramTypes = {logLevelObj.getClass()};
Object[] params = {logLevelObj};
Class<?> clz = Class.forName(LOGBACK_CLASSIC_LOGGER);
Method method = clz.getMethod("setLevel", paramTypes);
method.invoke(loggerObtained, params);
LOG.info("LogBack level set to {} for the logger '{}'", logLevelUpper, loggerName);
return true;
} catch (NoClassDefFoundError e) {
LOG.warn("Couldn't set logback level to {} for the logger '{}'", logLevelUpper, loggerName, e);
return false;
} catch (Exception e) {
LOG.warn("Couldn't set logback level to {} for the logger '{}'", logLevelUpper, loggerName, e);
return false;
}
} | [
"public",
"static",
"boolean",
"setLogBackLevel",
"(",
"String",
"loggerName",
",",
"String",
"logLevel",
")",
"{",
"String",
"logLevelUpper",
"=",
"(",
"logLevel",
"==",
"null",
")",
"?",
"\"OFF\"",
":",
"logLevel",
".",
"toUpperCase",
"(",
")",
";",
"try",
"{",
"Package",
"logbackPackage",
"=",
"Package",
".",
"getPackage",
"(",
"LOGBACK_CLASSIC",
")",
";",
"if",
"(",
"logbackPackage",
"==",
"null",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Logback is not in the classpath!\"",
")",
";",
"return",
"false",
";",
"}",
"// Use ROOT logger if given logger name is blank.",
"if",
"(",
"(",
"loggerName",
"==",
"null",
")",
"||",
"loggerName",
".",
"trim",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"loggerName",
"=",
"(",
"String",
")",
"getFieldVaulue",
"(",
"LOGBACK_CLASSIC_LOGGER",
",",
"\"ROOT_LOGGER_NAME\"",
")",
";",
"}",
"// Obtain logger by the name",
"Logger",
"loggerObtained",
"=",
"LoggerFactory",
".",
"getLogger",
"(",
"loggerName",
")",
";",
"if",
"(",
"loggerObtained",
"==",
"null",
")",
"{",
"// I don't know if this case occurs",
"LOG",
".",
"warn",
"(",
"\"No logger for the name: {}\"",
",",
"loggerName",
")",
";",
"return",
"false",
";",
"}",
"Object",
"logLevelObj",
"=",
"getFieldVaulue",
"(",
"LOGBACK_CLASSIC_LEVEL",
",",
"logLevelUpper",
")",
";",
"if",
"(",
"logLevelObj",
"==",
"null",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"No such log level: {}\"",
",",
"logLevelUpper",
")",
";",
"return",
"false",
";",
"}",
"Class",
"<",
"?",
">",
"[",
"]",
"paramTypes",
"=",
"{",
"logLevelObj",
".",
"getClass",
"(",
")",
"}",
";",
"Object",
"[",
"]",
"params",
"=",
"{",
"logLevelObj",
"}",
";",
"Class",
"<",
"?",
">",
"clz",
"=",
"Class",
".",
"forName",
"(",
"LOGBACK_CLASSIC_LOGGER",
")",
";",
"Method",
"method",
"=",
"clz",
".",
"getMethod",
"(",
"\"setLevel\"",
",",
"paramTypes",
")",
";",
"method",
".",
"invoke",
"(",
"loggerObtained",
",",
"params",
")",
";",
"LOG",
".",
"info",
"(",
"\"LogBack level set to {} for the logger '{}'\"",
",",
"logLevelUpper",
",",
"loggerName",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"NoClassDefFoundError",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Couldn't set logback level to {} for the logger '{}'\"",
",",
"logLevelUpper",
",",
"loggerName",
",",
"e",
")",
";",
"return",
"false",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Couldn't set logback level to {} for the logger '{}'\"",
",",
"logLevelUpper",
",",
"loggerName",
",",
"e",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Dynamically sets the logback log level for the given class to the specified level.
@param loggerName Name of the logger to set its log level. If blank, root logger will be used.
@param logLevel One of the supported log levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL,
OFF. {@code null} value is considered as 'OFF'. | [
"Dynamically",
"sets",
"the",
"logback",
"log",
"level",
"for",
"the",
"given",
"class",
"to",
"the",
"specified",
"level",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/utils/LogUtils.java#L93-L137 |
25,179 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/utils/LogUtils.java | LogUtils.setLog4jLevel | public static boolean setLog4jLevel(String loggerName, String logLevel) {
String logLevelUpper = (logLevel == null) ? "OFF" : logLevel.toUpperCase();
try {
Package log4jPackage = Package.getPackage(LOG4J_CLASSIC);
if (log4jPackage == null) {
LOG.warn("Log4j is not in the classpath!");
return false;
}
Class<?> clz = Class.forName(LOG4J_CLASSIC_LOGGER);
// Obtain logger by the name
Object loggerObtained;
if ((loggerName == null) || loggerName.trim().isEmpty() || loggerName.trim().equals("ROOT")) {
// Use ROOT logger if given logger name is blank.
Method method = clz.getMethod("getRootLogger");
loggerObtained = method.invoke(null);
loggerName = "ROOT";
} else {
Method method = clz.getMethod("getLogger", String.class);
loggerObtained = method.invoke(null, loggerName);
}
if (loggerObtained == null) {
// I don't know if this case occurs
LOG.warn("No logger for the name: {}", loggerName);
return false;
}
Object logLevelObj = getFieldVaulue(LOG4J_CLASSIC_LEVEL, logLevelUpper);
if (logLevelObj == null) {
LOG.warn("No such log level: {}", logLevelUpper);
return false;
}
Class<?>[] paramTypes = {logLevelObj.getClass()};
Object[] params = {logLevelObj};
Method method = clz.getMethod("setLevel", paramTypes);
method.invoke(loggerObtained, params);
LOG.info("Log4j level set to {} for the logger '{}'", logLevelUpper, loggerName);
return true;
} catch (NoClassDefFoundError e) {
LOG.warn("Couldn't set log4j level to {} for the logger '{}'", logLevelUpper, loggerName, e);
return false;
} catch (Exception e) {
LOG.warn("Couldn't set log4j level to {} for the logger '{}'", logLevelUpper, loggerName);
return false;
}
} | java | public static boolean setLog4jLevel(String loggerName, String logLevel) {
String logLevelUpper = (logLevel == null) ? "OFF" : logLevel.toUpperCase();
try {
Package log4jPackage = Package.getPackage(LOG4J_CLASSIC);
if (log4jPackage == null) {
LOG.warn("Log4j is not in the classpath!");
return false;
}
Class<?> clz = Class.forName(LOG4J_CLASSIC_LOGGER);
// Obtain logger by the name
Object loggerObtained;
if ((loggerName == null) || loggerName.trim().isEmpty() || loggerName.trim().equals("ROOT")) {
// Use ROOT logger if given logger name is blank.
Method method = clz.getMethod("getRootLogger");
loggerObtained = method.invoke(null);
loggerName = "ROOT";
} else {
Method method = clz.getMethod("getLogger", String.class);
loggerObtained = method.invoke(null, loggerName);
}
if (loggerObtained == null) {
// I don't know if this case occurs
LOG.warn("No logger for the name: {}", loggerName);
return false;
}
Object logLevelObj = getFieldVaulue(LOG4J_CLASSIC_LEVEL, logLevelUpper);
if (logLevelObj == null) {
LOG.warn("No such log level: {}", logLevelUpper);
return false;
}
Class<?>[] paramTypes = {logLevelObj.getClass()};
Object[] params = {logLevelObj};
Method method = clz.getMethod("setLevel", paramTypes);
method.invoke(loggerObtained, params);
LOG.info("Log4j level set to {} for the logger '{}'", logLevelUpper, loggerName);
return true;
} catch (NoClassDefFoundError e) {
LOG.warn("Couldn't set log4j level to {} for the logger '{}'", logLevelUpper, loggerName, e);
return false;
} catch (Exception e) {
LOG.warn("Couldn't set log4j level to {} for the logger '{}'", logLevelUpper, loggerName);
return false;
}
} | [
"public",
"static",
"boolean",
"setLog4jLevel",
"(",
"String",
"loggerName",
",",
"String",
"logLevel",
")",
"{",
"String",
"logLevelUpper",
"=",
"(",
"logLevel",
"==",
"null",
")",
"?",
"\"OFF\"",
":",
"logLevel",
".",
"toUpperCase",
"(",
")",
";",
"try",
"{",
"Package",
"log4jPackage",
"=",
"Package",
".",
"getPackage",
"(",
"LOG4J_CLASSIC",
")",
";",
"if",
"(",
"log4jPackage",
"==",
"null",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Log4j is not in the classpath!\"",
")",
";",
"return",
"false",
";",
"}",
"Class",
"<",
"?",
">",
"clz",
"=",
"Class",
".",
"forName",
"(",
"LOG4J_CLASSIC_LOGGER",
")",
";",
"// Obtain logger by the name",
"Object",
"loggerObtained",
";",
"if",
"(",
"(",
"loggerName",
"==",
"null",
")",
"||",
"loggerName",
".",
"trim",
"(",
")",
".",
"isEmpty",
"(",
")",
"||",
"loggerName",
".",
"trim",
"(",
")",
".",
"equals",
"(",
"\"ROOT\"",
")",
")",
"{",
"// Use ROOT logger if given logger name is blank.",
"Method",
"method",
"=",
"clz",
".",
"getMethod",
"(",
"\"getRootLogger\"",
")",
";",
"loggerObtained",
"=",
"method",
".",
"invoke",
"(",
"null",
")",
";",
"loggerName",
"=",
"\"ROOT\"",
";",
"}",
"else",
"{",
"Method",
"method",
"=",
"clz",
".",
"getMethod",
"(",
"\"getLogger\"",
",",
"String",
".",
"class",
")",
";",
"loggerObtained",
"=",
"method",
".",
"invoke",
"(",
"null",
",",
"loggerName",
")",
";",
"}",
"if",
"(",
"loggerObtained",
"==",
"null",
")",
"{",
"// I don't know if this case occurs",
"LOG",
".",
"warn",
"(",
"\"No logger for the name: {}\"",
",",
"loggerName",
")",
";",
"return",
"false",
";",
"}",
"Object",
"logLevelObj",
"=",
"getFieldVaulue",
"(",
"LOG4J_CLASSIC_LEVEL",
",",
"logLevelUpper",
")",
";",
"if",
"(",
"logLevelObj",
"==",
"null",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"No such log level: {}\"",
",",
"logLevelUpper",
")",
";",
"return",
"false",
";",
"}",
"Class",
"<",
"?",
">",
"[",
"]",
"paramTypes",
"=",
"{",
"logLevelObj",
".",
"getClass",
"(",
")",
"}",
";",
"Object",
"[",
"]",
"params",
"=",
"{",
"logLevelObj",
"}",
";",
"Method",
"method",
"=",
"clz",
".",
"getMethod",
"(",
"\"setLevel\"",
",",
"paramTypes",
")",
";",
"method",
".",
"invoke",
"(",
"loggerObtained",
",",
"params",
")",
";",
"LOG",
".",
"info",
"(",
"\"Log4j level set to {} for the logger '{}'\"",
",",
"logLevelUpper",
",",
"loggerName",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"NoClassDefFoundError",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Couldn't set log4j level to {} for the logger '{}'\"",
",",
"logLevelUpper",
",",
"loggerName",
",",
"e",
")",
";",
"return",
"false",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"LOG",
".",
"warn",
"(",
"\"Couldn't set log4j level to {} for the logger '{}'\"",
",",
"logLevelUpper",
",",
"loggerName",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Dynamically sets the log4j log level for the given class to the specified level.
@param loggerName Name of the logger to set its log level. If blank, root logger will be used.
@param logLevel One of the supported log levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL,
OFF. {@code null} value is considered as 'OFF'. | [
"Dynamically",
"sets",
"the",
"log4j",
"log",
"level",
"for",
"the",
"given",
"class",
"to",
"the",
"specified",
"level",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/utils/LogUtils.java#L146-L196 |
25,180 | alibaba/jstorm | jstorm-core/src/main/java/backtype/storm/serialization/KryoTupleDeserializer.java | KryoTupleDeserializer.deserializeTaskId | public static int deserializeTaskId(byte[] ser) {
Input _kryoInput = new Input(1);
_kryoInput.setBuffer(ser);
return _kryoInput.readInt();
} | java | public static int deserializeTaskId(byte[] ser) {
Input _kryoInput = new Input(1);
_kryoInput.setBuffer(ser);
return _kryoInput.readInt();
} | [
"public",
"static",
"int",
"deserializeTaskId",
"(",
"byte",
"[",
"]",
"ser",
")",
"{",
"Input",
"_kryoInput",
"=",
"new",
"Input",
"(",
"1",
")",
";",
"_kryoInput",
".",
"setBuffer",
"(",
"ser",
")",
";",
"return",
"_kryoInput",
".",
"readInt",
"(",
")",
";",
"}"
] | just get target taskId | [
"just",
"get",
"target",
"taskId"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/backtype/storm/serialization/KryoTupleDeserializer.java#L143-L148 |
25,181 | alibaba/jstorm | jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java | JstormYarnUtils.isPortAvailable | public static boolean isPortAvailable(int port) {
try {
ServerSocket socket = new ServerSocket(port);
socket.close();
return true;
} catch (IOException e) {
return false;
}
} | java | public static boolean isPortAvailable(int port) {
try {
ServerSocket socket = new ServerSocket(port);
socket.close();
return true;
} catch (IOException e) {
return false;
}
} | [
"public",
"static",
"boolean",
"isPortAvailable",
"(",
"int",
"port",
")",
"{",
"try",
"{",
"ServerSocket",
"socket",
"=",
"new",
"ServerSocket",
"(",
"port",
")",
";",
"socket",
".",
"close",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | See if a port is available for listening on by trying to listen
on it and seeing if that works or fails.
@param port port to listen to
@return true if the port was available for listening on | [
"See",
"if",
"a",
"port",
"is",
"available",
"for",
"listening",
"on",
"by",
"trying",
"to",
"listen",
"on",
"it",
"and",
"seeing",
"if",
"that",
"works",
"or",
"fails",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java#L103-L111 |
25,182 | alibaba/jstorm | jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java | JstormYarnUtils.isPortAvailable | public static boolean isPortAvailable(String host, int port) {
try {
Socket socket = new Socket(host, port);
socket.close();
return false;
} catch (IOException e) {
return true;
}
} | java | public static boolean isPortAvailable(String host, int port) {
try {
Socket socket = new Socket(host, port);
socket.close();
return false;
} catch (IOException e) {
return true;
}
} | [
"public",
"static",
"boolean",
"isPortAvailable",
"(",
"String",
"host",
",",
"int",
"port",
")",
"{",
"try",
"{",
"Socket",
"socket",
"=",
"new",
"Socket",
"(",
"host",
",",
"port",
")",
";",
"socket",
".",
"close",
"(",
")",
";",
"return",
"false",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"return",
"true",
";",
"}",
"}"
] | See if a port is available for listening on by trying connect to it
and seeing if that works or fails
@param host
@param port
@return | [
"See",
"if",
"a",
"port",
"is",
"available",
"for",
"listening",
"on",
"by",
"trying",
"connect",
"to",
"it",
"and",
"seeing",
"if",
"that",
"works",
"or",
"fails"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java#L121-L129 |
25,183 | alibaba/jstorm | jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java | JstormYarnUtils.patchConfiguration | public static Configuration patchConfiguration(Configuration conf) {
//if the fallback option is NOT set, enable it.
//if it is explicitly set to anything -leave alone
if (conf.get(JstormXmlConfKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH) == null) {
conf.set(JstormXmlConfKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH, "true");
}
return conf;
} | java | public static Configuration patchConfiguration(Configuration conf) {
//if the fallback option is NOT set, enable it.
//if it is explicitly set to anything -leave alone
if (conf.get(JstormXmlConfKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH) == null) {
conf.set(JstormXmlConfKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH, "true");
}
return conf;
} | [
"public",
"static",
"Configuration",
"patchConfiguration",
"(",
"Configuration",
"conf",
")",
"{",
"//if the fallback option is NOT set, enable it.",
"//if it is explicitly set to anything -leave alone",
"if",
"(",
"conf",
".",
"get",
"(",
"JstormXmlConfKeys",
".",
"IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH",
")",
"==",
"null",
")",
"{",
"conf",
".",
"set",
"(",
"JstormXmlConfKeys",
".",
"IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH",
",",
"\"true\"",
")",
";",
"}",
"return",
"conf",
";",
"}"
] | Take an existing conf and patch it for needs. Useful
in Service.init & RunService methods where a shared config is being
passed in
@param conf configuration
@return the patched configuration | [
"Take",
"an",
"existing",
"conf",
"and",
"patch",
"it",
"for",
"needs",
".",
"Useful",
"in",
"Service",
".",
"init",
"&",
"RunService",
"methods",
"where",
"a",
"shared",
"config",
"is",
"being",
"passed",
"in"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java#L158-L166 |
25,184 | alibaba/jstorm | jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java | JstormYarnUtils.collectionToStringList | public static List<String> collectionToStringList(Collection c) {
List<String> l = new ArrayList<String>(c.size());
for (Object o : c) {
l.add(o.toString());
}
return l;
} | java | public static List<String> collectionToStringList(Collection c) {
List<String> l = new ArrayList<String>(c.size());
for (Object o : c) {
l.add(o.toString());
}
return l;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"collectionToStringList",
"(",
"Collection",
"c",
")",
"{",
"List",
"<",
"String",
">",
"l",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
"c",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"Object",
"o",
":",
"c",
")",
"{",
"l",
".",
"add",
"(",
"o",
".",
"toString",
"(",
")",
")",
";",
"}",
"return",
"l",
";",
"}"
] | Take a collection, return a list containing the string value of every
element in the collection.
@param c collection
@return a stringified list | [
"Take",
"a",
"collection",
"return",
"a",
"list",
"containing",
"the",
"string",
"value",
"of",
"every",
"element",
"in",
"the",
"collection",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java#L175-L181 |
25,185 | alibaba/jstorm | jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java | JstormYarnUtils.join | public static String join(Collection collection, String separator) {
return join(collection, separator, true);
} | java | public static String join(Collection collection, String separator) {
return join(collection, separator, true);
} | [
"public",
"static",
"String",
"join",
"(",
"Collection",
"collection",
",",
"String",
"separator",
")",
"{",
"return",
"join",
"(",
"collection",
",",
"separator",
",",
"true",
")",
";",
"}"
] | Join an collection of objects with a separator that appears after every
instance in the list -including at the end
@param collection collection to call toString() on each element
@param separator separator string
@return the joined entries | [
"Join",
"an",
"collection",
"of",
"objects",
"with",
"a",
"separator",
"that",
"appears",
"after",
"every",
"instance",
"in",
"the",
"list",
"-",
"including",
"at",
"the",
"end"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java#L191-L193 |
25,186 | alibaba/jstorm | jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java | JstormYarnUtils.join | public static String join(Collection collection,
String separator,
boolean trailing) {
StringBuilder b = new StringBuilder();
// fast return on empty collection
if (collection.isEmpty()) {
return trailing ? separator : "";
}
for (Object o : collection) {
b.append(o);
b.append(separator);
}
int length = separator.length();
String s = b.toString();
return (trailing || s.isEmpty()) ?
s : (b.substring(0, b.length() - length));
} | java | public static String join(Collection collection,
String separator,
boolean trailing) {
StringBuilder b = new StringBuilder();
// fast return on empty collection
if (collection.isEmpty()) {
return trailing ? separator : "";
}
for (Object o : collection) {
b.append(o);
b.append(separator);
}
int length = separator.length();
String s = b.toString();
return (trailing || s.isEmpty()) ?
s : (b.substring(0, b.length() - length));
} | [
"public",
"static",
"String",
"join",
"(",
"Collection",
"collection",
",",
"String",
"separator",
",",
"boolean",
"trailing",
")",
"{",
"StringBuilder",
"b",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"// fast return on empty collection",
"if",
"(",
"collection",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"trailing",
"?",
"separator",
":",
"\"\"",
";",
"}",
"for",
"(",
"Object",
"o",
":",
"collection",
")",
"{",
"b",
".",
"append",
"(",
"o",
")",
";",
"b",
".",
"append",
"(",
"separator",
")",
";",
"}",
"int",
"length",
"=",
"separator",
".",
"length",
"(",
")",
";",
"String",
"s",
"=",
"b",
".",
"toString",
"(",
")",
";",
"return",
"(",
"trailing",
"||",
"s",
".",
"isEmpty",
"(",
")",
")",
"?",
"s",
":",
"(",
"b",
".",
"substring",
"(",
"0",
",",
"b",
".",
"length",
"(",
")",
"-",
"length",
")",
")",
";",
"}"
] | Join an collection of objects with a separator that appears after every
instance in the list -optionally at the end
@param collection collection to call toString() on each element
@param separator separator string
@param trailing add a trailing entry or not
@return the joined entries | [
"Join",
"an",
"collection",
"of",
"objects",
"with",
"a",
"separator",
"that",
"appears",
"after",
"every",
"instance",
"in",
"the",
"list",
"-",
"optionally",
"at",
"the",
"end"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java#L204-L220 |
25,187 | alibaba/jstorm | jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java | JstormYarnUtils.join | public static String join(String[] collection, String separator,
boolean trailing) {
return join(Arrays.asList(collection), separator, trailing);
} | java | public static String join(String[] collection, String separator,
boolean trailing) {
return join(Arrays.asList(collection), separator, trailing);
} | [
"public",
"static",
"String",
"join",
"(",
"String",
"[",
"]",
"collection",
",",
"String",
"separator",
",",
"boolean",
"trailing",
")",
"{",
"return",
"join",
"(",
"Arrays",
".",
"asList",
"(",
"collection",
")",
",",
"separator",
",",
"trailing",
")",
";",
"}"
] | Join an array of strings with a separator that appears after every
instance in the list -optionally at the end
@param collection strings
@param separator separator string
@param trailing add a trailing entry or not
@return the joined entries | [
"Join",
"an",
"array",
"of",
"strings",
"with",
"a",
"separator",
"that",
"appears",
"after",
"every",
"instance",
"in",
"the",
"list",
"-",
"optionally",
"at",
"the",
"end"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java#L245-L248 |
25,188 | alibaba/jstorm | jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java | JstormYarnUtils.joinWithInnerSeparator | public static String joinWithInnerSeparator(String separator,
Object... collection) {
StringBuilder b = new StringBuilder();
boolean first = true;
for (Object o : collection) {
if (first) {
first = false;
} else {
b.append(separator);
}
b.append(o.toString());
b.append(separator);
}
return b.toString();
} | java | public static String joinWithInnerSeparator(String separator,
Object... collection) {
StringBuilder b = new StringBuilder();
boolean first = true;
for (Object o : collection) {
if (first) {
first = false;
} else {
b.append(separator);
}
b.append(o.toString());
b.append(separator);
}
return b.toString();
} | [
"public",
"static",
"String",
"joinWithInnerSeparator",
"(",
"String",
"separator",
",",
"Object",
"...",
"collection",
")",
"{",
"StringBuilder",
"b",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"boolean",
"first",
"=",
"true",
";",
"for",
"(",
"Object",
"o",
":",
"collection",
")",
"{",
"if",
"(",
"first",
")",
"{",
"first",
"=",
"false",
";",
"}",
"else",
"{",
"b",
".",
"append",
"(",
"separator",
")",
";",
"}",
"b",
".",
"append",
"(",
"o",
".",
"toString",
"(",
")",
")",
";",
"b",
".",
"append",
"(",
"separator",
")",
";",
"}",
"return",
"b",
".",
"toString",
"(",
")",
";",
"}"
] | Join an array of strings with a separator that appears after every
instance in the list -except at the end
@param collection strings
@param separator separator string
@return the list | [
"Join",
"an",
"array",
"of",
"strings",
"with",
"a",
"separator",
"that",
"appears",
"after",
"every",
"instance",
"in",
"the",
"list",
"-",
"except",
"at",
"the",
"end"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java#L258-L273 |
25,189 | alibaba/jstorm | jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java | JstormYarnUtils.getSupervisorSlotPorts | public static String getSupervisorSlotPorts(int memory, int vcores, String instanceName, String supervisorHost, RegistryOperations registryOperations) {
return join(getSupervisorPorts(memory, vcores, instanceName, supervisorHost, registryOperations), JOYConstants.COMMA, false);
} | java | public static String getSupervisorSlotPorts(int memory, int vcores, String instanceName, String supervisorHost, RegistryOperations registryOperations) {
return join(getSupervisorPorts(memory, vcores, instanceName, supervisorHost, registryOperations), JOYConstants.COMMA, false);
} | [
"public",
"static",
"String",
"getSupervisorSlotPorts",
"(",
"int",
"memory",
",",
"int",
"vcores",
",",
"String",
"instanceName",
",",
"String",
"supervisorHost",
",",
"RegistryOperations",
"registryOperations",
")",
"{",
"return",
"join",
"(",
"getSupervisorPorts",
"(",
"memory",
",",
"vcores",
",",
"instanceName",
",",
"supervisorHost",
",",
"registryOperations",
")",
",",
"JOYConstants",
".",
"COMMA",
",",
"false",
")",
";",
"}"
] | this is for jstorm configuration's format
@param memory
@param vcores
@param supervisorHost
@return | [
"this",
"is",
"for",
"jstorm",
"configuration",
"s",
"format"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-on-yarn/src/main/java/com/alibaba/jstorm/yarn/utils/JstormYarnUtils.java#L283-L285 |
25,190 | alibaba/jstorm | jstorm-core/src/main/java/backtype/storm/windowing/WatermarkTimeTriggerPolicy.java | WatermarkTimeTriggerPolicy.getNextAlignedWindowTs | private long getNextAlignedWindowTs(long startTs, long endTs) {
long nextTs = windowManager.getEarliestEventTs(startTs, endTs);
if (nextTs == Long.MAX_VALUE || (nextTs % slidingIntervalMs == 0)) {
return nextTs;
}
return nextTs + (slidingIntervalMs - (nextTs % slidingIntervalMs));
} | java | private long getNextAlignedWindowTs(long startTs, long endTs) {
long nextTs = windowManager.getEarliestEventTs(startTs, endTs);
if (nextTs == Long.MAX_VALUE || (nextTs % slidingIntervalMs == 0)) {
return nextTs;
}
return nextTs + (slidingIntervalMs - (nextTs % slidingIntervalMs));
} | [
"private",
"long",
"getNextAlignedWindowTs",
"(",
"long",
"startTs",
",",
"long",
"endTs",
")",
"{",
"long",
"nextTs",
"=",
"windowManager",
".",
"getEarliestEventTs",
"(",
"startTs",
",",
"endTs",
")",
";",
"if",
"(",
"nextTs",
"==",
"Long",
".",
"MAX_VALUE",
"||",
"(",
"nextTs",
"%",
"slidingIntervalMs",
"==",
"0",
")",
")",
"{",
"return",
"nextTs",
";",
"}",
"return",
"nextTs",
"+",
"(",
"slidingIntervalMs",
"-",
"(",
"nextTs",
"%",
"slidingIntervalMs",
")",
")",
";",
"}"
] | Computes the next window by scanning the events in the window and
finds the next aligned window between the startTs and endTs. Return the end ts
of the next aligned window, i.e. the ts when the window should fire.
@param startTs the start timestamp (excluding)
@param endTs the end timestamp (including)
@return the aligned window end ts for the next window or Long.MAX_VALUE if there
are no more events to be processed. | [
"Computes",
"the",
"next",
"window",
"by",
"scanning",
"the",
"events",
"in",
"the",
"window",
"and",
"finds",
"the",
"next",
"aligned",
"window",
"between",
"the",
"startTs",
"and",
"endTs",
".",
"Return",
"the",
"end",
"ts",
"of",
"the",
"next",
"aligned",
"window",
"i",
".",
"e",
".",
"the",
"ts",
"when",
"the",
"window",
"should",
"fire",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/backtype/storm/windowing/WatermarkTimeTriggerPolicy.java#L109-L115 |
25,191 | alibaba/jstorm | jstorm-core/src/main/java/backtype/storm/windowing/WaterMarkEventGenerator.java | WaterMarkEventGenerator.computeWaterMarkTs | private long computeWaterMarkTs() {
long ts = 0;
// only if some data has arrived on each input stream
if (streamToTs.size() >= inputStreams.size()) {
ts = Long.MAX_VALUE;
for (Map.Entry<GlobalStreamId, Long> entry : streamToTs.entrySet()) {
ts = Math.min(ts, entry.getValue());
}
}
return ts - eventTsLag;
} | java | private long computeWaterMarkTs() {
long ts = 0;
// only if some data has arrived on each input stream
if (streamToTs.size() >= inputStreams.size()) {
ts = Long.MAX_VALUE;
for (Map.Entry<GlobalStreamId, Long> entry : streamToTs.entrySet()) {
ts = Math.min(ts, entry.getValue());
}
}
return ts - eventTsLag;
} | [
"private",
"long",
"computeWaterMarkTs",
"(",
")",
"{",
"long",
"ts",
"=",
"0",
";",
"// only if some data has arrived on each input stream",
"if",
"(",
"streamToTs",
".",
"size",
"(",
")",
">=",
"inputStreams",
".",
"size",
"(",
")",
")",
"{",
"ts",
"=",
"Long",
".",
"MAX_VALUE",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"GlobalStreamId",
",",
"Long",
">",
"entry",
":",
"streamToTs",
".",
"entrySet",
"(",
")",
")",
"{",
"ts",
"=",
"Math",
".",
"min",
"(",
"ts",
",",
"entry",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"return",
"ts",
"-",
"eventTsLag",
";",
"}"
] | Computes the min ts across all streams. | [
"Computes",
"the",
"min",
"ts",
"across",
"all",
"streams",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/backtype/storm/windowing/WaterMarkEventGenerator.java#L93-L103 |
25,192 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java | Common.topologyIdToName | public static String topologyIdToName(String topologyId) throws InvalidTopologyException {
String ret;
int index = topologyId.lastIndexOf('-');
if (index != -1 && index > 2) {
index = topologyId.lastIndexOf('-', index - 1);
if (index != -1 && index > 0)
ret = topologyId.substring(0, index);
else
throw new InvalidTopologyException(topologyId + " is not a valid topologyId");
} else
throw new InvalidTopologyException(topologyId + " is not a valid topologyId");
return ret;
} | java | public static String topologyIdToName(String topologyId) throws InvalidTopologyException {
String ret;
int index = topologyId.lastIndexOf('-');
if (index != -1 && index > 2) {
index = topologyId.lastIndexOf('-', index - 1);
if (index != -1 && index > 0)
ret = topologyId.substring(0, index);
else
throw new InvalidTopologyException(topologyId + " is not a valid topologyId");
} else
throw new InvalidTopologyException(topologyId + " is not a valid topologyId");
return ret;
} | [
"public",
"static",
"String",
"topologyIdToName",
"(",
"String",
"topologyId",
")",
"throws",
"InvalidTopologyException",
"{",
"String",
"ret",
";",
"int",
"index",
"=",
"topologyId",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"index",
"!=",
"-",
"1",
"&&",
"index",
">",
"2",
")",
"{",
"index",
"=",
"topologyId",
".",
"lastIndexOf",
"(",
"'",
"'",
",",
"index",
"-",
"1",
")",
";",
"if",
"(",
"index",
"!=",
"-",
"1",
"&&",
"index",
">",
"0",
")",
"ret",
"=",
"topologyId",
".",
"substring",
"(",
"0",
",",
"index",
")",
";",
"else",
"throw",
"new",
"InvalidTopologyException",
"(",
"topologyId",
"+",
"\" is not a valid topologyId\"",
")",
";",
"}",
"else",
"throw",
"new",
"InvalidTopologyException",
"(",
"topologyId",
"+",
"\" is not a valid topologyId\"",
")",
";",
"return",
"ret",
";",
"}"
] | Convert topologyId to topologyName. TopologyId = topoloygName-counter-timeStamp | [
"Convert",
"topologyId",
"to",
"topologyName",
".",
"TopologyId",
"=",
"topoloygName",
"-",
"counter",
"-",
"timeStamp"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java#L136-L148 |
25,193 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java | Common.charValidate | public static boolean charValidate(String name) {
if (name.matches("[0-9]+") || name.toLowerCase().equals("null")) {
return false;
} else {
return name.matches("[a-zA-Z0-9-_.]+");
}
} | java | public static boolean charValidate(String name) {
if (name.matches("[0-9]+") || name.toLowerCase().equals("null")) {
return false;
} else {
return name.matches("[a-zA-Z0-9-_.]+");
}
} | [
"public",
"static",
"boolean",
"charValidate",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"name",
".",
"matches",
"(",
"\"[0-9]+\"",
")",
"||",
"name",
".",
"toLowerCase",
"(",
")",
".",
"equals",
"(",
"\"null\"",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"name",
".",
"matches",
"(",
"\"[a-zA-Z0-9-_.]+\"",
")",
";",
"}",
"}"
] | Validation of topology name chars. Only alpha char, number, '-', '_', '.' are valid. | [
"Validation",
"of",
"topology",
"name",
"chars",
".",
"Only",
"alpha",
"char",
"number",
"-",
"_",
".",
"are",
"valid",
"."
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java#L153-L159 |
25,194 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java | Common.validate_ids | @SuppressWarnings("unchecked")
public static void validate_ids(StormTopology topology, String topologyId) throws InvalidTopologyException {
String topologyName = topologyIdToName(topologyId);
if (!charValidate(topologyName)) {
throw new InvalidTopologyException(topologyName + " is not a valid topology name. " + nameErrorInfo);
}
List<String> list = new ArrayList<>();
for (StormTopology._Fields field : Thrift.STORM_TOPOLOGY_FIELDS) {
Object value = topology.getFieldValue(field);
if (value != null) {
Map<String, Object> obj_map = (Map<String, Object>) value;
Set<String> commids = obj_map.keySet();
for (String id : commids) {
if (system_id(id) || !charComponentValidate(id)) {
throw new InvalidTopologyException(id + " is not a valid component id. " + compErrorInfo);
}
}
for (Object obj : obj_map.values()) {
validate_component(obj);
}
list.addAll(commids);
}
}
List<String> offending = JStormUtils.getRepeat(list);
if (!offending.isEmpty()) {
throw new InvalidTopologyException("Duplicate component ids: " + offending);
}
} | java | @SuppressWarnings("unchecked")
public static void validate_ids(StormTopology topology, String topologyId) throws InvalidTopologyException {
String topologyName = topologyIdToName(topologyId);
if (!charValidate(topologyName)) {
throw new InvalidTopologyException(topologyName + " is not a valid topology name. " + nameErrorInfo);
}
List<String> list = new ArrayList<>();
for (StormTopology._Fields field : Thrift.STORM_TOPOLOGY_FIELDS) {
Object value = topology.getFieldValue(field);
if (value != null) {
Map<String, Object> obj_map = (Map<String, Object>) value;
Set<String> commids = obj_map.keySet();
for (String id : commids) {
if (system_id(id) || !charComponentValidate(id)) {
throw new InvalidTopologyException(id + " is not a valid component id. " + compErrorInfo);
}
}
for (Object obj : obj_map.values()) {
validate_component(obj);
}
list.addAll(commids);
}
}
List<String> offending = JStormUtils.getRepeat(list);
if (!offending.isEmpty()) {
throw new InvalidTopologyException("Duplicate component ids: " + offending);
}
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"void",
"validate_ids",
"(",
"StormTopology",
"topology",
",",
"String",
"topologyId",
")",
"throws",
"InvalidTopologyException",
"{",
"String",
"topologyName",
"=",
"topologyIdToName",
"(",
"topologyId",
")",
";",
"if",
"(",
"!",
"charValidate",
"(",
"topologyName",
")",
")",
"{",
"throw",
"new",
"InvalidTopologyException",
"(",
"topologyName",
"+",
"\" is not a valid topology name. \"",
"+",
"nameErrorInfo",
")",
";",
"}",
"List",
"<",
"String",
">",
"list",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"StormTopology",
".",
"_Fields",
"field",
":",
"Thrift",
".",
"STORM_TOPOLOGY_FIELDS",
")",
"{",
"Object",
"value",
"=",
"topology",
".",
"getFieldValue",
"(",
"field",
")",
";",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"obj_map",
"=",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
")",
"value",
";",
"Set",
"<",
"String",
">",
"commids",
"=",
"obj_map",
".",
"keySet",
"(",
")",
";",
"for",
"(",
"String",
"id",
":",
"commids",
")",
"{",
"if",
"(",
"system_id",
"(",
"id",
")",
"||",
"!",
"charComponentValidate",
"(",
"id",
")",
")",
"{",
"throw",
"new",
"InvalidTopologyException",
"(",
"id",
"+",
"\" is not a valid component id. \"",
"+",
"compErrorInfo",
")",
";",
"}",
"}",
"for",
"(",
"Object",
"obj",
":",
"obj_map",
".",
"values",
"(",
")",
")",
"{",
"validate_component",
"(",
"obj",
")",
";",
"}",
"list",
".",
"addAll",
"(",
"commids",
")",
";",
"}",
"}",
"List",
"<",
"String",
">",
"offending",
"=",
"JStormUtils",
".",
"getRepeat",
"(",
"list",
")",
";",
"if",
"(",
"!",
"offending",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidTopologyException",
"(",
"\"Duplicate component ids: \"",
"+",
"offending",
")",
";",
"}",
"}"
] | Check Whether ID of Bolt or spout is system_id
@throws InvalidTopologyException | [
"Check",
"Whether",
"ID",
"of",
"Bolt",
"or",
"spout",
"is",
"system_id"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java#L173-L205 |
25,195 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java | Common.add_acker | public static void add_acker(Map stormConf, StormTopology ret) {
String key = Config.TOPOLOGY_ACKER_EXECUTORS;
Integer ackerNum = JStormUtils.parseInt(stormConf.get(key), 0);
// generate outputs
HashMap<String, StreamInfo> outputs = new HashMap<>();
ArrayList<String> fields = new ArrayList<>();
fields.add("id");
outputs.put(ACKER_ACK_STREAM_ID, Thrift.directOutputFields(fields));
outputs.put(ACKER_FAIL_STREAM_ID, Thrift.directOutputFields(fields));
IBolt ackerbolt = new Acker();
// generate inputs
Map<GlobalStreamId, Grouping> inputs = acker_inputs(ret);
// generate acker which will be stored in topology
Bolt acker_bolt = Thrift.mkBolt(inputs, ackerbolt, outputs, ackerNum);
// add every bolt two output stream
// ACKER_ACK_STREAM_ID/ACKER_FAIL_STREAM_ID
for (Entry<String, Bolt> e : ret.get_bolts().entrySet()) {
Bolt bolt = e.getValue();
ComponentCommon common = bolt.get_common();
List<String> ackList = JStormUtils.mk_list("id", "ack-val");
common.put_to_streams(ACKER_ACK_STREAM_ID, Thrift.outputFields(ackList));
List<String> failList = JStormUtils.mk_list("id");
common.put_to_streams(ACKER_FAIL_STREAM_ID, Thrift.outputFields(failList));
bolt.set_common(common);
}
// add every spout output stream ACKER_INIT_STREAM_ID
// add every spout two intput source
// ((ACKER_COMPONENT_ID, ACKER_ACK_STREAM_ID), directGrouping)
// ((ACKER_COMPONENT_ID, ACKER_FAIL_STREAM_ID), directGrouping)
for (Entry<String, SpoutSpec> kv : ret.get_spouts().entrySet()) {
SpoutSpec bolt = kv.getValue();
ComponentCommon common = bolt.get_common();
List<String> initList = JStormUtils.mk_list("id", "init-val", "spout-task");
common.put_to_streams(ACKER_INIT_STREAM_ID, Thrift.outputFields(initList));
GlobalStreamId ack_ack = new GlobalStreamId(ACKER_COMPONENT_ID, ACKER_ACK_STREAM_ID);
common.put_to_inputs(ack_ack, Thrift.mkDirectGrouping());
GlobalStreamId ack_fail = new GlobalStreamId(ACKER_COMPONENT_ID, ACKER_FAIL_STREAM_ID);
common.put_to_inputs(ack_fail, Thrift.mkDirectGrouping());
}
ret.put_to_bolts(ACKER_COMPONENT_ID, acker_bolt);
} | java | public static void add_acker(Map stormConf, StormTopology ret) {
String key = Config.TOPOLOGY_ACKER_EXECUTORS;
Integer ackerNum = JStormUtils.parseInt(stormConf.get(key), 0);
// generate outputs
HashMap<String, StreamInfo> outputs = new HashMap<>();
ArrayList<String> fields = new ArrayList<>();
fields.add("id");
outputs.put(ACKER_ACK_STREAM_ID, Thrift.directOutputFields(fields));
outputs.put(ACKER_FAIL_STREAM_ID, Thrift.directOutputFields(fields));
IBolt ackerbolt = new Acker();
// generate inputs
Map<GlobalStreamId, Grouping> inputs = acker_inputs(ret);
// generate acker which will be stored in topology
Bolt acker_bolt = Thrift.mkBolt(inputs, ackerbolt, outputs, ackerNum);
// add every bolt two output stream
// ACKER_ACK_STREAM_ID/ACKER_FAIL_STREAM_ID
for (Entry<String, Bolt> e : ret.get_bolts().entrySet()) {
Bolt bolt = e.getValue();
ComponentCommon common = bolt.get_common();
List<String> ackList = JStormUtils.mk_list("id", "ack-val");
common.put_to_streams(ACKER_ACK_STREAM_ID, Thrift.outputFields(ackList));
List<String> failList = JStormUtils.mk_list("id");
common.put_to_streams(ACKER_FAIL_STREAM_ID, Thrift.outputFields(failList));
bolt.set_common(common);
}
// add every spout output stream ACKER_INIT_STREAM_ID
// add every spout two intput source
// ((ACKER_COMPONENT_ID, ACKER_ACK_STREAM_ID), directGrouping)
// ((ACKER_COMPONENT_ID, ACKER_FAIL_STREAM_ID), directGrouping)
for (Entry<String, SpoutSpec> kv : ret.get_spouts().entrySet()) {
SpoutSpec bolt = kv.getValue();
ComponentCommon common = bolt.get_common();
List<String> initList = JStormUtils.mk_list("id", "init-val", "spout-task");
common.put_to_streams(ACKER_INIT_STREAM_ID, Thrift.outputFields(initList));
GlobalStreamId ack_ack = new GlobalStreamId(ACKER_COMPONENT_ID, ACKER_ACK_STREAM_ID);
common.put_to_inputs(ack_ack, Thrift.mkDirectGrouping());
GlobalStreamId ack_fail = new GlobalStreamId(ACKER_COMPONENT_ID, ACKER_FAIL_STREAM_ID);
common.put_to_inputs(ack_fail, Thrift.mkDirectGrouping());
}
ret.put_to_bolts(ACKER_COMPONENT_ID, acker_bolt);
} | [
"public",
"static",
"void",
"add_acker",
"(",
"Map",
"stormConf",
",",
"StormTopology",
"ret",
")",
"{",
"String",
"key",
"=",
"Config",
".",
"TOPOLOGY_ACKER_EXECUTORS",
";",
"Integer",
"ackerNum",
"=",
"JStormUtils",
".",
"parseInt",
"(",
"stormConf",
".",
"get",
"(",
"key",
")",
",",
"0",
")",
";",
"// generate outputs",
"HashMap",
"<",
"String",
",",
"StreamInfo",
">",
"outputs",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"ArrayList",
"<",
"String",
">",
"fields",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"fields",
".",
"add",
"(",
"\"id\"",
")",
";",
"outputs",
".",
"put",
"(",
"ACKER_ACK_STREAM_ID",
",",
"Thrift",
".",
"directOutputFields",
"(",
"fields",
")",
")",
";",
"outputs",
".",
"put",
"(",
"ACKER_FAIL_STREAM_ID",
",",
"Thrift",
".",
"directOutputFields",
"(",
"fields",
")",
")",
";",
"IBolt",
"ackerbolt",
"=",
"new",
"Acker",
"(",
")",
";",
"// generate inputs",
"Map",
"<",
"GlobalStreamId",
",",
"Grouping",
">",
"inputs",
"=",
"acker_inputs",
"(",
"ret",
")",
";",
"// generate acker which will be stored in topology",
"Bolt",
"acker_bolt",
"=",
"Thrift",
".",
"mkBolt",
"(",
"inputs",
",",
"ackerbolt",
",",
"outputs",
",",
"ackerNum",
")",
";",
"// add every bolt two output stream",
"// ACKER_ACK_STREAM_ID/ACKER_FAIL_STREAM_ID",
"for",
"(",
"Entry",
"<",
"String",
",",
"Bolt",
">",
"e",
":",
"ret",
".",
"get_bolts",
"(",
")",
".",
"entrySet",
"(",
")",
")",
"{",
"Bolt",
"bolt",
"=",
"e",
".",
"getValue",
"(",
")",
";",
"ComponentCommon",
"common",
"=",
"bolt",
".",
"get_common",
"(",
")",
";",
"List",
"<",
"String",
">",
"ackList",
"=",
"JStormUtils",
".",
"mk_list",
"(",
"\"id\"",
",",
"\"ack-val\"",
")",
";",
"common",
".",
"put_to_streams",
"(",
"ACKER_ACK_STREAM_ID",
",",
"Thrift",
".",
"outputFields",
"(",
"ackList",
")",
")",
";",
"List",
"<",
"String",
">",
"failList",
"=",
"JStormUtils",
".",
"mk_list",
"(",
"\"id\"",
")",
";",
"common",
".",
"put_to_streams",
"(",
"ACKER_FAIL_STREAM_ID",
",",
"Thrift",
".",
"outputFields",
"(",
"failList",
")",
")",
";",
"bolt",
".",
"set_common",
"(",
"common",
")",
";",
"}",
"// add every spout output stream ACKER_INIT_STREAM_ID",
"// add every spout two intput source",
"// ((ACKER_COMPONENT_ID, ACKER_ACK_STREAM_ID), directGrouping)",
"// ((ACKER_COMPONENT_ID, ACKER_FAIL_STREAM_ID), directGrouping)",
"for",
"(",
"Entry",
"<",
"String",
",",
"SpoutSpec",
">",
"kv",
":",
"ret",
".",
"get_spouts",
"(",
")",
".",
"entrySet",
"(",
")",
")",
"{",
"SpoutSpec",
"bolt",
"=",
"kv",
".",
"getValue",
"(",
")",
";",
"ComponentCommon",
"common",
"=",
"bolt",
".",
"get_common",
"(",
")",
";",
"List",
"<",
"String",
">",
"initList",
"=",
"JStormUtils",
".",
"mk_list",
"(",
"\"id\"",
",",
"\"init-val\"",
",",
"\"spout-task\"",
")",
";",
"common",
".",
"put_to_streams",
"(",
"ACKER_INIT_STREAM_ID",
",",
"Thrift",
".",
"outputFields",
"(",
"initList",
")",
")",
";",
"GlobalStreamId",
"ack_ack",
"=",
"new",
"GlobalStreamId",
"(",
"ACKER_COMPONENT_ID",
",",
"ACKER_ACK_STREAM_ID",
")",
";",
"common",
".",
"put_to_inputs",
"(",
"ack_ack",
",",
"Thrift",
".",
"mkDirectGrouping",
"(",
")",
")",
";",
"GlobalStreamId",
"ack_fail",
"=",
"new",
"GlobalStreamId",
"(",
"ACKER_COMPONENT_ID",
",",
"ACKER_FAIL_STREAM_ID",
")",
";",
"common",
".",
"put_to_inputs",
"(",
"ack_fail",
",",
"Thrift",
".",
"mkDirectGrouping",
"(",
")",
")",
";",
"}",
"ret",
".",
"put_to_bolts",
"(",
"ACKER_COMPONENT_ID",
",",
"acker_bolt",
")",
";",
"}"
] | Add acker bolt to topology | [
"Add",
"acker",
"bolt",
"to",
"topology"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java#L464-L521 |
25,196 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java | Common.component_conf | @SuppressWarnings("unchecked")
public static Map component_conf(TopologyContext topology_context, String component_id) {
Map<Object, Object> componentConf = new HashMap<>();
String jconf = topology_context.getComponentCommon(component_id).get_json_conf();
if (jconf != null) {
componentConf = (Map<Object, Object>) JStormUtils.from_json(jconf);
}
return componentConf;
} | java | @SuppressWarnings("unchecked")
public static Map component_conf(TopologyContext topology_context, String component_id) {
Map<Object, Object> componentConf = new HashMap<>();
String jconf = topology_context.getComponentCommon(component_id).get_json_conf();
if (jconf != null) {
componentConf = (Map<Object, Object>) JStormUtils.from_json(jconf);
}
return componentConf;
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"static",
"Map",
"component_conf",
"(",
"TopologyContext",
"topology_context",
",",
"String",
"component_id",
")",
"{",
"Map",
"<",
"Object",
",",
"Object",
">",
"componentConf",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"String",
"jconf",
"=",
"topology_context",
".",
"getComponentCommon",
"(",
"component_id",
")",
".",
"get_json_conf",
"(",
")",
";",
"if",
"(",
"jconf",
"!=",
"null",
")",
"{",
"componentConf",
"=",
"(",
"Map",
"<",
"Object",
",",
"Object",
">",
")",
"JStormUtils",
".",
"from_json",
"(",
"jconf",
")",
";",
"}",
"return",
"componentConf",
";",
"}"
] | get component configuration | [
"get",
"component",
"configuration"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java#L635-L644 |
25,197 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java | Common.get_task_object | public static Object get_task_object(StormTopology topology, String component_id, URLClassLoader loader) {
Map<String, SpoutSpec> spouts = topology.get_spouts();
Map<String, Bolt> bolts = topology.get_bolts();
Map<String, StateSpoutSpec> state_spouts = topology.get_state_spouts();
ComponentObject obj = null;
if (spouts.containsKey(component_id)) {
obj = spouts.get(component_id).get_spout_object();
} else if (bolts.containsKey(component_id)) {
obj = bolts.get(component_id).get_bolt_object();
} else if (state_spouts.containsKey(component_id)) {
obj = state_spouts.get(component_id).get_state_spout_object();
}
if (obj == null) {
throw new RuntimeException("Could not find " + component_id + " in " + topology.toString());
}
Object componentObject = Utils.getSetComponentObject(obj, loader);
Object rtn;
if (componentObject instanceof JavaObject) {
rtn = Thrift.instantiateJavaObject((JavaObject) componentObject);
} else if (componentObject instanceof ShellComponent) {
if (spouts.containsKey(component_id)) {
rtn = new ShellSpout((ShellComponent) componentObject);
} else {
rtn = new ShellBolt((ShellComponent) componentObject);
}
} else {
rtn = componentObject;
}
return rtn;
} | java | public static Object get_task_object(StormTopology topology, String component_id, URLClassLoader loader) {
Map<String, SpoutSpec> spouts = topology.get_spouts();
Map<String, Bolt> bolts = topology.get_bolts();
Map<String, StateSpoutSpec> state_spouts = topology.get_state_spouts();
ComponentObject obj = null;
if (spouts.containsKey(component_id)) {
obj = spouts.get(component_id).get_spout_object();
} else if (bolts.containsKey(component_id)) {
obj = bolts.get(component_id).get_bolt_object();
} else if (state_spouts.containsKey(component_id)) {
obj = state_spouts.get(component_id).get_state_spout_object();
}
if (obj == null) {
throw new RuntimeException("Could not find " + component_id + " in " + topology.toString());
}
Object componentObject = Utils.getSetComponentObject(obj, loader);
Object rtn;
if (componentObject instanceof JavaObject) {
rtn = Thrift.instantiateJavaObject((JavaObject) componentObject);
} else if (componentObject instanceof ShellComponent) {
if (spouts.containsKey(component_id)) {
rtn = new ShellSpout((ShellComponent) componentObject);
} else {
rtn = new ShellBolt((ShellComponent) componentObject);
}
} else {
rtn = componentObject;
}
return rtn;
} | [
"public",
"static",
"Object",
"get_task_object",
"(",
"StormTopology",
"topology",
",",
"String",
"component_id",
",",
"URLClassLoader",
"loader",
")",
"{",
"Map",
"<",
"String",
",",
"SpoutSpec",
">",
"spouts",
"=",
"topology",
".",
"get_spouts",
"(",
")",
";",
"Map",
"<",
"String",
",",
"Bolt",
">",
"bolts",
"=",
"topology",
".",
"get_bolts",
"(",
")",
";",
"Map",
"<",
"String",
",",
"StateSpoutSpec",
">",
"state_spouts",
"=",
"topology",
".",
"get_state_spouts",
"(",
")",
";",
"ComponentObject",
"obj",
"=",
"null",
";",
"if",
"(",
"spouts",
".",
"containsKey",
"(",
"component_id",
")",
")",
"{",
"obj",
"=",
"spouts",
".",
"get",
"(",
"component_id",
")",
".",
"get_spout_object",
"(",
")",
";",
"}",
"else",
"if",
"(",
"bolts",
".",
"containsKey",
"(",
"component_id",
")",
")",
"{",
"obj",
"=",
"bolts",
".",
"get",
"(",
"component_id",
")",
".",
"get_bolt_object",
"(",
")",
";",
"}",
"else",
"if",
"(",
"state_spouts",
".",
"containsKey",
"(",
"component_id",
")",
")",
"{",
"obj",
"=",
"state_spouts",
".",
"get",
"(",
"component_id",
")",
".",
"get_state_spout_object",
"(",
")",
";",
"}",
"if",
"(",
"obj",
"==",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not find \"",
"+",
"component_id",
"+",
"\" in \"",
"+",
"topology",
".",
"toString",
"(",
")",
")",
";",
"}",
"Object",
"componentObject",
"=",
"Utils",
".",
"getSetComponentObject",
"(",
"obj",
",",
"loader",
")",
";",
"Object",
"rtn",
";",
"if",
"(",
"componentObject",
"instanceof",
"JavaObject",
")",
"{",
"rtn",
"=",
"Thrift",
".",
"instantiateJavaObject",
"(",
"(",
"JavaObject",
")",
"componentObject",
")",
";",
"}",
"else",
"if",
"(",
"componentObject",
"instanceof",
"ShellComponent",
")",
"{",
"if",
"(",
"spouts",
".",
"containsKey",
"(",
"component_id",
")",
")",
"{",
"rtn",
"=",
"new",
"ShellSpout",
"(",
"(",
"ShellComponent",
")",
"componentObject",
")",
";",
"}",
"else",
"{",
"rtn",
"=",
"new",
"ShellBolt",
"(",
"(",
"ShellComponent",
")",
"componentObject",
")",
";",
"}",
"}",
"else",
"{",
"rtn",
"=",
"componentObject",
";",
"}",
"return",
"rtn",
";",
"}"
] | get object of component_id | [
"get",
"object",
"of",
"component_id"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java#L649-L683 |
25,198 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java | Common.getComponentMap | public static Map getComponentMap(DefaultTopologyAssignContext context, Integer task) {
String componentName = context.getTaskToComponent().get(task);
ComponentCommon componentCommon = ThriftTopologyUtils.getComponentCommon(context.getSysTopology(), componentName);
Map componentMap = (Map) JStormUtils.from_json(componentCommon.get_json_conf());
if (componentMap == null) {
componentMap = Maps.newHashMap();
}
return componentMap;
} | java | public static Map getComponentMap(DefaultTopologyAssignContext context, Integer task) {
String componentName = context.getTaskToComponent().get(task);
ComponentCommon componentCommon = ThriftTopologyUtils.getComponentCommon(context.getSysTopology(), componentName);
Map componentMap = (Map) JStormUtils.from_json(componentCommon.get_json_conf());
if (componentMap == null) {
componentMap = Maps.newHashMap();
}
return componentMap;
} | [
"public",
"static",
"Map",
"getComponentMap",
"(",
"DefaultTopologyAssignContext",
"context",
",",
"Integer",
"task",
")",
"{",
"String",
"componentName",
"=",
"context",
".",
"getTaskToComponent",
"(",
")",
".",
"get",
"(",
"task",
")",
";",
"ComponentCommon",
"componentCommon",
"=",
"ThriftTopologyUtils",
".",
"getComponentCommon",
"(",
"context",
".",
"getSysTopology",
"(",
")",
",",
"componentName",
")",
";",
"Map",
"componentMap",
"=",
"(",
"Map",
")",
"JStormUtils",
".",
"from_json",
"(",
"componentCommon",
".",
"get_json_conf",
"(",
")",
")",
";",
"if",
"(",
"componentMap",
"==",
"null",
")",
"{",
"componentMap",
"=",
"Maps",
".",
"newHashMap",
"(",
")",
";",
"}",
"return",
"componentMap",
";",
"}"
] | get the component's configuration | [
"get",
"the",
"component",
"s",
"configuration"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/cluster/Common.java#L726-L735 |
25,199 | alibaba/jstorm | jstorm-core/src/main/java/com/alibaba/jstorm/cluster/DistributedClusterState.java | DistributedClusterState.get_version | @Override
public Integer get_version(String path, boolean watch) throws Exception {
return zkObj.getVersion(zk, path, watch);
} | java | @Override
public Integer get_version(String path, boolean watch) throws Exception {
return zkObj.getVersion(zk, path, watch);
} | [
"@",
"Override",
"public",
"Integer",
"get_version",
"(",
"String",
"path",
",",
"boolean",
"watch",
")",
"throws",
"Exception",
"{",
"return",
"zkObj",
".",
"getVersion",
"(",
"zk",
",",
"path",
",",
"watch",
")",
";",
"}"
] | Note that get_version doesn't use zkCache avoid to conflict with get_data | [
"Note",
"that",
"get_version",
"doesn",
"t",
"use",
"zkCache",
"avoid",
"to",
"conflict",
"with",
"get_data"
] | 5d6cde22dbca7df3d6e6830bf94f98a6639ab559 | https://github.com/alibaba/jstorm/blob/5d6cde22dbca7df3d6e6830bf94f98a6639ab559/jstorm-core/src/main/java/com/alibaba/jstorm/cluster/DistributedClusterState.java#L149-L152 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.