_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q158800
BshArray.slice
train
public static Object slice(Object arr, int from, int to, int step) { Class<?> toType = Types.arrayElementType(arr.getClass()); int length = Array.getLength(arr); if ( to > length ) to = length; if ( 0 > from ) from = 0; length = to - from; if ( 0 >= length ) r...
java
{ "resource": "" }
q158801
BshArray.repeat
train
public static Object repeat(List<Object> list, int times) { if ( times < 1 ) if (list instanceof Queue) return new LinkedList<>(); else return new ArrayList<>(0); List<Object> lst = list instanceof Queue ? new LinkedList...
java
{ "resource": "" }
q158802
BshArray.repeat
train
public static Object repeat(Object arr, int times) { Class<?> toType = Types.arrayElementType(arr.getClass()); if ( times < 1 ) return Array.newInstance(toType, 0); int[] dims = dimensions(arr); int length = dims[0]; dims[0] *= times; int i = 0, total = dims[0...
java
{ "resource": "" }
q158803
BshArray.concat
train
public static Object concat(List<?> lhs, List<?> rhs) { List<Object> list = lhs instanceof Queue ? new LinkedList<>(lhs) : new ArrayList<>(lhs); list.addAll(rhs); return list; }
java
{ "resource": "" }
q158804
BshArray.dimensions
train
public static int[] dimensions(Object arr) { int[] dims = new int[Types.arrayDimensions(arr.getClass())]; if ( 0 == dims.length || 0 == (dims[0] = Array.getLength(arr)) ) return dims; for ( int i = 1; i < dims.length; i++ ) if ( null != (arr = Array.get(arr, 0)) ) ...
java
{ "resource": "" }
q158805
BshArray.mapOfEntries
train
private static Map<?, ?> mapOfEntries( Entry<?, ?>... entries ) { Map<Object, Object> looseTypedMap = new LinkedHashMap<>( entries.length ); for (Entry<?, ?> entry : entries) looseTypedMap.put(entry.getKey(), entry.getValue()); return looseTypedMap; }
java
{ "resource": "" }
q158806
BshArray.commonType
train
public static Class<?> commonType(Class<?> baseType, Object fromValue, IntSupplier length) { if ( Object.class != baseType ) return baseType; Class<?> common = null; int len = length.getAsInt(); for (int i = 0; i < len; i++) if ( Object.class == (common = Types.ge...
java
{ "resource": "" }
q158807
Name.toObject
train
public Object toObject( CallStack callstack, Interpreter interpreter ) throws UtilEvalError { return toObject( callstack, interpreter, false ); }
java
{ "resource": "" }
q158808
Name.resolveThisFieldReference
train
Object resolveThisFieldReference( CallStack callstack, NameSpace thisNameSpace, Interpreter interpreter, String varName, boolean specialFieldsVisible ) throws UtilEvalError { if ( varName.equals("this") ) { /* Somewhat of a hack. If the special fi...
java
{ "resource": "" }
q158809
BshServlet.escape
train
public static String escape(String value) { String search = "&<>"; String[] replace = {"&amp;", "&lt;", "&gt;"}; StringBuilder buf = new StringBuilder(); for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); int pos = search.indexOf(c)...
java
{ "resource": "" }
q158810
ReferenceCache.get
train
public V get(K key) { if (null == key) return null; CacheReference<K> refKey = lookupFactory.createKey(key, queue); if (cache.containsKey(refKey)) { V value = dereferenceValue(cache.get(refKey)); if (null != value) return value; cac...
java
{ "resource": "" }
q158811
ReferenceCache.init
train
public void init(K key) { if (null == key) return; CacheReference<K> refKey = keyFactory.createKey(key, queue); if (cache.containsKey(refKey)) return; FutureTask<CacheReference<V>> task = new FutureTask<>(()-> { V created = requireNonNull(create(key));...
java
{ "resource": "" }
q158812
ReferenceCache.remove
train
public boolean remove(K key) { if (null == key) return false; CacheReference<K> keyRef = lookupFactory.createKey(key, queue); return CacheKey.class.cast(keyRef).removeCacheEntry(); }
java
{ "resource": "" }
q158813
ReferenceCache.toFactory
train
private final ReferenceFactory<K,V> toFactory(Type type) { switch (type) { case Hard : return new HardReferenceFactory(); case Weak : return new WeakReferenceFactory(); case Soft : return new SoftReferenceFactory(); default : return null; } }
java
{ "resource": "" }
q158814
ReferenceCache.dereferenceValue
train
private V dereferenceValue(Future<CacheReference<V>> futureValue) { try { return dereferenceValue(futureValue.get()); } catch (final Throwable e) { return null; } }
java
{ "resource": "" }
q158815
Types.getTypes
train
public static Class<?>[] getTypes( Object[] args ) { if ( args == null ) return Reflect.ZERO_TYPES; Class<?>[] types = new Class[ args.length ]; for( int i=0; i < args.length; i++ ) types[i] = getType(args[i]); return types; }
java
{ "resource": "" }
q158816
Types.getType
train
public static Class<?> getType( Object arg, boolean boxed ) { if ( null == arg || Primitive.NULL == arg ) return null; if ( arg instanceof Primitive && !boxed ) return ((Primitive) arg).getType(); return Primitive.unwrap(arg).getClass(); }
java
{ "resource": "" }
q158817
Types.areSignaturesEqual
train
static boolean areSignaturesEqual(Class[] from, Class[] to) { if (from.length != to.length) return false; for (int i = 0; i < from.length; i++) if (from[i] != to[i]) return false; return true; }
java
{ "resource": "" }
q158818
Types.arrayElementType
train
public static Class<?> arrayElementType(Class<?> arrType) { if ( null == arrType ) return null; while ( arrType.isArray() ) arrType = arrType.getComponentType(); return arrType; }
java
{ "resource": "" }
q158819
Types.arrayDimensions
train
public static int arrayDimensions(Class<?> arrType) { if ( null == arrType || !arrType.isArray() ) return 0; return arrType.getName().lastIndexOf('[') + 1; }
java
{ "resource": "" }
q158820
Types.getCommonType
train
public static Class<?> getCommonType(Class<?> common, Class<?> compare) { if ( null == common ) return compare; if ( null == compare || common.isAssignableFrom(compare) ) return common; // pick the largest number type based on NUMBER_ORDER definitions if ( NUMBER...
java
{ "resource": "" }
q158821
Types.castError
train
static UtilEvalError castError( Class lhsType, Class rhsType, int operation ) { return castError( StringUtil.typeString(lhsType), StringUtil.typeString(rhsType), operation ); }
java
{ "resource": "" }
q158822
Types.getBaseName
train
public static String getBaseName(String className) { int i = className.indexOf("$"); if (i == -1) return className; return className.substring(i + 1); }
java
{ "resource": "" }
q158823
BSHFormalParameters.eval
train
public Object eval( CallStack callstack, Interpreter interpreter ) throws EvalError { if ( paramTypes != null ) return paramTypes; insureParsed(); Class [] paramTypes = new Class[numArgs]; for(int i=0; i<numArgs; i++) { BSHFormalParameter par...
java
{ "resource": "" }
q158824
MethodWriter.computeMethodInfoSize
train
int computeMethodInfoSize() { // If this method_info must be copied from an existing one, the size computation is trivial. if (sourceOffset != 0) { // sourceLength excludes the first 6 bytes for access_flags, name_index and descriptor_index. return 6 + sourceLength; } // 2 bytes each for acc...
java
{ "resource": "" }
q158825
ScriptContextEngineView.put
train
@Override public Object put(String key, Object value) { Object oldValue = context.getAttribute(key, ENGINE_SCOPE); context.setAttribute(key, value, ENGINE_SCOPE); return oldValue; }
java
{ "resource": "" }
q158826
ScriptContextEngineView.putAll
train
@Override public void putAll(Map<? extends String, ? extends Object> t) { context.getBindings(ENGINE_SCOPE).putAll(t); }
java
{ "resource": "" }
q158827
Type.getDescriptor
train
public String getDescriptor() { if (sort == OBJECT) { return valueBuffer.substring(valueBegin - 1, valueEnd + 1); } else if (sort == INTERNAL) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append('L'); stringBuilder.append(valueBuffer, valueBegin, valueEnd); st...
java
{ "resource": "" }
q158828
Type.appendDescriptor
train
private static void appendDescriptor(final StringBuilder stringBuilder, final Class<?> clazz) { Class<?> currentClass = clazz; while (currentClass.isArray()) { stringBuilder.append('['); currentClass = currentClass.getComponentType(); } if (currentClass.isPrimitive()) { char descriptor...
java
{ "resource": "" }
q158829
Frame.setInputFrameFromApiFormat
train
final void setInputFrameFromApiFormat( final SymbolTable symbolTable, final int nLocal, final Object[] local, final int nStack, final Object[] stack) { int inputLocalIndex = 0; for (int i = 0; i < nLocal; ++i) { inputLocals[inputLocalIndex++] = getAbstractTypeFromApiFormat(sy...
java
{ "resource": "" }
q158830
Reflect.invokeStaticMethod
train
public static Object invokeStaticMethod( BshClassManager bcm, Class<?> clas, String methodName, Object [] args, SimpleNode callerInfo ) throws ReflectError, UtilEvalError, InvocationTargetException { Interpreter.debug("invoke static Method")...
java
{ "resource": "" }
q158831
Reflect.getObjectFieldValue
train
public static Object getObjectFieldValue( Object object, String fieldName ) throws UtilEvalError, ReflectError { if ( object instanceof This ) { return ((This) object).namespace.getVariable( fieldName ); } else if( object == Primitive.NULL ) { throw new UtilTargetErro...
java
{ "resource": "" }
q158832
Reflect.getLHSObjectField
train
static LHS getLHSObjectField( Object object, String fieldName ) throws UtilEvalError, ReflectError { if ( object instanceof This ) return new LHS( ((This)object).namespace, fieldName, false ); try { Invocable f = resolveExpectedJavaField( object.getCla...
java
{ "resource": "" }
q158833
Reflect.staticMethodImport
train
static BshMethod staticMethodImport(Class<?> baseClass, String methodName) { Invocable method = BshClassManager.memberCache.get(baseClass) .findStaticMethod(methodName); if (null != method) return new BshMethod(method, null); return null; }
java
{ "resource": "" }
q158834
Reflect.getClassStaticThis
train
public static This getClassStaticThis(Class<?> clas, String className) { try { return (This) getStaticFieldValue(clas, BSHSTATIC + className); } catch (Exception e) { throw new InterpreterError("Unable to get class static space: " + e, e); } }
java
{ "resource": "" }
q158835
Reflect.getClassInstanceThis
train
public static This getClassInstanceThis(Object instance, String className) { try { Object o = getObjectFieldValue(instance, BSHTHIS + className); return (This) Primitive.unwrap(o); // unwrap Primitive.Null to null } catch (Exception e) { throw new InterpreterError("Ge...
java
{ "resource": "" }
q158836
BshClassManager.createClassManager
train
public static BshClassManager createClassManager( Interpreter interpreter ) { BshClassManager manager; // Do we have the optional package? if ( Capabilities.classExists("bsh.classpath.ClassManagerImpl") ) try { // Try to load the module // don't r...
java
{ "resource": "" }
q158837
BshClassManager.cacheClassInfo
train
public void cacheClassInfo( String name, Class<?> value ) { if ( value != null ) { absoluteClassCache.put(name, value); // eagerly start the member cache memberCache.init(value); } else absoluteNonClasses.add( name ); }
java
{ "resource": "" }
q158838
BshClassManager.getClassBeingDefined
train
protected String getClassBeingDefined( String className ) { String baseName = Name.suffix(className,1); return definingClassesBaseNames.get( baseName ); }
java
{ "resource": "" }
q158839
BshClassManager.doneDefiningClass
train
protected void doneDefiningClass( String className ) { String baseName = Name.suffix(className,1); definingClasses.remove( className ); definingClassesBaseNames.remove( baseName ); }
java
{ "resource": "" }
q158840
BSHPrimaryExpression.setArrayExpression
train
void setArrayExpression(BSHArrayInitializer init) { this.isArrayExpression = true; if (parent instanceof BSHAssignment) { BSHAssignment ass = (BSHAssignment) parent; if ( null != ass.operator && ass.operator == ParserConstants.ASSIGN ) this.isM...
java
{ "resource": "" }
q158841
BSHPrimaryExpression.toLHS
train
public LHS toLHS( CallStack callstack, Interpreter interpreter) throws EvalError { // loosely typed map expression new {a=1, b=2} are treated // as non assignment (LHS) to retrieve Map.Entry key values // then wrapped in a MAP_ENTRY type LHS for value assignment. return (LHS)...
java
{ "resource": "" }
q158842
TypeReference.putTarget
train
static void putTarget(final int targetTypeAndInfo, final ByteVector output) { switch (targetTypeAndInfo >>> 24) { case CLASS_TYPE_PARAMETER: case METHOD_TYPE_PARAMETER: case METHOD_FORMAL_PARAMETER: output.putShort(targetTypeAndInfo >>> 16); break; case FIELD: case METH...
java
{ "resource": "" }
q158843
BeanShellBSFEngine.call
train
public Object call( Object object, String name, Object[] args ) throws BSFException { /* If object is null use the interpreter's global scope. */ if ( object == null ) try { object = interpreter.get("global"); } catch ( EvalError e ...
java
{ "resource": "" }
q158844
ClassBrowser.driveToClass
train
public void driveToClass( String classname ) { String [] sa = BshClassPath.splitClassname( classname ); String packn = sa[0]; String classn = sa[1]; // Do we have the package? if ( classPath.getClassesForPackage(packn).size()==0 ) return; ptree.setSelectedPa...
java
{ "resource": "" }
q158845
Primitive.getValue
train
public Object getValue() { if ( value == Special.NULL_VALUE ) return null; if ( value == Special.VOID_TYPE ) throw new InterpreterError("attempt to unwrap void type"); return value; }
java
{ "resource": "" }
q158846
Primitive.getType
train
public Class<?> getType() { if ( this == Primitive.VOID ) return Void.TYPE; // NULL return null as type... we currently use null type to indicate // loose typing throughout bsh. if ( this == Primitive.NULL ) return null; return unboxType( value.getCl...
java
{ "resource": "" }
q158847
Primitive.unwrap
train
public static Object unwrap( Object obj ) { // map voids to nulls for the outside world if (obj == Primitive.VOID) return null; // unwrap primitives if (obj instanceof Primitive) return((Primitive)obj).getValue(); return obj; }
java
{ "resource": "" }
q158848
Primitive.getDefaultValue
train
public static Primitive getDefaultValue( Class<?> type ) { if ( type == null ) return Primitive.NULL; if ( Boolean.TYPE == type || Boolean.class == type ) return Primitive.FALSE; if ( Character.TYPE == type || Character.class == type ) return Primitive.ZER...
java
{ "resource": "" }
q158849
FieldWriter.computeFieldInfoSize
train
int computeFieldInfoSize() { // The access_flags, name_index, descriptor_index and attributes_count fields use 8 bytes. int size = 8; // For ease of reference, we use here the same attribute order as in Section 4.7 of the JVMS. if (constantValueIndex != 0) { // ConstantValue attributes always use ...
java
{ "resource": "" }
q158850
FieldWriter.putFieldInfo
train
void putFieldInfo(final ByteVector output) { boolean useSyntheticAttribute = symbolTable.getMajorVersion() < Opcodes.V1_5; // Put the access_flags, name_index and descriptor_index fields. int mask = useSyntheticAttribute ? Opcodes.ACC_SYNTHETIC : 0; output.putShort(accessFlags & ~mask).putShort(nameInde...
java
{ "resource": "" }
q158851
UtilTargetError.toEvalError
train
public EvalError toEvalError( String msg, SimpleNode node, CallStack callstack ) { if ( null == msg ) msg = this.getMessage(); else msg += ": " + this.getMessage(); return new TargetError( msg, this.getCause(), node, callstack, false ); }
java
{ "resource": "" }
q158852
BSHMethodDeclaration.insureNodesParsed
train
synchronized void insureNodesParsed() { if ( paramsNode != null ) // there is always a paramsNode return; Object firstNode = jjtGetChild(0); firstThrowsClause = 1; if ( firstNode instanceof BSHReturnType ) { returnTypeNode = (BSHReturnType)firstNode; ...
java
{ "resource": "" }
q158853
BSHMethodDeclaration.evalReturnType
train
Class evalReturnType( CallStack callstack, Interpreter interpreter ) throws EvalError { insureNodesParsed(); if ( returnTypeNode != null ) return returnTypeNode.evalReturnType( callstack, interpreter ); else return null; }
java
{ "resource": "" }
q158854
BSHMethodDeclaration.eval
train
public Object eval( CallStack callstack, Interpreter interpreter ) throws EvalError { returnType = evalReturnType( callstack, interpreter ); evalNodes( callstack, interpreter ); // Install an *instance* of this method in the namespace. // See notes in BshMethod // This is n...
java
{ "resource": "" }
q158855
ZooKeeperUtil.createAcl
train
public static ArrayList<ACL> createAcl(FailoverWatcher failoverWatcher, String znode) { if (znode.equals("/chronos")) { return Ids.OPEN_ACL_UNSAFE; } if (failoverWatcher.isZkSecure()) { ArrayList<ACL> acls = new ArrayList<ACL>(); acls.add(new ACL(ZooDefs.Perms.READ, ZooDefs.Ids.ANYONE...
java
{ "resource": "" }
q158856
ZooKeeperUtil.longToBytes
train
public static byte[] longToBytes(long val) { byte[] b = new byte[8]; for (int i = 7; i > 0; i--) { b[i] = (byte) val; val >>>= 8; } b[0] = (byte) val; return b; }
java
{ "resource": "" }
q158857
ZooKeeperUtil.bytesToLong
train
public static long bytesToLong(byte[] bytes) { long l = 0; for (int i = 0; i < 0 + 8; i++) { l <<= 8; l ^= bytes[i] & 0xFF; } return l; }
java
{ "resource": "" }
q158858
ChronosClientWatcher.reconnectZooKeeper
train
private void reconnectZooKeeper() throws InterruptedException, IOException { LOG.info("Try to reconnect ZooKeeper " + zkQuorum); if (zooKeeper != null) { zooKeeper.close(); } connectZooKeeper(); }
java
{ "resource": "" }
q158859
ChronosClientWatcher.connectChronosServer
train
private void connectChronosServer() throws IOException { LOG.info("Try to connect chronos server"); byte[] hostPortBytes = getData(this, masterZnode); if (hostPortBytes != null) { String hostPort = new String(hostPortBytes); // e.g. 127.0.0.0_2181 LOG.info("Find the active chronos server i...
java
{ "resource": "" }
q158860
ChronosClientWatcher.getTimestamps
train
public long getTimestamps(int range) throws IOException { long timestamp; try { timestamp = client.getTimestamps(range); } catch (TException e) { LOG.info("Can't get timestamp, try to connect the active chronos server"); try { reconnectChronosServer(); return client.getTime...
java
{ "resource": "" }
q158861
ChronosClientWatcher.process
train
@Override public void process(WatchedEvent event) { if (LOG.isDebugEnabled()) { LOG.info("Received ZooKeeper Event, " + "type=" + event.getType() + ", " + "state=" + event.getState() + ", " + "path=" + event.getPath()); } switch (event.getType()) { case None: { switch (event.get...
java
{ "resource": "" }
q158862
ChronosClientWatcher.waitToInitZooKeeper
train
public void waitToInitZooKeeper(long maxWaitMillis) throws Exception { long finished = System.currentTimeMillis() + maxWaitMillis; while (System.currentTimeMillis() < finished) { if (this.zooKeeper != null) { return; } try { Thread.sleep(1); } catch (Inter...
java
{ "resource": "" }
q158863
ChronosClientWatcher.getData
train
public byte[] getData(ChronosClientWatcher chronosClientWatcher, String znode) throws IOException { byte[] data = null; for (int i = 0; i <= connectRetryTimes; i++) { try { data = chronosClientWatcher.getZooKeeper().getData(znode, null, null); break; } catch (Exception e) { ...
java
{ "resource": "" }
q158864
ChronosServer.initThriftServer
train
private void initThriftServer() throws TTransportException, FatalChronosException, ChronosException { int maxThread = Integer.parseInt(properties.getProperty(MAX_THREAD, String.valueOf(Integer.MAX_VALUE))); String serverHost = properties.getProperty(FailoverServer.SERVER_HOST); int serverPort =...
java
{ "resource": "" }
q158865
ChronosServer.doAsActiveServer
train
@Override public void doAsActiveServer() { try { LOG.info("As active master, init timestamp from ZooKeeper"); chronosImplement.initTimestamp(); } catch (Exception e) { LOG.fatal("Exception to init timestamp from ZooKeeper, exit immediately"); System.exit(0); } chronosServe...
java
{ "resource": "" }
q158866
ChronosServer.main
train
public static void main(String[] args) { Properties properties = new Properties(); LOG.info("Load chronos.cfg configuration from class path"); try { properties.load(ChronosServer.class.getClassLoader().getResourceAsStream("chronos.cfg")); properties.setProperty(FailoverServer.BASE_ZNODE, ...
java
{ "resource": "" }
q158867
ChronosServerWatcher.initZnode
train
@Override protected void initZnode() { try { ZooKeeperUtil.createAndFailSilent(this, "/chronos"); super.initZnode(); ZooKeeperUtil.createAndFailSilent(this, baseZnode + "/persistent-timestamp"); } catch (Exception e) { LOG.fatal("Error to create znode of chronos, exit immediately"); ...
java
{ "resource": "" }
q158868
ChronosServerWatcher.getPersistentTimestamp
train
public long getPersistentTimestamp() throws ChronosException { byte[] persistentTimesampBytes = null; for (int i = 0; i <= connectRetryTimes; ++i) { try { persistentTimesampBytes = ZooKeeperUtil.getDataAndWatch(this, persistentTimestampZnode); break; } catch (KeeperException e) { ...
java
{ "resource": "" }
q158869
ChronosServerWatcher.setPersistentTimestamp
train
public void setPersistentTimestamp(long newTimestamp) throws FatalChronosException, ChronosException { if (newTimestamp <= persistentTimestamp) { throw new FatalChronosException("Fatal error to set a smaller timestamp"); } if (LOG.isDebugEnabled()) { LOG.debug("Setting persistent timestam...
java
{ "resource": "" }
q158870
ChronosServerWatcher.processConnection
train
@Override protected void processConnection(WatchedEvent event) { super.processConnection(event); switch (event.getState()) { case Disconnected: if (beenActiveMaster) { LOG.fatal(hostPort.getHostPort() + " disconnected from ZooKeeper, stop serving and exit immediately"); S...
java
{ "resource": "" }
q158871
FailoverWatcher.connectZooKeeper
train
protected void connectZooKeeper() throws IOException { LOG.info("Connecting ZooKeeper " + zkQuorum); for (int i = 0; i <= connectRetryTimes; i++) { try { zooKeeper = new ZooKeeper(zkQuorum, sessionTimeout, this); break; } catch (IOException e) { if (i == connectRetryTimes) {...
java
{ "resource": "" }
q158872
FailoverWatcher.initZnode
train
protected void initZnode() { try { ZooKeeperUtil.createAndFailSilent(this, baseZnode); ZooKeeperUtil.createAndFailSilent(this, backupServersZnode); } catch (Exception e) { LOG.fatal("Error to create znode " + baseZnode + " and " + backupServersZnode + ", exit immediately", e); ...
java
{ "resource": "" }
q158873
FailoverWatcher.process
train
@Override public void process(WatchedEvent event) { if (LOG.isDebugEnabled()) { LOG.debug("Received ZooKeeper Event, " + "type=" + event.getType() + ", " + "state=" + event.getState() + ", " + "path=" + event.getPath()); } switch (event.getType()) { case None: { processConnectio...
java
{ "resource": "" }
q158874
FailoverWatcher.processConnection
train
protected void processConnection(WatchedEvent event) { switch (event.getState()) { case SyncConnected: LOG.info(hostPort.getHostPort() + " sync connect from ZooKeeper"); try { waitToInitZooKeeper(2000); // init zookeeper in another thread, wait for a while } catch (Exception e) { ...
java
{ "resource": "" }
q158875
FailoverWatcher.processNodeCreated
train
protected void processNodeCreated(String path) { if (path.equals(masterZnode)) { LOG.info(masterZnode + " created and try to become active master"); handleMasterNodeChange(); } }
java
{ "resource": "" }
q158876
FailoverWatcher.processNodeDeleted
train
protected void processNodeDeleted(String path) { if (path.equals(masterZnode)) { LOG.info(masterZnode + " deleted and try to become active master"); handleMasterNodeChange(); } }
java
{ "resource": "" }
q158877
FailoverWatcher.handleMasterNodeChange
train
private void handleMasterNodeChange() { try { synchronized (hasActiveServer) { if (ZooKeeperUtil.watchAndCheckExists(this, masterZnode)) { // A master node exists, there is an active master if (LOG.isDebugEnabled()) { LOG.debug("A master is now available"); } ...
java
{ "resource": "" }
q158878
FailoverWatcher.blockUntilActive
train
public boolean blockUntilActive() { while (true) { try { if (ZooKeeperUtil.createEphemeralNodeAndWatch(this, masterZnode, hostPort.getHostPort() .getBytes())) { // If we were a backup master before, delete our ZNode from the backup // master directory since we are the a...
java
{ "resource": "" }
q158879
FailoverWatcher.close
train
public void close() { if (zooKeeper != null) { try { zooKeeper.close(); } catch (InterruptedException e) { LOG.error("Interrupt when closing zookeeper connection", e); } } }
java
{ "resource": "" }
q158880
HostPort.parseHostPort
train
public static HostPort parseHostPort(String string) { String[] strings = string.split("_"); return new HostPort(strings[0], Integer.parseInt(strings[1])); }
java
{ "resource": "" }
q158881
ChronosImplement.getTimestamps
train
public long getTimestamps(int range) throws TException { // can get 2^18(262144) times for each millisecond for about 1115 years long currentTime = System.currentTimeMillis() << 18; synchronized (this) { // maxAssignedTimestamp is assigned last time, can't return currentTime when it's less or equal ...
java
{ "resource": "" }
q158882
ChronosImplement.sleepUntilAsyncSet
train
private void sleepUntilAsyncSet() { LOG.info("Sleep a while until asynchronously set persistent timestamp"); while (isAsyncSetPersistentTimestamp) { try { Thread.sleep(1); } catch (InterruptedException e) { LOG.fatal("Interrupt when sleep to set persistent timestamp, exit immediately...
java
{ "resource": "" }
q158883
ChronosImplement.initTimestamp
train
public void initTimestamp() throws ChronosException, FatalChronosException { maxAssignedTimestamp = chronosServerWatcher.getPersistentTimestamp(); long newPersistentTimestamp = maxAssignedTimestamp + zkAdvanceTimestamp; chronosServerWatcher.setPersistentTimestamp(newPersistentTimestamp); LOG.info("Get p...
java
{ "resource": "" }
q158884
ChronosImplement.asyncSetPersistentTimestamp
train
public synchronized void asyncSetPersistentTimestamp(final long newPersistentTimestamp) { new Thread() { @Override public void run() { try { chronosServerWatcher.setPersistentTimestamp(newPersistentTimestamp); isAsyncSetPersistentTimestamp = false; } catch (Exception ...
java
{ "resource": "" }
q158885
FailoverServer.doAsActiveServer
train
public void doAsActiveServer() { while (true) { LOG.info("No business logic, sleep for " + Integer.MAX_VALUE); try { Thread.sleep(Integer.MAX_VALUE); } catch (InterruptedException e) { LOG.error("Interrupt when sleeping as active master", e); } } }
java
{ "resource": "" }
q158886
BenchmarkChronosServer.startBenchmark
train
public void startBenchmark() { startTime = System.currentTimeMillis(); LOG.info("Start to benchmark chronos server"); Thread t = new Thread() { // new thread to output the metrics @Override public void run() { final long collectPeriod = 10000; LOG.info("Start another thread to e...
java
{ "resource": "" }
q158887
BitSet.set
train
public void set(long startIndex, long endIndex) { if (endIndex <= startIndex) return; int startWord = (int) (startIndex >> 6); // since endIndex is one past the end, this is index of the last // word to be changed. int endWord = expandingWordNum(endIndex - 1); long...
java
{ "resource": "" }
q158888
BitSet.clear
train
public void clear(int startIndex, int endIndex) { if (endIndex <= startIndex) return; int startWord = (startIndex >> 6); if (startWord >= wlen) return; // since endIndex is one past the end, this is index of the last // word to be changed. int endWord = ((endIndex -...
java
{ "resource": "" }
q158889
BitSet.getAndSet
train
public boolean getAndSet(int index) { int wordNum = index >> 6; // div 64 int bit = index & 0x3f; // mod 64 long bitmask = 1L << bit; boolean val = (bits[wordNum] & bitmask) != 0; bits[wordNum] |= bitmask; return val; }
java
{ "resource": "" }
q158890
BitSet.flipAndGet
train
public boolean flipAndGet(long index) { int wordNum = (int) (index >> 6); // div 64 int bit = (int) index & 0x3f; // mod 64 long bitmask = 1L << bit; bits[wordNum] ^= bitmask; return (bits[wordNum] & bitmask) != 0; }
java
{ "resource": "" }
q158891
BitSet.flip
train
public void flip(long startIndex, long endIndex) { if (endIndex <= startIndex) return; int startWord = (int) (startIndex >> 6); // since endIndex is one past the end, this is index of the last // word to be changed. int endWord = expandingWordNum(endIndex - 1); long...
java
{ "resource": "" }
q158892
BitSetIterator.shift
train
private void shift() { if ((int)word ==0) {wordShift +=32; word = word >>>32; } if ((word & 0x0000FFFF) == 0) { wordShift +=16; word >>>=16; } if ((word & 0x000000FF) == 0) { wordShift +=8; word >>>=8; } indexArray = bitlist[(int)word & 0xff]; }
java
{ "resource": "" }
q158893
KTypeStack.push
train
public void push(KType e1, KType e2) { ensureBufferSpace(2); buffer[elementsCount++] = e1; buffer[elementsCount++] = e2; }
java
{ "resource": "" }
q158894
KTypeStack.push
train
public void push(KType[] elements, int start, int len) { assert start >= 0 && len >= 0; ensureBufferSpace(len); System.arraycopy(elements, start, buffer, elementsCount, len); elementsCount += len; }
java
{ "resource": "" }
q158895
KTypeStack.discard
train
public void discard(int count) { assert elementsCount >= count; elementsCount -= count; /* #if ($TemplateOptions.KTypeGeneric) */ Arrays.fill(buffer, elementsCount, elementsCount + count, null); /* #end */ }
java
{ "resource": "" }
q158896
KTypeStack.pop
train
public KType pop() { assert elementsCount > 0; final KType v = Intrinsics.<KType> cast(buffer[--elementsCount]); /* #if ($TemplateOptions.KTypeGeneric) */ buffer[elementsCount] = null; /* #end */ return v; }
java
{ "resource": "" }
q158897
Intrinsics.add
train
@SuppressWarnings("unchecked") public static <T> T add(T op1, T op2) { if (op1.getClass() != op2.getClass()) { throw new RuntimeException("Arguments of different classes: " + op1 + " " + op2); } if (Byte.class.isInstance(op1)) { return (T)(Byte)(byte)(((Byte) op1).byteValue() + ((Byte) op2).b...
java
{ "resource": "" }
q158898
AbstractKTypeCollection.removeAll
train
@Override public int removeAll(final KTypeLookupContainer<? super KType> c) { // We know c holds sub-types of KType and we're not modifying c, so go unchecked. return this.removeAll(new KTypePredicate<KType>() { public boolean apply(KType k) { return c.contains(k); } }); }
java
{ "resource": "" }
q158899
AbstractKTypeCollection.toArray
train
@Override /*!#if ($TemplateOptions.KTypePrimitive) public KType [] toArray() #else !*/ public Object[] toArray() /*! #end !*/ { KType[] array = Intrinsics.<KType> newArray(size()); int i = 0; for (KTypeCursor<KType> c : this) { array[i++] = c.value; } return array; ...
java
{ "resource": "" }