id
stringlengths
7
14
text
stringlengths
1
106k
160996_65
public void alloc( int k ) { if (k == 0) throw new IllegalArgumentException( "k == 0" ); int newAlloc = alloc + k; if (newAlloc > limit) throw new IllegalStateException( "newAlloc > limit" ); if (newAlloc < 0) throw new IllegalStateException( "newAlloc < 0" ); alloc = newAlloc; }
160996_66
public void alloc( int k ) { if (k == 0) throw new IllegalArgumentException( "k == 0" ); int newAlloc = alloc + k; if (newAlloc > limit) throw new IllegalStateException( "newAlloc > limit" ); if (newAlloc < 0) throw new IllegalStateException( "newAlloc < 0" ); alloc = newAlloc; }
160996_67
public void alloc( int k ) { if (k == 0) throw new IllegalArgumentException( "k == 0" ); int newAlloc = alloc + k; if (newAlloc > limit) throw new IllegalStateException( "newAlloc > limit" ); if (newAlloc < 0) throw new IllegalStateException( "newAlloc < 0" ); alloc = newAlloc; }
160996_68
public SessionData getSession() { return session; }
160996_69
void stop() throws IOException { started = false; MyAcceptHandler h = setHandler( null ); if (h != null) { h.cancel(); } }
160996_70
public int size() { return size; }
160996_71
public int size() { return size; }
160996_72
public int size() { return size; }
160996_73
public T get() throws InterruptedException { return get( 0 ); }
160996_74
public boolean put( T obj ) throws InterruptedException { return put( obj, 0 ); }
160996_75
final private void checkBuf( byte[] buf, int off, int len ) { if (buf == null) throw new NullPointerException( "buf == null" ); if (off < 0 || off > buf.length) throw new IllegalArgumentException( "off < 0 || off > buf.length" ); if (len < 0) throw new IllegalArgumentException( "len < 0" ); if (off+len > buf.length) throw new IllegalArgumentException( "off+len > buf.length" ); }
160996_76
final private void checkBuf( byte[] buf, int off, int len ) { if (buf == null) throw new NullPointerException( "buf == null" ); if (off < 0 || off > buf.length) throw new IllegalArgumentException( "off < 0 || off > buf.length" ); if (len < 0) throw new IllegalArgumentException( "len < 0" ); if (off+len > buf.length) throw new IllegalArgumentException( "off+len > buf.length" ); }
160996_77
final private void checkBuf( byte[] buf, int off, int len ) { if (buf == null) throw new NullPointerException( "buf == null" ); if (off < 0 || off > buf.length) throw new IllegalArgumentException( "off < 0 || off > buf.length" ); if (len < 0) throw new IllegalArgumentException( "len < 0" ); if (off+len > buf.length) throw new IllegalArgumentException( "off+len > buf.length" ); }
160996_78
final private void checkBuf( byte[] buf, int off, int len ) { if (buf == null) throw new NullPointerException( "buf == null" ); if (off < 0 || off > buf.length) throw new IllegalArgumentException( "off < 0 || off > buf.length" ); if (len < 0) throw new IllegalArgumentException( "len < 0" ); if (off+len > buf.length) throw new IllegalArgumentException( "off+len > buf.length" ); }
160996_79
final public FlexBuffer setLength( int length ) throws IllegalArgumentException, IOException { if (length < 0) throw new IllegalArgumentException( "length < 0" ); ensureLength( length ); this.length = length; if (index > length) index = length; return this; }
160996_80
final public FlexBuffer setIndex( int index ) throws IllegalArgumentException { if (index < 0 || index > length) throw new IllegalArgumentException( "index < 0 || index > length" ); this.index = index; return this; }
160996_81
final public FlexBuffer setIndex( int index ) throws IllegalArgumentException { if (index < 0 || index > length) throw new IllegalArgumentException( "index < 0 || index > length" ); this.index = index; return this; }
160996_82
final public FlexBuffer reset() { index = 0; length = 0; if (buffer.length > TRIM_BUFFER_LEN) buffer = new byte[TRIM_BUFFER_LEN]; return this; }
160996_83
final public int get() throws IOException { checkAvail( 1 ); return buffer[index++] & 255; }
160996_84
final public FlexBuffer compact() { if (index == 0) return this; int n = avail(); if (n == 0) { reset(); return this; } System.arraycopy( buffer, index, buffer, 0, n ); index = 0; length = n; return this; }
160996_85
final public byte getByte() throws IOException { checkAvail( 1 ); return buffer[index++]; }
160996_86
final public short getShort() throws IOException { eckAvail( 2 ); (littleEndian) / little-endian nt value = buffer[index++] & 255; eturn (short) (value + ((buffer[index++] & 255) << 8)); big-endian t value = buffer[index++]; turn (short) ((value << 8) + (buffer[index++] & 255)); }
160996_87
final public int getInt() throws IOException { checkAvail( 4 ); if (littleEndian) { // little-endian int value = buffer[index++] & 255; value += (buffer[index++] & 255) << 8; value += (buffer[index++] & 255) << 16; return value + ((buffer[index++] & 255) << 24); } // big-endian int value = buffer[index++]; value = (value << 8) + (buffer[index++] & 255); value = (value << 8) + (buffer[index++] & 255); return (value << 8) + (buffer[index++] & 255); }
160996_88
final public long getLong() throws IOException { eckAvail( 8 ); (littleEndian) / little-endian ong value = buffer[index++] & 255; alue += (long)(buffer[index++] & 255) << 8; alue += (long)(buffer[index++] & 255) << 16; alue += (long)(buffer[index++] & 255) << 24; alue += (long)(buffer[index++] & 255) << 32; alue += (long)(buffer[index++] & 255) << 40; alue += (long)(buffer[index++] & 255) << 48; eturn value + ((long)(buffer[index++] & 255) << 56); big-endian ng value = buffer[index++]; lue = (value << 8) + (buffer[index++] & 255); lue = (value << 8) + (buffer[index++] & 255); lue = (value << 8) + (buffer[index++] & 255); lue = (value << 8) + (buffer[index++] & 255); lue = (value << 8) + (buffer[index++] & 255); lue = (value << 8) + (buffer[index++] & 255); turn (value << 8) + (buffer[index++] & 255); }
160996_89
final public float getFloat() throws IOException { turn Float.intBitsToFloat( getInt() ); }
160996_90
final public double getDouble() throws IOException { turn Double.longBitsToDouble( getLong() ); }
160996_91
final public void getFully( byte[] b ) throws IOException { checkAvail( b.length ); int n = get( b, 0, b.length ); assert n == b.length; }
160996_92
final public FlexBuffer skip( int len, boolean put ) throws IOException { if (len < 0) throw new IllegalArgumentException( "len < 0" ); if (len == 0) return this; if (put) { ensureLength( index+len ); index += len; fixLength(); return this; } checkAvail( len ); index += len; return this; }
160996_93
final public FlexBuffer skip( int len, boolean put ) throws IOException { if (len < 0) throw new IllegalArgumentException( "len < 0" ); if (len == 0) return this; if (put) { ensureLength( index+len ); index += len; fixLength(); return this; } checkAvail( len ); index += len; return this; }
160996_94
final public FlexBuffer skip( int len, boolean put ) throws IOException { if (len < 0) throw new IllegalArgumentException( "len < 0" ); if (len == 0) return this; if (put) { ensureLength( index+len ); index += len; fixLength(); return this; } checkAvail( len ); index += len; return this; }
160996_95
public void transportMessage( Who recipient, Message msg ) throws Exception { if (msg.getMessageId() != null) throw new IllegalStateException( "message has already been sent" ); msg.setMessageId( idGen.next() ); //Log.report( "MailboxManager.send", "msg", msg ); transport.transportMessage( recipient, msg ); }
160996_96
public boolean sessionMessage( Who sender, Message msg ) throws Exception { //Log.report( "MailboxManager.recv", "msg", msg ); Long msgid = msg.getInReplyTo(); if (msgid != null) { Mailbox mb = getMailbox( msgid ); //Log.report( "MailboxManager.recv", "msg", msg, "mb", mb ); if (mb != null) { try { return mb.message( sender, msg ); } catch ( InterruptedException e ) { // timeout or mailbox closed - fall through } } // no such mailbox - reject return false; } // no msgid - pass off to session return session.sessionMessage( sender, msg ); }
160996_97
public boolean sessionMessage( Who sender, Message msg ) throws Exception { //Log.report( "MailboxManager.recv", "msg", msg ); Long msgid = msg.getInReplyTo(); if (msgid != null) { Mailbox mb = getMailbox( msgid ); //Log.report( "MailboxManager.recv", "msg", msg, "mb", mb ); if (mb != null) { try { return mb.message( sender, msg ); } catch ( InterruptedException e ) { // timeout or mailbox closed - fall through } } // no such mailbox - reject return false; } // no msgid - pass off to session return session.sessionMessage( sender, msg ); }
160996_98
public boolean sessionMessage( Who sender, Message msg ) throws Exception { //Log.report( "MailboxManager.recv", "msg", msg ); Long msgid = msg.getInReplyTo(); if (msgid != null) { Mailbox mb = getMailbox( msgid ); //Log.report( "MailboxManager.recv", "msg", msg, "mb", mb ); if (mb != null) { try { return mb.message( sender, msg ); } catch ( InterruptedException e ) { // timeout or mailbox closed - fall through } } // no such mailbox - reject return false; } // no msgid - pass off to session return session.sessionMessage( sender, msg ); }
160996_99
public boolean sessionMessage( Who sender, Message msg ) throws Exception { //Log.report( "MailboxManager.recv", "msg", msg ); Long msgid = msg.getInReplyTo(); if (msgid != null) { Mailbox mb = getMailbox( msgid ); //Log.report( "MailboxManager.recv", "msg", msg, "mb", mb ); if (mb != null) { try { return mb.message( sender, msg ); } catch ( InterruptedException e ) { // timeout or mailbox closed - fall through } } // no such mailbox - reject return false; } // no msgid - pass off to session return session.sessionMessage( sender, msg ); }
160999_10
public static String formatInetAddr(InetSocketAddress addr) { InetAddress ia = addr.getAddress(); if (ia == null) { return String.format("%s:%s", addr.getHostString(), addr.getPort()); } if (ia instanceof Inet6Address) { return String.format("[%s]:%s", ia.getHostAddress(), addr.getPort()); } else { return String.format("%s:%s", ia.getHostAddress(), addr.getPort()); } }
160999_11
public static String formatInetAddr(InetSocketAddress addr) { InetAddress ia = addr.getAddress(); if (ia == null) { return String.format("%s:%s", addr.getHostString(), addr.getPort()); } if (ia instanceof Inet6Address) { return String.format("[%s]:%s", ia.getHostAddress(), addr.getPort()); } else { return String.format("%s:%s", ia.getHostAddress(), addr.getPort()); } }
160999_12
public static String formatInetAddr(InetSocketAddress addr) { InetAddress ia = addr.getAddress(); if (ia == null) { return String.format("%s:%s", addr.getHostString(), addr.getPort()); } if (ia instanceof Inet6Address) { return String.format("[%s]:%s", ia.getHostAddress(), addr.getPort()); } else { return String.format("%s:%s", ia.getHostAddress(), addr.getPort()); } }
160999_13
public static String[] getIPV6HostAndPort(String hostPort) { if (hostPort.startsWith("[")) { int i = hostPort.lastIndexOf(']'); if (i < 0) { throw new IllegalArgumentException( hostPort + " starts with '[' but has no matching ']'"); } String host = hostPort.substring(1, i); if (host.isEmpty()) { throw new IllegalArgumentException(host + " is empty."); } if (hostPort.length() > i + 1) { return getHostPort(hostPort, i, host); } return new String[] { host }; } else { //Not an IPV6 host port string return new String[] {}; } }
160999_14
public static String[] getIPV6HostAndPort(String hostPort) { if (hostPort.startsWith("[")) { int i = hostPort.lastIndexOf(']'); if (i < 0) { throw new IllegalArgumentException( hostPort + " starts with '[' but has no matching ']'"); } String host = hostPort.substring(1, i); if (host.isEmpty()) { throw new IllegalArgumentException(host + " is empty."); } if (hostPort.length() > i + 1) { return getHostPort(hostPort, i, host); } return new String[] { host }; } else { //Not an IPV6 host port string return new String[] {}; } }
160999_15
public static String[] getIPV6HostAndPort(String hostPort) { if (hostPort.startsWith("[")) { int i = hostPort.lastIndexOf(']'); if (i < 0) { throw new IllegalArgumentException( hostPort + " starts with '[' but has no matching ']'"); } String host = hostPort.substring(1, i); if (host.isEmpty()) { throw new IllegalArgumentException(host + " is empty."); } if (hostPort.length() > i + 1) { return getHostPort(hostPort, i, host); } return new String[] { host }; } else { //Not an IPV6 host port string return new String[] {}; } }
160999_16
public static String[] getIPV6HostAndPort(String hostPort) { if (hostPort.startsWith("[")) { int i = hostPort.lastIndexOf(']'); if (i < 0) { throw new IllegalArgumentException( hostPort + " starts with '[' but has no matching ']'"); } String host = hostPort.substring(1, i); if (host.isEmpty()) { throw new IllegalArgumentException(host + " is empty."); } if (hostPort.length() > i + 1) { return getHostPort(hostPort, i, host); } return new String[] { host }; } else { //Not an IPV6 host port string return new String[] {}; } }
160999_17
public static String[] getIPV6HostAndPort(String hostPort) { if (hostPort.startsWith("[")) { int i = hostPort.lastIndexOf(']'); if (i < 0) { throw new IllegalArgumentException( hostPort + " starts with '[' but has no matching ']'"); } String host = hostPort.substring(1, i); if (host.isEmpty()) { throw new IllegalArgumentException(host + " is empty."); } if (hostPort.length() > i + 1) { return getHostPort(hostPort, i, host); } return new String[] { host }; } else { //Not an IPV6 host port string return new String[] {}; } }
160999_18
public static String[] getIPV6HostAndPort(String hostPort) { if (hostPort.startsWith("[")) { int i = hostPort.lastIndexOf(']'); if (i < 0) { throw new IllegalArgumentException( hostPort + " starts with '[' but has no matching ']'"); } String host = hostPort.substring(1, i); if (host.isEmpty()) { throw new IllegalArgumentException(host + " is empty."); } if (hostPort.length() > i + 1) { return getHostPort(hostPort, i, host); } return new String[] { host }; } else { //Not an IPV6 host port string return new String[] {}; } }
160999_19
public static String[] getIPV6HostAndPort(String hostPort) { if (hostPort.startsWith("[")) { int i = hostPort.lastIndexOf(']'); if (i < 0) { throw new IllegalArgumentException( hostPort + " starts with '[' but has no matching ']'"); } String host = hostPort.substring(1, i); if (host.isEmpty()) { throw new IllegalArgumentException(host + " is empty."); } if (hostPort.length() > i + 1) { return getHostPort(hostPort, i, host); } return new String[] { host }; } else { //Not an IPV6 host port string return new String[] {}; } }
160999_20
@Override public boolean verify(final String host, final SSLSession session) { try { final Certificate[] certs = session.getPeerCertificates(); final X509Certificate x509 = (X509Certificate) certs[0]; verify(host, x509); return true; } catch (final SSLException ex) { log.debug("Unexpected exception", ex); return false; } }
160999_21
@Override public void checkServerTrusted( X509Certificate[] chain, String authType, Socket socket) throws CertificateException { x509ExtendedTrustManager.checkServerTrusted(chain, authType, socket); if (serverHostnameVerificationEnabled) { performHostVerification(socket.getInetAddress(), chain[0]); } }
160999_22
@Override public void checkServerTrusted( X509Certificate[] chain, String authType, Socket socket) throws CertificateException { x509ExtendedTrustManager.checkServerTrusted(chain, authType, socket); if (serverHostnameVerificationEnabled) { performHostVerification(socket.getInetAddress(), chain[0]); } }
160999_23
@Override public void checkServerTrusted( X509Certificate[] chain, String authType, Socket socket) throws CertificateException { x509ExtendedTrustManager.checkServerTrusted(chain, authType, socket); if (serverHostnameVerificationEnabled) { performHostVerification(socket.getInetAddress(), chain[0]); } }
160999_24
@Override public void checkServerTrusted( X509Certificate[] chain, String authType, Socket socket) throws CertificateException { x509ExtendedTrustManager.checkServerTrusted(chain, authType, socket); if (serverHostnameVerificationEnabled) { performHostVerification(socket.getInetAddress(), chain[0]); } }
160999_25
@Override public void checkClientTrusted( X509Certificate[] chain, String authType, Socket socket) throws CertificateException { x509ExtendedTrustManager.checkClientTrusted(chain, authType, socket); if (clientHostnameVerificationEnabled) { performHostVerification(socket.getInetAddress(), chain[0]); } }
160999_26
@Override public void checkClientTrusted( X509Certificate[] chain, String authType, Socket socket) throws CertificateException { x509ExtendedTrustManager.checkClientTrusted(chain, authType, socket); if (clientHostnameVerificationEnabled) { performHostVerification(socket.getInetAddress(), chain[0]); } }
160999_27
@Override public void checkClientTrusted( X509Certificate[] chain, String authType, Socket socket) throws CertificateException { x509ExtendedTrustManager.checkClientTrusted(chain, authType, socket); if (clientHostnameVerificationEnabled) { performHostVerification(socket.getInetAddress(), chain[0]); } }
160999_28
@Override public void checkClientTrusted( X509Certificate[] chain, String authType, Socket socket) throws CertificateException { x509ExtendedTrustManager.checkClientTrusted(chain, authType, socket); if (clientHostnameVerificationEnabled) { performHostVerification(socket.getInetAddress(), chain[0]); } }
160999_29
public void addPath(final String path) { Objects.requireNonNull(path, "Path cannot be null"); if (path.length() == 0) { throw new IllegalArgumentException("Invalid path: " + path); } final String[] pathComponents = split(path); writeLock.lock(); try { TrieNode parent = rootNode; for (final String part : pathComponents) { TrieNode child = parent.getChild(part); if (child == null) { child = new TrieNode(parent, part); parent.addChild(part, child); } parent = child; } parent.setProperty(true); } finally { writeLock.unlock(); } }
160999_30
public void addPath(final String path) { Objects.requireNonNull(path, "Path cannot be null"); if (path.length() == 0) { throw new IllegalArgumentException("Invalid path: " + path); } final String[] pathComponents = split(path); writeLock.lock(); try { TrieNode parent = rootNode; for (final String part : pathComponents) { TrieNode child = parent.getChild(part); if (child == null) { child = new TrieNode(parent, part); parent.addChild(part, child); } parent = child; } parent.setProperty(true); } finally { writeLock.unlock(); } }
160999_31
public void deletePath(final String path) { Objects.requireNonNull(path, "Path cannot be null"); if (path.length() == 0) { throw new IllegalArgumentException("Invalid path: " + path); } final String[] pathComponents = split(path); writeLock.lock(); try { TrieNode parent = rootNode; for (final String part : pathComponents) { if (parent.getChild(part) == null) { // the path does not exist return; } parent = parent.getChild(part); LOG.debug("{}", parent); } final TrieNode realParent = parent.getParent(); realParent.deleteChild(parent.getValue()); } finally { writeLock.unlock(); } }
160999_32
public void deletePath(final String path) { Objects.requireNonNull(path, "Path cannot be null"); if (path.length() == 0) { throw new IllegalArgumentException("Invalid path: " + path); } final String[] pathComponents = split(path); writeLock.lock(); try { TrieNode parent = rootNode; for (final String part : pathComponents) { if (parent.getChild(part) == null) { // the path does not exist return; } parent = parent.getChild(part); LOG.debug("{}", parent); } final TrieNode realParent = parent.getParent(); realParent.deleteChild(parent.getValue()); } finally { writeLock.unlock(); } }
160999_33
public String findMaxPrefix(final String path) { Objects.requireNonNull(path, "Path cannot be null"); final String[] pathComponents = split(path); readLock.lock(); try { TrieNode parent = rootNode; TrieNode deepestPropertyNode = null; for (final String element : pathComponents) { parent = parent.getChild(element); if (parent == null) { LOG.debug("{}", element); break; } if (parent.hasProperty()) { deepestPropertyNode = parent; } } if (deepestPropertyNode == null) { return "/"; } final Deque<String> treePath = new ArrayDeque<>(); TrieNode node = deepestPropertyNode; while (node != this.rootNode) { treePath.offerFirst(node.getValue()); node = node.parent; } return "/" + String.join("/", treePath); } finally { readLock.unlock(); } }
160999_34
public String findMaxPrefix(final String path) { Objects.requireNonNull(path, "Path cannot be null"); final String[] pathComponents = split(path); readLock.lock(); try { TrieNode parent = rootNode; TrieNode deepestPropertyNode = null; for (final String element : pathComponents) { parent = parent.getChild(element); if (parent == null) { LOG.debug("{}", element); break; } if (parent.hasProperty()) { deepestPropertyNode = parent; } } if (deepestPropertyNode == null) { return "/"; } final Deque<String> treePath = new ArrayDeque<>(); TrieNode node = deepestPropertyNode; while (node != this.rootNode) { treePath.offerFirst(node.getValue()); node = node.parent; } return "/" + String.join("/", treePath); } finally { readLock.unlock(); } }
160999_35
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_36
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_37
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_38
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_39
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_40
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_41
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_42
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_43
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_44
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_45
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_46
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_47
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_48
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_49
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_50
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_51
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_52
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_53
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_54
public static void validatePath(String path, boolean isSequential) throws IllegalArgumentException { validatePath(isSequential ? path + "1" : path); }
160999_55
static FileKeyStoreLoader.Builder<? extends FileKeyStoreLoader> getBuilderForKeyStoreFileType(KeyStoreFileType type) { switch (Objects.requireNonNull(type)) { case JKS: return new JKSFileLoader.Builder(); case PEM: return new PEMFileLoader.Builder(); case PKCS12: return new PKCS12FileLoader.Builder(); case BCFKS: return new BCFKSFileLoader.Builder(); default: throw new AssertionError("Unexpected StoreFileType: " + type.name()); } }
160999_56
static FileKeyStoreLoader.Builder<? extends FileKeyStoreLoader> getBuilderForKeyStoreFileType(KeyStoreFileType type) { switch (Objects.requireNonNull(type)) { case JKS: return new JKSFileLoader.Builder(); case PEM: return new PEMFileLoader.Builder(); case PKCS12: return new PKCS12FileLoader.Builder(); case BCFKS: return new BCFKSFileLoader.Builder(); default: throw new AssertionError("Unexpected StoreFileType: " + type.name()); } }
160999_57
static FileKeyStoreLoader.Builder<? extends FileKeyStoreLoader> getBuilderForKeyStoreFileType(KeyStoreFileType type) { switch (Objects.requireNonNull(type)) { case JKS: return new JKSFileLoader.Builder(); case PEM: return new PEMFileLoader.Builder(); case PKCS12: return new PKCS12FileLoader.Builder(); case BCFKS: return new BCFKSFileLoader.Builder(); default: throw new AssertionError("Unexpected StoreFileType: " + type.name()); } }
160999_58
static FileKeyStoreLoader.Builder<? extends FileKeyStoreLoader> getBuilderForKeyStoreFileType(KeyStoreFileType type) { switch (Objects.requireNonNull(type)) { case JKS: return new JKSFileLoader.Builder(); case PEM: return new PEMFileLoader.Builder(); case PKCS12: return new PKCS12FileLoader.Builder(); case BCFKS: return new BCFKSFileLoader.Builder(); default: throw new AssertionError("Unexpected StoreFileType: " + type.name()); } }
160999_59
public boolean getBoolean(String key) { return getBoolean(key, false); }
160999_60
@Override public int hashCode() { int hash = results.size(); for (OpResult result : results) { hash = (hash * 35) + result.hashCode(); } return hash; }
160999_61
public void delete(final String path, int version) throws InterruptedException, KeeperException { final String clientPath = path; PathUtils.validatePath(clientPath); final String serverPath; // maintain semantics even in chroot case // specifically - root cannot be deleted // I think this makes sense even in chroot case. if (clientPath.equals("/")) { // a bit of a hack, but delete(/) will never succeed and ensures // that the same semantics are maintained serverPath = clientPath; } else { serverPath = prependChroot(clientPath); } RequestHeader h = new RequestHeader(); h.setType(ZooDefs.OpCode.delete); DeleteRequest request = new DeleteRequest(); request.setPath(serverPath); request.setVersion(version); ReplyHeader r = cnxn.submitRequest(h, request, null, null); if (r.getErr() != 0) { throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath); } }
160999_62
public Stat setData(final String path, byte[] data, int version) throws KeeperException, InterruptedException { final String clientPath = path; PathUtils.validatePath(clientPath); final String serverPath = prependChroot(clientPath); RequestHeader h = new RequestHeader(); h.setType(ZooDefs.OpCode.setData); SetDataRequest request = new SetDataRequest(); request.setPath(serverPath); request.setData(data); request.setVersion(version); SetDataResponse response = new SetDataResponse(); ReplyHeader r = cnxn.submitRequest(h, request, response, null); if (r.getErr() != 0) { throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath); } return response.getStat(); }
160999_63
@Override public String toString() { States state = getState(); return ("State:" + state.toString() + (state.isConnected() ? " Timeout:" + getSessionTimeout() + " " : " ") + cnxn); }
160999_64
public String create( final String path, byte[] data, List<ACL> acl, CreateMode createMode) throws KeeperException, InterruptedException { final String clientPath = path; PathUtils.validatePath(clientPath, createMode.isSequential()); EphemeralType.validateTTL(createMode, -1); validateACL(acl); final String serverPath = prependChroot(clientPath); RequestHeader h = new RequestHeader(); h.setType(createMode.isContainer() ? ZooDefs.OpCode.createContainer : ZooDefs.OpCode.create); CreateRequest request = new CreateRequest(); CreateResponse response = new CreateResponse(); request.setData(data); request.setFlags(createMode.toFlag()); request.setPath(serverPath); request.setAcl(acl); ReplyHeader r = cnxn.submitRequest(h, request, response, null); if (r.getErr() != 0) { throw KeeperException.create(KeeperException.Code.get(r.getErr()), clientPath); } if (cnxn.chrootPath == null) { return response.getPath(); } else { return response.getPath().substring(cnxn.chrootPath.length()); } }
160999_65
@Override public int hashCode() { int h = 1023; for (Op op : ops) { h = h * 25 + op.hashCode(); } return h; }
160999_66
public synchronized Long convertAcls(List<ACL> acls) { if (acls == null) { return OPEN_UNSAFE_ACL_ID; } // get the value from the map Long ret = aclKeyMap.get(acls); if (ret == null) { ret = incrementIndex(); longKeyMap.put(ret, acls); aclKeyMap.put(acls, ret); } addUsage(ret); return ret; }
160999_67
public synchronized Long convertAcls(List<ACL> acls) { if (acls == null) { return OPEN_UNSAFE_ACL_ID; } // get the value from the map Long ret = aclKeyMap.get(acls); if (ret == null) { ret = incrementIndex(); longKeyMap.put(ret, acls); aclKeyMap.put(acls, ret); } addUsage(ret); return ret; }
160999_68
public synchronized void addUsage(Long acl) { if (acl == OPEN_UNSAFE_ACL_ID) { return; } if (!longKeyMap.containsKey(acl)) { LOG.info("Ignoring acl {} as it does not exist in the cache", acl); return; } AtomicLong count = referenceCounter.get(acl); if (count == null) { referenceCounter.put(acl, new AtomicLongWithEquals(1)); } else { count.incrementAndGet(); } }
160999_69
public synchronized void purgeUnused() { Iterator<Map.Entry<Long, AtomicLongWithEquals>> refCountIter = referenceCounter.entrySet().iterator(); while (refCountIter.hasNext()) { Map.Entry<Long, AtomicLongWithEquals> entry = refCountIter.next(); if (entry.getValue().get() <= 0) { Long acl = entry.getKey(); aclKeyMap.remove(longKeyMap.get(acl)); longKeyMap.remove(acl); refCountIter.remove(); } } }
160999_70
@Override public void start() { stopped = false; if (workerPool == null) { workerPool = new WorkerService("NIOWorker", numWorkerThreads, false); } for (SelectorThread thread : selectorThreads) { if (thread.getState() == Thread.State.NEW) { thread.start(); } } // ensure thread is started once and only once if (acceptThread.getState() == Thread.State.NEW) { acceptThread.start(); } if (expirerThread.getState() == Thread.State.NEW) { expirerThread.start(); } }
160999_71
public void shutdown() { try { // close listen socket and signal selector threads to stop stop(); // wait for selector and worker threads to shutdown join(); // close all open connections closeAll(ServerCnxn.DisconnectReason.SERVER_SHUTDOWN); if (login != null) { login.shutdown(); } } catch (InterruptedException e) { LOG.warn("Ignoring interrupted exception during shutdown", e); } catch (Exception e) { LOG.warn("Ignoring unexpected exception during shutdown", e); } if (zkServer != null) { zkServer.shutdown(); } }
160999_72
@Override public void sendCloseSession() { sendBuffer(ServerCnxnFactory.closeConn); }
160999_73
@Override protected ServerStats serverStats() { if (zkServer == null) { return null; } return zkServer.serverStats(); }
160999_74
static String trimPathDepth(String path, int maxDepth) { int count = 0; StringBuilder sb = new StringBuilder(); StringTokenizer pathTokenizer = new StringTokenizer(path, PATH_SEPERATOR); while (pathTokenizer.hasMoreElements() && count++ < maxDepth) { sb.append(PATH_SEPERATOR); sb.append(pathTokenizer.nextToken()); } path = sb.toString(); return path; }