code
stringlengths
73
34.1k
label
stringclasses
1 value
@Override public boolean containsKey(Object key) { if (key == null) { return false; } K []keys = _keys; for (int i = _size - 1 ; i >= 0; i--) { K testKey = keys[i]; if (key.equals(testKey)) { return true; } } return false; }
java
public void start() { _state = _state.toStart(); _bufferCapacity = DEFAULT_SIZE; _tBuf = TempBuffer.create(); _buffer = _tBuf.buffer(); _startOffset = bufferStart(); _offset = _startOffset; _contentLength = 0; }
java
@Override public void write(int ch) throws IOException { if (isClosed() || isHead()) { return; } int offset = _offset; if (SIZE <= offset) { flushByteBuffer(); offset = _offset; } _buffer[offset++] = (byte) ch; _offset = offset; }
java
@Override public void write(byte []buffer, int offset, int length) { if (isClosed() || isHead()) { return; } int byteLength = _offset; while (true) { int sublen = Math.min(length, SIZE - byteLength); System.arraycopy(buffer, offset, _buffer, byteLength, sublen); offset...
java
@Override public byte []nextBuffer(int offset) throws IOException { if (offset < 0 || SIZE < offset) { throw new IllegalStateException(L.l("Invalid offset: " + offset)); } if (_bufferCapacity <= SIZE || _bufferCapacity <= offset + _bufferSize) { _offset = offset; flush...
java
@Override public final void close() throws IOException { State state = _state; if (state.isClosing()) { return; } _state = state.toClosing(); try { flush(true); } finally { try { _state = _state.toClose(); } catch (RuntimeException e) { ...
java
private void flush(boolean isEnd) { if (_startOffset == _offset && _bufferSize == 0) { if (! isCommitted() || isEnd) { flush(null, isEnd); _startOffset = bufferStart(); _offset = _startOffset; } return; } int sublen = _offset - _startOffset; _tBuf.length(_off...
java
private boolean readSend(InH3 hIn, OutboxAmp outbox, HeadersAmp headers) throws IOException { MethodRefHamp methodHamp = null; try { methodHamp = readMethod(hIn); } catch (Throwable e) { log.log(Level.FINER, e.toString(), e); ...
java
private void readQuery(InH3 hIn, OutboxAmp outbox, HeadersAmp headers) throws IOException { GatewayReply from = readFromAddress(hIn); long qid = hIn.readLong(); long timeout = 120 * 1000L; /* AmpQueryRef queryRef = new Qu...
java
private void readQueryResult(InH3 hIn, HeadersAmp headers) throws IOException { ServiceRefAmp serviceRef = readToAddress(hIn); long id = hIn.readLong(); QueryRefAmp queryRef = serviceRef.removeQueryRef(id); if (queryRef != null) { ClassLoader loader = queryRef.getClassLoader(); ...
java
public void addInclude(PathPatternType pattern) { if (_includeList == null) _includeList = new ArrayList<PathPatternType>(); _includeList.add(pattern); }
java
public void setUserPathPrefix(String prefix) { if (prefix != null && ! prefix.equals("") && ! prefix.endsWith("/")) _userPathPrefix = prefix + "/"; else _userPathPrefix = prefix; }
java
@Override public ExprKraken getKeyExpr(String name) { if (name.equals(_column.getColumn().name())) { return getRight(); } else { return null; } }
java
@Override public void write(byte []buf, int offset, int length, boolean isEnd) throws IOException { OutputStream stream = getStream(); if (stream == null) { return; } synchronized (stream) { stream.write(buf, offset, length); if (isEnd) { stream.flush(); ...
java
@Override public void flush() throws IOException { OutputStream stream = getStream(); if (stream == null) { return; } synchronized (stream) { stream.flush(); } }
java
public synchronized static void setStdout(OutputStream os) { if (_stdoutStream == null) { initStdout(); } if (os == _systemErr || os == _systemOut) { return; } if (os instanceof WriteStream) { WriteStream out = (WriteStream) os; /* if (out.getSource() == StdoutStre...
java
public static synchronized void setStderr(OutputStream os) { if (_stderrStream == null) { initStderr(); } if (os == _systemErr || os == _systemOut) { return; } if (os instanceof WriteStream) { WriteStream out = (WriteStream) os; /* if (out.getSource() == StdoutStre...
java
protected static <E extends SubSystemBase> SystemManager preCreate(Class<E> serviceClass) { SystemManager system = SystemManager.getCurrent(); if (system == null) throw new IllegalStateException(L.l("{0} must be created before {1}", SystemManager.class.getSi...
java
public String addConnectionRequirement(NodeTemplate target, String type, String varName) { Map<String, Object> requirement = new LinkedHashMap(); String requirementName = "endpoint"; Map requirementMap = new LinkedHashMap<String, Object>(); requirement.put(requirementName, ...
java
@Override public boolean stop() { if (! _lifecycle.toStopping()) return false; log.finest(this + " stopping"); closeConnections(); destroy(); return true; }
java
int writePageIndex(byte []buffer, int head, int type, int pid, int nextPid, int entryOffset, int entryLength) { int sublen = 1 + 4 * 4; if (BLOCK_SIZE - 8 < head + sublen) { ...
java
public void readEntries(TableKelp table, InSegment reader, SegmentEntryCallback cb) { TempBuffer tBuf = TempBuffer.createLarge(); byte []buffer = tBuf.buffer(); InStore sIn = reader.getStoreRead(); byte []tableKey = new byte[TableKelp.TABLE_KEY...
java
public int getSize() { int size = length(); if (_blobs == null) { return size; } for (BlobOutputStream blob : _blobs) { if (blob != null) { size += blob.getSize(); } } return size; }
java
public final OutputStream openOutputStream(int index) { Column column = _row.columns()[index]; return column.openOutputStream(this); }
java
public static Path currentDataDirectory() { RootDirectorySystem rootService = getCurrent(); if (rootService == null) throw new IllegalStateException(L.l("{0} must be active for getCurrentDataDirectory().", RootDirectorySystem.class.getSimpleName())); ...
java
public static JournalStore create(Path path, boolean isMmap) throws IOException { // RampManager rampManager = Ramp.newManager(); long segmentSize = 4 * 1024 * 1024; JournalStore.Builder builder = JournalStore.Builder.create(path); builder.segmentSize(segmentSize); // builder.ra...
java
public static void clearJarCache() { LruCache<PathImpl,Jar> jarCache = _jarCache; if (jarCache == null) return; ArrayList<Jar> jars = new ArrayList<Jar>(); synchronized (jarCache) { Iterator<Jar> iter = jarCache.values(); while (iter.hasNext()) jars.add(iter...
java
private Path keyStoreFile() { String fileName = _config.get(_prefix + ".ssl.key-store"); if (fileName == null) { return null; } return Vfs.path(fileName); }
java
private String keyStorePassword() { String password = _config.get(_prefix + ".ssl.key-store-password"); if (password != null) { return password; } else { return _config.get(_prefix + ".ssl.password"); } }
java
private SSLSocketFactory createFactory() throws Exception { SSLSocketFactory ssFactory = null; String host = "localhost"; int port = 8086; if (_keyStore == null) { return createAnonymousFactory(null, port); } SSLContext sslContext = SSLContext.getInstance(_sslContext);...
java
public static InjectorImpl current(ClassLoader loader) { if (loader instanceof DynamicClassLoader) { return _localManager.getLevel(loader); } else { SoftReference<InjectorImpl> injectRef = _loaderManagerMap.get(loader); if (injectRef != null) { return injectRef.get(); } ...
java
@Override public <T> T instance(Class<T> type) { Key<T> key = Key.of(type); return instance(key); }
java
@Override public <T> T instance(Key<T> key) { Objects.requireNonNull(key); Class<T> type = (Class) key.rawClass(); if (type.equals(Provider.class)) { TypeRef typeRef = TypeRef.of(key.type()); TypeRef param = typeRef.param(0); return (T) provider(Key.of(param.type())); } Pro...
java
@Override public <T> T instance(InjectionPoint<T> ip) { Objects.requireNonNull(ip); Provider<T> provider = provider(ip); if (provider != null) { return provider.get(); } else { return null; } }
java
@Override public <T> Provider<T> provider(InjectionPoint<T> ip) { Objects.requireNonNull(ip); Provider<T> provider = lookupProvider(ip); if (provider != null) { return provider; } provider = autoProvider(ip); if (provider != null) { return provider; } return new Prov...
java
@Override public <T> Provider<T> provider(Key<T> key) { Objects.requireNonNull(key); Provider<T> provider = (Provider) _providerMap.get(key); if (provider == null) { provider = lookupProvider(key); if (provider == null) { provider = autoProvider(key); } _providerMap.p...
java
private <T> Provider<T> lookupProvider(Key<T> key) { BindingInject<T> bean = findBean(key); if (bean != null) { return bean.provider(); } BindingAmp<T> binding = findBinding(key); if (binding != null) { return binding.provider(); } binding = findObjectBinding(key); if ...
java
private <T> Provider<T> lookupProvider(InjectionPoint<T> ip) { Key<T> key = ip.key(); BindingInject<T> bean = findBean(key); if (bean != null) { return bean.provider(ip); } BindingAmp<T> provider = findBinding(key); if (provider != null) { return provider.provider(ip); } ...
java
private <T> InjectScope<T> findScope(AnnotatedElement annElement) { for (Annotation ann : annElement.getAnnotations()) { Class<? extends Annotation> annType = ann.annotationType(); if (annType.isAnnotationPresent(Scope.class)) { Supplier<InjectScope<T>> scopeGen = (Supplier) _scopeMap.get(ann...
java
@Override public <T> Iterable<Binding<T>> bindings(Class<T> type) { BindingSet<T> set = (BindingSet) _bindingSetMap.get(type); if (set != null) { return (Iterable) set; } else { return Collections.EMPTY_LIST; } }
java
@Override public <T> List<Binding<T>> bindings(Key<T> key) { BindingSet<T> set = (BindingSet) _bindingSetMap.get(key.rawClass()); if (set != null) { return set.bindings(key); } else { return Collections.EMPTY_LIST; } }
java
<T> InjectScope<T> scope(Class<? extends Annotation> scopeType) { Supplier<InjectScope<T>> scopeGen = (Supplier) _scopeMap.get(scopeType); if (scopeGen == null) { throw error("{0} is an unknown scope", scopeType.getSimpleName()); } return scopeGen.get(); }
java
@Override public <T> Consumer<T> injector(Class<T> type) { ArrayList<InjectProgram> injectList = new ArrayList<>(); introspectInject(injectList, type); introspectInit(injectList, type); return new InjectProgramImpl<T>(injectList); }
java
@Override public Provider<?> []program(Parameter []params) { Provider<?> []program = new Provider<?>[params.length]; for (int i = 0; i < program.length; i++) { //Key<?> key = Key.of(params[i]); program[i] = provider(InjectionPoint.of(params[i])); } return program; }
java
private <T> BindingInject<T> findBean(Key<T> key) { for (InjectProvider provider : _providerList) { BindingInject<T> bean = (BindingInject) provider.lookup(key.rawClass()); if (bean != null) { return bean; } } return null; }
java
private <T> BindingAmp<T> findObjectBinding(Key<T> key) { Objects.requireNonNull(key); if (key.qualifiers().length != 1) { throw new IllegalArgumentException(); } return (BindingAmp) findBinding(Key.of(Object.class, key.qualifiers()[0])); }
java
private <T> BindingAmp<T> findBinding(Key<T> key) { BindingSet<T> set = (BindingSet) _bindingSetMap.get(key.rawClass()); if (set != null) { BindingAmp<T> binding = set.find(key); if (binding != null) { return binding; } } return null; }
java
public void setLevel(Level level) { _level = level; if (level.intValue() < _lowLevel.intValue()) _lowLevel = level; }
java
public boolean waitForActive(long timeout) { LifecycleState state = getState(); if (state.isActive()) { return true; } else if (state.isAfterActive()) { return false; } // server/1d2j long waitEnd = CurrentTime.getCurrentTimeActual() + timeout; synchronized (this) { ...
java
public boolean toPostInit() { synchronized (this) { if (_state == STOPPED) { _state = INIT; _lastChangeTime = CurrentTime.currentTime(); notifyListeners(STOPPED, INIT); return true; } else { return _state.isInit(); } } }
java
public boolean toStarting() { LifecycleState state; synchronized (this) { state = _state; if (state.isAfterStarting() && ! state.isStopped()) { return false; } _state = STARTING; _lastChangeTime = CurrentTime.currentTime(); if (_log != null && _log.is...
java
public boolean toActive() { LifecycleState state; synchronized (this) { state = _state; if (state.isAfterActive() && ! state.isStopped()) { return false; } _state = ACTIVE; _lastChangeTime = CurrentTime.currentTime(); } if (_log != null && _log.isLo...
java
public boolean toFail() { LifecycleState state; synchronized (this) { state = _state; if (state.isAfterDestroying()) { return false; } _state = FAILED; _lastChangeTime = CurrentTime.currentTime(); } if (_log != null && _log.isLoggable(_level)) ...
java
public boolean toStopping() { LifecycleState state; synchronized (this) { state = _state; if (state.isAfterStopping() || state.isStarting()) { return false; } _state = STOPPING; _lastChangeTime = CurrentTime.currentTime(); } if (_log != null &...
java
public void addListener(LifecycleListener listener) { synchronized (this) { if (isDestroyed()) { IllegalStateException e = new IllegalStateException("attempted to add listener to a destroyed lifecyle " + this); if (_log != null) _log.log(Level.WARNING, e.toString(), e); el...
java
@Override public String serialize(Object obj) throws JsonMarshallingException { try { return serializeChecked(obj); } catch (Exception e) { throw new JsonMarshallingException(e); } }
java
public void setExecutorTaskMax(int max) { if (getThreadMax() < max) throw new ConfigException(L.l("<thread-executor-max> ({0}) must be less than <thread-max> ({1})", max, getThreadMax())); if (max == 0) throw new ConfigException(L.l("<thread-executor-max> must ...
java
public boolean scheduleExecutorTask(Runnable task) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); synchronized (_executorLock) { _executorTaskCount++; if (_executorTaskCount <= _executorTaskMax || _executorTaskMax < 0) { boolean isPriority = false; boolean...
java
public void completeExecutorTask() { ExecutorQueueItem item = null; synchronized (_executorLock) { _executorTaskCount--; assert(_executorTaskCount >= 0); if (_executorQueueHead != null) { item = _executorQueueHead; _executorQueueHead = item._next; if (_executorQu...
java
public Offering getOffering(String offeringName) { BasicDBObject query = new BasicDBObject("offering_name", offeringName); FindIterable<Document> cursor = this.offeringsCollection.find(query); return Offering.fromDB(cursor.first()); }
java
public String addOffering(Offering offering) { this.offeringsCollection.insertOne(offering.toDBObject()); this.offeringNames.add(offering.getName()); return offering.getName(); }
java
public boolean removeOffering(String offeringName) { if(offeringName == null) throw new NullPointerException("The parameter \"cloudOfferingId\" cannot be null."); BasicDBObject query = new BasicDBObject("offering_name", offeringName); Document removedOffering = this.offeringsCollect...
java
public void initializeOfferings() { FindIterable<Document> offerings = this.offeringsCollection.find(); for (Document d : offerings) { offeringNames.add((String) d.get("offering_name")); } }
java
public void generateSingleOffering(String offeringNodeTemplates) { this.removeOffering("0"); Offering singleOffering = new Offering("all"); singleOffering.toscaString = offeringNodeTemplates; this.addOffering(singleOffering); }
java
public JClass getSuperClass() { lazyLoad(); if (_superClass == null) return null; else return getClassLoader().forName(_superClass.replace('/', '.')); }
java
public void addInterface(String className) { _interfaces.add(className); if (_isWrite) getConstantPool().addClass(className); }
java
public JClass []getInterfaces() { lazyLoad(); JClass []interfaces = new JClass[_interfaces.size()]; for (int i = 0; i < _interfaces.size(); i++) { String name = _interfaces.get(i); name = name.replace('/', '.'); interfaces[i] = getClassLoader().forName(name); } ...
java
public JavaField getField(String name) { ArrayList<JavaField> fieldList = getFieldList(); for (int i = 0; i < fieldList.size(); i++) { JavaField field = fieldList.get(i); if (field.getName().equals(name)) return field; } return null; }
java
public JavaMethod getMethod(String name) { ArrayList<JavaMethod> methodList = getMethodList(); for (int i = 0; i < methodList.size(); i++) { JavaMethod method = methodList.get(i); if (method.getName().equals(name)) return method; } return null; }
java
public JavaMethod findMethod(String name, String descriptor) { ArrayList<JavaMethod> methodList = getMethodList(); for (int i = 0; i < methodList.size(); i++) { JavaMethod method = methodList.get(i); if (method.getName().equals(name) && method.getDescriptor().equals(descriptor)) ...
java
public JField []getDeclaredFields() { ArrayList<JavaField> fieldList = getFieldList(); JField[] fields = new JField[fieldList.size()]; fieldList.toArray(fields); return fields; }
java
public JField []getFields() { ArrayList<JField> fieldList = new ArrayList<JField>(); getFields(fieldList); JField []fields = new JField[fieldList.size()]; fieldList.toArray(fields); return fields; }
java
private void getFields(ArrayList<JField> fieldList) { for (JField field : getDeclaredFields()) { if (! fieldList.contains(field)) fieldList.add(field); } if (getSuperClass() != null) { for (JField field : getSuperClass().getFields()) { if (! fieldList.contains(field)) ...
java
private void lazyLoad() { if (_major > 0) return; try { if (_url == null) throw new IllegalStateException(); try (InputStream is = _url.openStream()) { //ReadStream rs = VfsOld.openRead(is); _major = 1; ByteCodeParser parser = new ByteCodeParser(); ...
java
public void write(OutputStream os) throws IOException { ByteCodeWriter out = new ByteCodeWriter(os, this); out.writeInt(MAGIC); out.writeShort(_minor); out.writeShort(_major); _constantPool.write(out); out.writeShort(_accessFlags); out.writeClass(_thisClass); out.writeClass(_sup...
java
public final I getInvocation(Object protocolKey) { I invocation = null; // XXX: see if can remove this LruCache<Object,I> invocationCache = _invocationCache; if (invocationCache != null) { invocation = invocationCache.get(protocolKey); } if (invocation == null) { return null; ...
java
public I buildInvocation(Object protocolKey, I invocation) throws ConfigException { Objects.requireNonNull(invocation); invocation = buildInvocation(invocation); // XXX: see if can remove this, and rely on the invocation cache existing LruCache<Object,I> invocationCache = _invocationCache; ...
java
public void clearCache() { // XXX: see if can remove this, and rely on the invocation cache existing LruCache<Object,I> invocationCache = _invocationCache; if (invocationCache != null) { invocationCache.clear(); } }
java
public ArrayList<I> getInvocations() { LruCache<Object,I> invocationCache = _invocationCache; ArrayList<I> invocationList = new ArrayList<>(); synchronized (invocationCache) { Iterator<I> iter; iter = invocationCache.values(); while (iter.hasNext()) { invocationList.add(...
java
private void loadManifest() { if (_isManifestRead) return; synchronized (this) { if (_isManifestRead) return; try { _manifest = _jarPath.getManifest(); if (_manifest == null) return; Attributes attr = _manifest.getMainAttributes(); if ...
java
private void addManifestPackage(String name, Attributes attr) { // only add packages if (! name.endsWith("/") && ! name.equals("")) return; String specTitle = attr.getValue("Specification-Title"); String specVersion = attr.getValue("Specification-Version"); String specVendor = attr.getValue...
java
public void validate() throws ConfigException { loadManifest(); if (_manifest != null) validateManifest(_jarPath.getContainer().getURL(), _manifest); }
java
public static void validateManifest(String manifestName, Manifest manifest) throws ConfigException { Attributes attr = manifest.getMainAttributes(); if (attr == null) return; String extList = attr.getValue("Extension-List"); if (extList == null) return; Pattern pattern = Pattern....
java
public CodeSource getCodeSource(String path) { try { PathImpl jarPath = _jarPath.lookup(path); Certificate []certificates = jarPath.getCertificates(); URL url = new URL(_jarPath.getContainer().getURL()); return new CodeSource(url, certificates); } catch (Exception e) { ...
java
public GuaranteeTermEvaluationResult evaluate( IAgreement agreement, IGuaranteeTerm term, List<IMonitoringMetric> metrics, Date now) { /* * throws NullPointerException if not property initialized */ checkInitialized(); logger.debug("evaluate(a...
java
@Override public int read(byte []buf, int offset, int len) throws IOException { int available = _available; // The chunk still has more data left if (available > 0) { len = Math.min(len, available); len = _next.read(buf, offset, len); if (len > 0) { _available -= len; ...
java
private int readChunkLength() throws IOException { int length = 0; int ch; ReadStream is = _next; // skip whitespace for (ch = is.read(); ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; ch = is.read()) { } // XXX: This doesn't properly handle the case when whe...
java
private String getSlaUrl(String envSlaUrl, UriInfo uriInfo) { String baseUrl = uriInfo.getBaseUri().toString(); if (envSlaUrl == null) { envSlaUrl = ""; } String result = ("".equals(envSlaUrl))? baseUrl : envSlaUrl; logger.debug("getSlaUrl(env={}, supp...
java
private String getMetricsBaseUrl(String suppliedBaseUrl, String envBaseUrl) { String result = ("".equals(suppliedBaseUrl))? envBaseUrl : suppliedBaseUrl; logger.debug("getMetricsBaseUrl(env={}, supplied={}) = {}", envBaseUrl, suppliedBaseUrl, result); return result; }
java
public int read(byte []buffer, int offset, int length) throws IOException { return _stream.read(buffer, offset, length); }
java
@Override public PathImpl getParent() { if (_pathname.length() <= 1) return lookup("/"); int length = _pathname.length(); int lastSlash = _pathname.lastIndexOf('/'); if (lastSlash < 1) return lookup("/"); if (lastSlash == length - 1) { lastSlash = _pathname.lastIndexOf('/', ...
java
static protected String normalizePath(String oldPath, String newPath, int offset, char separatorChar) { CharBuffer cb = new CharBuffer(); normalizePath(cb, oldPath, newPath, offset, separato...
java
static protected void normalizePath(CharBuffer cb, String oldPath, String newPath, int offset, char separatorChar) { cb.clear(); cb.append(oldPath); if (cb.length() == 0 || cb.lastChar() != '/') cb.append('/'); int leng...
java
public String getFullPath() { if (_root == this || _root == null) return getPath(); String rootPath = _root.getFullPath(); String path = getPath(); if (rootPath.length() <= 1) return path; else if (path.length() <= 1) return rootPath; else return rootPath + path; }
java
public Class<?> getClass(int index) { Object value = _values[index - 1]; if (value == null) { return null; } else { return value.getClass(); } }
java
public String getString(int index) { Object value = _values[index - 1]; if (value != null) { return value.toString(); } else { return null; } }
java
public long getLong(int index) { Object value = _values[index - 1]; if (value instanceof Long) { return (Long) value; } else if (value instanceof Integer) { return (Integer) value; } else { return Long.valueOf(value.toString()); } }
java
public double getDouble(int index) { Object value = _values[index - 1]; if (value instanceof Double) { return (Double) value; } else if (value instanceof Float) { return (Float) value; } else if (value instanceof Number) { return (Double) ((Number) value); } else { ...
java
public boolean getBoolean(int index) { Object value = _values[index - 1]; if (value instanceof Boolean) { return (Boolean) value; } else { return Boolean.valueOf(value.toString()); } }
java
@InService(SegmentServiceImpl.class) public Page writeCheckpoint(TableKelp table, OutSegment sOut, long oldSequence, int saveLength, int tail, int saveSequence) throws IOException { return n...
java