idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
33,200 | public void terminate ( ) { slotSync . lock ( ) ; try { for ( Entry < PendingConnection , String > pending : pendingConnections . entries ( ) ) { SocketBase s = createSocket ( ZMQ . ZMQ_PAIR ) ; assert ( s != null ) ; s . bind ( pending . getValue ( ) ) ; s . close ( ) ; } if ( ! starting . get ( ) ) { boolean restarted = terminating ; terminating = true ; if ( ! restarted ) { for ( SocketBase socket : sockets ) { socket . stop ( ) ; } if ( sockets . isEmpty ( ) ) { reaper . stop ( ) ; } } } } finally { slotSync . unlock ( ) ; } if ( ! starting . get ( ) ) { Command cmd = termMailbox . recv ( WAIT_FOREVER ) ; if ( cmd == null ) { throw new IllegalStateException ( ZError . toString ( errno . get ( ) ) ) ; } assert ( cmd . type == Command . Type . DONE ) : cmd ; slotSync . lock ( ) ; try { assert ( sockets . isEmpty ( ) ) ; } finally { slotSync . unlock ( ) ; } } try { destroy ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } | after the last one is closed . |
33,201 | public Selector createSelector ( ) { selectorSync . lock ( ) ; try { Selector selector = Selector . open ( ) ; assert ( selector != null ) ; selectors . add ( selector ) ; return selector ; } catch ( IOException e ) { throw new ZError . IOException ( e ) ; } finally { selectorSync . unlock ( ) ; } } | Creates a Selector that will be closed when the context is destroyed . |
33,202 | boolean registerEndpoint ( String addr , Endpoint endpoint ) { endpointsSync . lock ( ) ; Endpoint inserted = null ; try { inserted = endpoints . put ( addr , endpoint ) ; } finally { endpointsSync . unlock ( ) ; } if ( inserted != null ) { return false ; } return true ; } | Management of inproc endpoints . |
33,203 | public void attachPipe ( Pipe pipe ) { assert ( ! isTerminating ( ) ) ; assert ( this . pipe == null ) ; assert ( pipe != null ) ; this . pipe = pipe ; this . pipe . setEventSink ( this ) ; } | To be used once only when creating the session . |
33,204 | private void cleanPipes ( ) { assert ( pipe != null ) ; pipe . rollback ( ) ; pipe . flush ( ) ; while ( incompleteIn ) { Msg msg = pullMsg ( ) ; if ( msg == null ) { assert ( ! incompleteIn ) ; break ; } } } | Call this function when engine disconnect to get rid of leftovers . |
33,205 | public void destroy ( ) { for ( Socket socket : sockets ) { destroySocket ( socket ) ; } sockets . clear ( ) ; for ( Selector selector : selectors ) { context . close ( selector ) ; } selectors . clear ( ) ; if ( isMain ( ) ) { context . term ( ) ; } } | Destructor . Call this to gracefully terminate context and close any managed 0MQ sockets |
33,206 | public Socket createSocket ( SocketType type ) { Socket socket = context . socket ( type ) ; socket . setRcvHWM ( this . rcvhwm ) ; socket . setSndHWM ( this . sndhwm ) ; sockets . add ( socket ) ; return socket ; } | Creates a new managed socket within this ZContext instance . Use this to get automatic management of the socket at shutdown |
33,207 | public void destroySocket ( Socket s ) { if ( s == null ) { return ; } s . setLinger ( linger ) ; s . close ( ) ; this . sockets . remove ( s ) ; } | Destroys managed socket within this context and remove from sockets list |
33,208 | Selector selector ( ) { Selector selector = context . selector ( ) ; selectors . add ( selector ) ; return selector ; } | Creates a selector . Resource will be released when context will be closed . |
33,209 | public void closeSelector ( Selector selector ) { if ( selectors . remove ( selector ) ) { context . close ( selector ) ; } } | Closes a selector . This is a DRAFT method and may change without notice . |
33,210 | public static ZContext shadow ( ZContext ctx ) { ZContext context = new ZContext ( ctx . context , false , ctx . ioThreads ) ; context . linger = ctx . linger ; context . sndhwm = ctx . sndhwm ; context . rcvhwm = ctx . rcvhwm ; context . pipehwm = ctx . pipehwm ; return context ; } | Creates new shadow context . Shares same underlying org . zeromq . Context instance but has own list of managed sockets io thread count etc . |
33,211 | public Socket fork ( ZThread . IAttachedRunnable runnable , Object ... args ) { return ZThread . fork ( this , runnable , args ) ; } | Create an attached thread An attached thread gets a ctx and a PAIR pipe back to its parent . It must monitor its pipe and exit if the pipe becomes unreadable |
33,212 | public static ByteBuffer putUInt64 ( ByteBuffer buf , long value ) { buf . put ( ( byte ) ( ( value >>> 56 ) & 0xff ) ) ; buf . put ( ( byte ) ( ( value >>> 48 ) & 0xff ) ) ; buf . put ( ( byte ) ( ( value >>> 40 ) & 0xff ) ) ; buf . put ( ( byte ) ( ( value >>> 32 ) & 0xff ) ) ; buf . put ( ( byte ) ( ( value >>> 24 ) & 0xff ) ) ; buf . put ( ( byte ) ( ( value >>> 16 ) & 0xff ) ) ; buf . put ( ( byte ) ( ( value >>> 8 ) & 0xff ) ) ; buf . put ( ( byte ) ( ( value ) & 0xff ) ) ; return buf ; } | 8 bytes value |
33,213 | public static Socket fork ( ZContext ctx , IAttachedRunnable runnable , Object ... args ) { Socket pipe = ctx . createSocket ( SocketType . PAIR ) ; if ( pipe != null ) { pipe . bind ( String . format ( "inproc://zctx-pipe-%d" , pipe . hashCode ( ) ) ) ; } else { return null ; } ZContext ccontext = ZContext . shadow ( ctx ) ; Socket cpipe = ccontext . createSocket ( SocketType . PAIR ) ; if ( cpipe == null ) { return null ; } cpipe . connect ( String . format ( "inproc://zctx-pipe-%d" , pipe . hashCode ( ) ) ) ; Thread shim = new ShimThread ( ccontext , runnable , args , cpipe ) ; shim . start ( ) ; return pipe ; } | pipe becomes unreadable . Returns pipe or null if there was an error . |
33,214 | private void startConnecting ( ) { try { boolean rc = open ( ) ; if ( rc ) { handle = ioObject . addFd ( fd ) ; connectEvent ( ) ; } else { handle = ioObject . addFd ( fd ) ; ioObject . setPollConnect ( handle ) ; socket . eventConnectDelayed ( addr . toString ( ) , - 1 ) ; } } catch ( RuntimeException | IOException e ) { if ( fd != null ) { close ( ) ; } addReconnectTimer ( ) ; } } | Internal function to start the actual connection establishment . |
33,215 | private void addReconnectTimer ( ) { int rcIvl = getNewReconnectIvl ( ) ; ioObject . addTimer ( rcIvl , RECONNECT_TIMER_ID ) ; try { addr . resolve ( options . ipv6 ) ; } catch ( Exception ignored ) { } socket . eventConnectRetried ( addr . toString ( ) , rcIvl ) ; timerStarted = true ; } | Internal function to add a reconnect timer |
33,216 | private int getNewReconnectIvl ( ) { int interval = currentReconnectIvl + ( Utils . randomInt ( ) % options . reconnectIvl ) ; if ( options . reconnectIvlMax > 0 && options . reconnectIvlMax > options . reconnectIvl ) { currentReconnectIvl = Math . min ( currentReconnectIvl * 2 , options . reconnectIvlMax ) ; } return interval ; } | Returns the currently used interval |
33,217 | private boolean open ( ) throws IOException { assert ( fd == null ) ; if ( addr == null ) { throw new IOException ( "Null address" ) ; } addr . resolve ( options . ipv6 ) ; Address . IZAddress resolved = addr . resolved ( ) ; if ( resolved == null ) { throw new IOException ( "Address not resolved" ) ; } SocketAddress sa = resolved . address ( ) ; if ( sa == null ) { throw new IOException ( "Socket address not resolved" ) ; } if ( options . selectorChooser == null ) { fd = SocketChannel . open ( ) ; } else { fd = options . selectorChooser . choose ( resolved , options ) . openSocketChannel ( ) ; } if ( resolved . family ( ) == StandardProtocolFamily . INET6 ) { TcpUtils . enableIpv4Mapping ( fd ) ; } TcpUtils . unblockSocket ( fd ) ; if ( options . sndbuf != 0 ) { TcpUtils . setTcpSendBuffer ( fd , options . sndbuf ) ; } if ( options . rcvbuf != 0 ) { TcpUtils . setTcpReceiveBuffer ( fd , options . rcvbuf ) ; } if ( options . tos != 0 ) { TcpUtils . setIpTypeOfService ( fd , options . tos ) ; } if ( resolved . sourceAddress ( ) != null ) { } boolean rc ; try { rc = fd . connect ( sa ) ; if ( rc ) { } else { errno . set ( ZError . EINPROGRESS ) ; } } catch ( IllegalArgumentException e ) { throw new IOException ( e . getMessage ( ) , e ) ; } return rc ; } | Returns false if async connect was launched . |
33,218 | private SocketChannel connect ( ) { try { boolean finished = fd . finishConnect ( ) ; assert ( finished ) ; return fd ; } catch ( IOException e ) { return null ; } } | null if the connection was unsuccessful . |
33,219 | protected void close ( ) { assert ( fd != null ) ; try { fd . close ( ) ; socket . eventClosed ( addr . toString ( ) , fd ) ; } catch ( IOException e ) { socket . eventCloseFailed ( addr . toString ( ) , ZError . exccode ( e ) ) ; } fd = null ; } | Close the connecting socket . |
33,220 | public boolean setInterval ( Timer timer , long interval ) { assert ( timer . parent == this ) ; return timer . setInterval ( interval ) ; } | Changes the interval of the timer . This method is slow canceling existing and adding a new timer yield better performance . |
33,221 | public long timeout ( ) { final long now = now ( ) ; for ( Entry < Timer , Long > entry : entries ( ) ) { final Timer timer = entry . getKey ( ) ; final Long expiration = entry . getValue ( ) ; if ( timer . alive ) { if ( expiration - now > 0 ) { return expiration - now ; } else { return 0 ; } } timers . remove ( expiration , timer ) ; } return - 1 ; } | Returns the time in millisecond until the next timer . |
33,222 | public int execute ( ) { int executed = 0 ; final long now = now ( ) ; for ( Entry < Timer , Long > entry : entries ( ) ) { final Timer timer = entry . getKey ( ) ; final Long expiration = entry . getValue ( ) ; if ( ! timer . alive ) { timers . remove ( expiration , timer ) ; continue ; } if ( expiration - now > 0 ) { break ; } insert ( timer ) ; timer . handler . time ( timer . args ) ; ++ executed ; } return executed ; } | Execute the timers . |
33,223 | public static ZProxy newProxy ( ZContext ctx , String name , Proxy sockets , String motdelafin , Object ... args ) { return new ZProxy ( ctx , name , sockets , new ZmqPump ( ) , motdelafin , args ) ; } | Creates a new low - level proxy for better performances . |
33,224 | public String restart ( ZMsg hot ) { ZMsg msg = new ZMsg ( ) ; msg . add ( RESTART ) ; final boolean cold = hot == null ; if ( cold ) { msg . add ( Boolean . toString ( false ) ) ; } else { msg . add ( Boolean . toString ( true ) ) ; msg . append ( hot ) ; } String status = EXITED ; if ( agent . send ( msg ) ) { status = status ( false ) ; } return status ; } | Restarts the proxy . Stays alive . |
33,225 | public String exit ( ) { agent . send ( EXIT ) ; exit . awaitSilent ( ) ; agent . close ( ) ; return EXITED ; } | Stops the proxy and exits . The call is synchronous . |
33,226 | public String status ( boolean sync ) { if ( exit . isExited ( ) ) { return EXITED ; } try { String status = recvStatus ( ) ; if ( agent . send ( STATUS ) && sync ) { status = recvStatus ( ) ; if ( EXITED . equals ( status ) || ! agent . send ( STATUS ) ) { return EXITED ; } } return status ; } catch ( ZMQException e ) { return EXITED ; } } | Inquires for the status of the proxy . |
33,227 | private String recvStatus ( ) { if ( ! agent . sign ( ) ) { return EXITED ; } final ZMsg msg = agent . recv ( ) ; if ( msg == null ) { return EXITED ; } String status = msg . popString ( ) ; msg . destroy ( ) ; return status ; } | receives the last known state of the proxy |
33,228 | public boolean containsPublicKey ( byte [ ] publicKey ) { Utils . checkArgument ( publicKey . length == 32 , "publickey needs to have a size of 32 bytes. got only " + publicKey . length ) ; return containsPublicKey ( ZMQ . Curve . z85Encode ( publicKey ) ) ; } | Check if a public key is in the certificate store . |
33,229 | public boolean containsPublicKey ( String publicKey ) { Utils . checkArgument ( publicKey . length ( ) == 40 , "z85 publickeys should have a length of 40 bytes but got " + publicKey . length ( ) ) ; reloadIfNecessary ( ) ; return publicKeys . containsKey ( publicKey ) ; } | check if a z85 - based public key is in the certificate store . This method will scan the folder for changes on every call |
33,230 | boolean checkForChanges ( ) { final Map < File , byte [ ] > presents = new HashMap < > ( fingerprints ) ; boolean modified = traverseDirectory ( location , new IFileVisitor ( ) { public boolean visitFile ( File file ) { return modified ( presents . remove ( file ) , file ) ; } public boolean visitDir ( File dir ) { return modified ( presents . remove ( dir ) , dir ) ; } } ) ; return modified || ! presents . isEmpty ( ) ; } | Check if files in the certificate folders have been added or removed . |
33,231 | public ZAuth configureCurve ( String location ) { Objects . requireNonNull ( location , "Location has to be supplied" ) ; return send ( Mechanism . CURVE . name ( ) , location ) ; } | Configure CURVE authentication |
33,232 | public ZapReply nextReply ( boolean wait ) { if ( ! repliesEnabled ) { System . out . println ( "ZAuth: replies are disabled. Please use replies(true);" ) ; return null ; } return ZapReply . recv ( replies , wait ) ; } | Retrieves the next ZAP reply . |
33,233 | public static int send ( SocketBase s , String str , int flags ) { byte [ ] data = str . getBytes ( CHARSET ) ; return send ( s , data , data . length , flags ) ; } | Sending functions . |
33,234 | public static Msg recv ( SocketBase s , int flags ) { checkSocket ( s ) ; Msg msg = recvMsg ( s , flags ) ; if ( msg == null ) { return null ; } return msg ; } | Receiving functions . |
33,235 | public static String getMessageMetadata ( Msg msg , String property ) { String data = null ; Metadata metadata = msg . getMetadata ( ) ; if ( metadata != null ) { data = metadata . get ( property ) ; } return data ; } | Get message metadata string |
33,236 | public static boolean proxy ( SocketBase frontend , SocketBase backend , SocketBase capture ) { Utils . checkArgument ( frontend != null , "Frontend socket has to be present for proxy" ) ; Utils . checkArgument ( backend != null , "Backend socket has to be present for proxy" ) ; return Proxy . proxy ( frontend , backend , capture , null ) ; } | The proxy functionality |
33,237 | public final ZMonitor start ( ) { if ( started ) { System . out . println ( "ZMonitor: Unable to start while already started." ) ; return this ; } agent . send ( START ) ; agent . recv ( ) ; started = true ; return this ; } | Starts the monitoring . Event types have to be added before the start or they will take no effect . |
33,238 | public final ZMonitor verbose ( boolean verbose ) { if ( started ) { System . out . println ( "ZMonitor: Unable to change verbosity while already started." ) ; return this ; } agent . send ( VERBOSE , true ) ; agent . send ( Boolean . toString ( verbose ) ) ; agent . recv ( ) ; return this ; } | Sets verbosity of the monitor . |
33,239 | public final ZMonitor add ( Event ... events ) { if ( started ) { System . out . println ( "ZMonitor: Unable to add events while already started." ) ; return this ; } ZMsg msg = new ZMsg ( ) ; msg . add ( ADD_EVENTS ) ; for ( Event evt : events ) { msg . add ( evt . name ( ) ) ; } agent . send ( msg ) ; agent . recv ( ) ; return this ; } | Adds event types to monitor . |
33,240 | public final ZEvent nextEvent ( boolean wait ) { if ( ! started ) { System . out . println ( "ZMonitor: Start before getting events." ) ; return null ; } ZMsg msg = agent . recv ( wait ) ; if ( msg == null ) { return null ; } return new ZEvent ( msg ) ; } | Gets the next event blocking for it until available if requested . |
33,241 | public boolean sendFrame ( ZFrame frame , int flags ) { final byte [ ] data = frame . getData ( ) ; final Msg msg = new Msg ( data ) ; if ( socketBase . send ( msg , flags ) ) { return true ; } mayRaise ( ) ; return false ; } | Send a frame |
33,242 | public static Pipe [ ] pair ( ZObject [ ] parents , int [ ] hwms , boolean [ ] conflates ) { Pipe [ ] pipes = new Pipe [ 2 ] ; YPipeBase < Msg > upipe1 = conflates [ 0 ] ? new YPipeConflate < > ( ) : new YPipe < Msg > ( Config . MESSAGE_PIPE_GRANULARITY . getValue ( ) ) ; YPipeBase < Msg > upipe2 = conflates [ 1 ] ? new YPipeConflate < > ( ) : new YPipe < Msg > ( Config . MESSAGE_PIPE_GRANULARITY . getValue ( ) ) ; pipes [ 0 ] = new Pipe ( parents [ 0 ] , upipe1 , upipe2 , hwms [ 1 ] , hwms [ 0 ] , conflates [ 0 ] ) ; pipes [ 1 ] = new Pipe ( parents [ 1 ] , upipe2 , upipe1 , hwms [ 0 ] , hwms [ 1 ] , conflates [ 1 ] ) ; pipes [ 0 ] . setPeer ( pipes [ 1 ] ) ; pipes [ 1 ] . setPeer ( pipes [ 0 ] ) ; return pipes ; } | terminates straight away . |
33,243 | public boolean checkRead ( ) { if ( ! inActive ) { return false ; } if ( state != State . ACTIVE && state != State . WAITING_FOR_DELIMITER ) { return false ; } if ( ! inpipe . checkRead ( ) ) { inActive = false ; return false ; } if ( isDelimiter ( inpipe . probe ( ) ) ) { Msg msg = inpipe . read ( ) ; assert ( msg != null ) ; processDelimiter ( ) ; return false ; } return true ; } | Returns true if there is at least one message to read in the pipe . |
33,244 | public Msg read ( ) { if ( ! inActive ) { return null ; } if ( state != State . ACTIVE && state != State . WAITING_FOR_DELIMITER ) { return null ; } while ( true ) { Msg msg = inpipe . read ( ) ; if ( msg == null ) { inActive = false ; return null ; } if ( msg . isCredential ( ) ) { credential = Blob . createBlob ( msg ) ; continue ; } if ( msg . isDelimiter ( ) ) { processDelimiter ( ) ; return null ; } if ( ! msg . hasMore ( ) && ! msg . isIdentity ( ) ) { msgsRead ++ ; } if ( lwm > 0 && msgsRead % lwm == 0 ) { sendActivateWrite ( peer , msgsRead ) ; } return msg ; } } | Reads a message to the underlying pipe . |
33,245 | public boolean checkWrite ( ) { if ( ! outActive || state != State . ACTIVE ) { return false ; } boolean full = ! checkHwm ( ) ; if ( full ) { outActive = false ; return false ; } return true ; } | the message would cause high watermark the function returns false . |
33,246 | public boolean write ( Msg msg ) { if ( ! checkWrite ( ) ) { return false ; } boolean more = msg . hasMore ( ) ; boolean identity = msg . isIdentity ( ) ; outpipe . write ( msg , more ) ; if ( ! more && ! identity ) { msgsWritten ++ ; } return true ; } | message cannot be written because high watermark was reached . |
33,247 | public void rollback ( ) { Msg msg ; if ( outpipe != null ) { while ( ( msg = outpipe . unwrite ( ) ) != null ) { assert ( msg . hasMore ( ) ) ; } } } | Remove unfinished parts of the outbound message from the pipe . |
33,248 | public void flush ( ) { if ( state == State . TERM_ACK_SENT ) { return ; } if ( outpipe != null && ! outpipe . flush ( ) ) { sendActivateRead ( peer ) ; } } | Flush the messages downstream . |
33,249 | public void terminate ( boolean delay ) { this . delay = delay ; if ( state == State . TERM_REQ_SENT_1 || state == State . TERM_REQ_SENT_2 ) { return ; } else if ( state == State . TERM_ACK_SENT ) { return ; } else if ( state == State . ACTIVE ) { sendPipeTerm ( peer ) ; state = State . TERM_REQ_SENT_1 ; } else if ( state == State . WAITING_FOR_DELIMITER && ! this . delay ) { outpipe = null ; sendPipeTermAck ( peer ) ; state = State . TERM_ACK_SENT ; } else if ( state == State . WAITING_FOR_DELIMITER ) { } else if ( state == State . DELIMITER_RECEIVED ) { sendPipeTerm ( peer ) ; state = State . TERM_REQ_SENT_1 ; } else { assert ( false ) ; } outActive = false ; if ( outpipe != null ) { rollback ( ) ; Msg msg = new Msg ( ) ; msg . initDelimiter ( ) ; outpipe . write ( msg , false ) ; flush ( ) ; } } | before actual shutdown . |
33,250 | private void processDelimiter ( ) { assert ( state == State . ACTIVE || state == State . WAITING_FOR_DELIMITER ) ; if ( state == State . ACTIVE ) { state = State . DELIMITER_RECEIVED ; } else { outpipe = null ; sendPipeTermAck ( peer ) ; state = State . TERM_ACK_SENT ; } } | Handler for delimiter read from the pipe . |
33,251 | public void hiccup ( ) { if ( state != State . ACTIVE ) { return ; } inpipe = null ; if ( conflate ) { inpipe = new YPipeConflate < > ( ) ; } else { inpipe = new YPipe < > ( Config . MESSAGE_PIPE_GRANULARITY . getValue ( ) ) ; } inActive = true ; sendHiccup ( peer , inpipe ) ; } | in the peer . |
33,252 | protected boolean rollback ( ) { if ( currentOut != null ) { currentOut . rollback ( ) ; currentOut = null ; moreOut = false ; } return true ; } | Rollback any message parts that were sent but not yet flushed . |
33,253 | public final int encode ( ValueReference < ByteBuffer > data , int size ) { int bufferSize = size ; ByteBuffer buf = data . get ( ) ; if ( buf == null ) { buf = this . buffer ; bufferSize = this . bufferSize ; buffer . clear ( ) ; } if ( inProgress == null ) { return 0 ; } int pos = 0 ; buf . limit ( buf . capacity ( ) ) ; while ( pos < bufferSize ) { if ( toWrite == 0 ) { if ( newMsgFlag ) { inProgress = null ; break ; } next ( ) ; } if ( pos == 0 && data . get ( ) == null && toWrite >= bufferSize ) { writeBuf . limit ( writeBuf . capacity ( ) ) ; data . set ( writeBuf ) ; pos = toWrite ; writeBuf = null ; toWrite = 0 ; return pos ; } int toCopy = Math . min ( toWrite , bufferSize - pos ) ; int limit = writeBuf . limit ( ) ; writeBuf . limit ( Math . min ( writeBuf . capacity ( ) , writeBuf . position ( ) + toCopy ) ) ; int current = buf . position ( ) ; buf . put ( writeBuf ) ; toCopy = buf . position ( ) - current ; writeBuf . limit ( limit ) ; pos += toCopy ; toWrite -= toCopy ; } data . set ( buf ) ; return pos ; } | is NULL ) encoder will provide buffer of its own . |
33,254 | private void nextStep ( byte [ ] buf , int toWrite , Runnable next , boolean newMsgFlag ) { if ( buf != null ) { writeBuf = ByteBuffer . wrap ( buf ) ; writeBuf . limit ( toWrite ) ; } else { writeBuf = null ; } this . toWrite = toWrite ; this . next = next ; this . newMsgFlag = newMsgFlag ; } | to the buffer and schedule next state machine action . |
33,255 | public void addTimer ( long timeout , IPollEvents sink , int id ) { assert ( Thread . currentThread ( ) == worker ) ; final long expiration = clock ( ) + timeout ; TimerInfo info = new TimerInfo ( sink , id ) ; timers . insert ( expiration , info ) ; changed = true ; } | argument set to id_ . |
33,256 | public void cancelTimer ( IPollEvents sink , int id ) { assert ( Thread . currentThread ( ) == worker ) ; TimerInfo copy = new TimerInfo ( sink , id ) ; TimerInfo timerInfo = timers . find ( copy ) ; if ( timerInfo != null ) { timerInfo . cancelled = true ; } } | Cancel the timer created by sink_ object with ID equal to id_ . |
33,257 | protected long executeTimers ( ) { assert ( Thread . currentThread ( ) == worker ) ; changed = false ; if ( timers . isEmpty ( ) ) { return 0L ; } long current = clock ( ) ; for ( Entry < TimerInfo , Long > entry : timers . entries ( ) ) { final TimerInfo timerInfo = entry . getKey ( ) ; if ( timerInfo . cancelled ) { timers . remove ( entry . getValue ( ) , timerInfo ) ; continue ; } final Long key = entry . getValue ( ) ; if ( key > current ) { return key - current ; } timers . remove ( key , timerInfo ) ; timerInfo . sink . timerEvent ( timerInfo . id ) ; } for ( Entry < TimerInfo , Long > entry : timers . entries ( ) ) { final Long key = entry . getValue ( ) ; if ( ! timers . hasValues ( key ) ) { timers . remove ( key ) ; } } if ( changed ) { return executeTimers ( ) ; } return 0L ; } | to wait to match the next timer or 0 meaning no timers . |
33,258 | protected void processTerm ( int linger ) { assert ( ! terminating ) ; for ( Own it : owned ) { sendTerm ( it , linger ) ; } registerTermAcks ( owned . size ( ) ) ; owned . clear ( ) ; terminating = true ; checkTermAcks ( ) ; } | steps to the beginning of the termination process . |
33,259 | public boolean rm ( Pipe pipe , IMtrieHandler func , XPub pub ) { assert ( pipe != null ) ; assert ( func != null ) ; return rmHelper ( pipe , new byte [ 0 ] , 0 , 0 , func , pub ) ; } | supplied callback function . |
33,260 | public boolean rm ( Msg msg , Pipe pipe ) { assert ( msg != null ) ; assert ( pipe != null ) ; return rmHelper ( msg , 1 , msg . size ( ) - 1 , pipe ) ; } | actually removed rather than de - duplicated . |
33,261 | public void match ( ByteBuffer data , int size , IMtrieHandler func , XPub pub ) { assert ( data != null ) ; assert ( func != null ) ; assert ( pub != null ) ; Mtrie current = this ; int idx = 0 ; while ( true ) { if ( current . pipes != null ) { for ( Pipe it : current . pipes ) { func . invoke ( it , null , 0 , pub ) ; } } if ( size == 0 ) { break ; } if ( current . count == 0 ) { break ; } byte c = data . get ( idx ) ; if ( current . count == 1 ) { if ( c != current . min ) { break ; } current = current . next [ 0 ] ; idx ++ ; size -- ; continue ; } if ( c < current . min || c >= current . min + current . count ) { break ; } if ( current . next [ c - current . min ] == null ) { break ; } current = current . next [ c - current . min ] ; idx ++ ; size -- ; } } | Signal all the matching pipes . |
33,262 | private void close ( ) { assert ( fd != null ) ; try { fd . close ( ) ; socket . eventClosed ( endpoint , fd ) ; } catch ( IOException e ) { socket . eventCloseFailed ( endpoint , ZError . exccode ( e ) ) ; } fd = null ; } | Close the listening socket . |
33,263 | private SocketChannel accept ( ) throws IOException { assert ( fd != null ) ; SocketChannel sock = fd . accept ( ) ; if ( ! options . tcpAcceptFilters . isEmpty ( ) ) { boolean matched = false ; for ( TcpAddress . TcpAddressMask am : options . tcpAcceptFilters ) { if ( am . matchAddress ( address . address ( ) ) ) { matched = true ; break ; } } if ( ! matched ) { try { sock . close ( ) ; } catch ( IOException e ) { } return null ; } } if ( options . tos != 0 ) { TcpUtils . setIpTypeOfService ( sock , options . tos ) ; } if ( options . sndbuf != 0 ) { TcpUtils . setTcpSendBuffer ( sock , options . sndbuf ) ; } if ( options . rcvbuf != 0 ) { TcpUtils . setTcpReceiveBuffer ( sock , options . rcvbuf ) ; } if ( ! isWindows ) { TcpUtils . setReuseAddress ( sock , true ) ; } return sock ; } | or was denied because of accept filters . |
33,264 | public void attach ( Pipe pipe ) { if ( more ) { pipes . add ( pipe ) ; Collections . swap ( pipes , eligible , pipes . size ( ) - 1 ) ; eligible ++ ; } else { pipes . add ( pipe ) ; Collections . swap ( pipes , active , pipes . size ( ) - 1 ) ; active ++ ; eligible ++ ; } } | Adds the pipe to the distributor object . |
33,265 | public void match ( Pipe pipe ) { int idx = pipes . indexOf ( pipe ) ; if ( idx < matching ) { return ; } if ( idx >= eligible ) { return ; } Collections . swap ( pipes , idx , matching ) ; matching ++ ; } | will send message also to this pipe . |
33,266 | public void terminated ( Pipe pipe ) { if ( pipes . indexOf ( pipe ) < matching ) { Collections . swap ( pipes , pipes . indexOf ( pipe ) , matching - 1 ) ; matching -- ; } if ( pipes . indexOf ( pipe ) < active ) { Collections . swap ( pipes , pipes . indexOf ( pipe ) , active - 1 ) ; active -- ; } if ( pipes . indexOf ( pipe ) < eligible ) { Collections . swap ( pipes , pipes . indexOf ( pipe ) , eligible - 1 ) ; eligible -- ; } pipes . remove ( pipe ) ; } | Removes the pipe from the distributor object . |
33,267 | public void activated ( Pipe pipe ) { Collections . swap ( pipes , pipes . indexOf ( pipe ) , eligible ) ; eligible ++ ; if ( ! more ) { Collections . swap ( pipes , eligible - 1 , active ) ; active ++ ; } } | Activates pipe that have previously reached high watermark . |
33,268 | public boolean sendToMatching ( Msg msg ) { boolean msgMore = msg . hasMore ( ) ; distribute ( msg ) ; if ( ! msgMore ) { active = eligible ; } more = msgMore ; return true ; } | Send the message to the matching outbound pipes . |
33,269 | private void distribute ( Msg msg ) { if ( matching == 0 ) { return ; } for ( int idx = 0 ; idx < matching ; ++ idx ) { if ( ! write ( pipes . get ( idx ) , msg ) ) { -- idx ; } } } | Put the message to all active pipes . |
33,270 | private boolean write ( Pipe pipe , Msg msg ) { if ( ! pipe . write ( msg ) ) { Collections . swap ( pipes , pipes . indexOf ( pipe ) , matching - 1 ) ; matching -- ; Collections . swap ( pipes , pipes . indexOf ( pipe ) , active - 1 ) ; active -- ; Collections . swap ( pipes , active , eligible - 1 ) ; eligible -- ; return false ; } if ( ! msg . hasMore ( ) ) { pipe . flush ( ) ; } return true ; } | fails . In such a case false is returned . |
33,271 | public final boolean register ( final SelectableChannel channel , final EventsHandler handler ) { return register ( channel , handler , IN | OUT | ERR ) ; } | Registers a SelectableChannel for polling on all events . |
33,272 | public final boolean unregister ( final Object socketOrChannel ) { if ( socketOrChannel == null ) { return false ; } CompositePollItem items = this . items . remove ( socketOrChannel ) ; boolean rc = items != null ; if ( rc ) { all . remove ( items ) ; } return rc ; } | Unregister a Socket or SelectableChannel for polling on the specified events . |
33,273 | protected int poll ( final long timeout , final boolean dispatchEvents ) { final Set < PollItem > pollItems = new HashSet < > ( ) ; for ( CompositePollItem it : all ) { pollItems . add ( it . item ( ) ) ; } final int rc = poll ( selector , timeout , pollItems ) ; if ( ! dispatchEvents ) { return rc ; } if ( dispatch ( all , pollItems . size ( ) ) ) { return rc ; } return - 1 ; } | Issue a poll call using the specified timeout value . |
33,274 | protected int poll ( final Selector selector , final long tout , final Collection < zmq . poll . PollItem > items ) { final int size = items . size ( ) ; return zmq . ZMQ . poll ( selector , items . toArray ( new PollItem [ size ] ) , size , tout ) ; } | does the effective polling |
33,275 | protected boolean dispatch ( final Collection < ? extends ItemHolder > all , int size ) { ItemHolder [ ] array = all . toArray ( new ItemHolder [ all . size ( ) ] ) ; for ( ItemHolder holder : array ) { EventsHandler handler = holder . handler ( ) ; if ( handler == null ) { handler = globalHandler ; } if ( handler == null ) { continue ; } final PollItem item = holder . item ( ) ; final int events = item . readyOps ( ) ; if ( events <= 0 ) { continue ; } final Socket socket = holder . socket ( ) ; final SelectableChannel channel = holder . item ( ) . getRawSocket ( ) ; if ( socket != null ) { assert ( channel == null ) ; if ( ! handler . events ( socket , events ) ) { return false ; } } if ( channel != null ) { assert ( socket == null ) ; if ( ! handler . events ( channel , events ) ) { return false ; } } } return true ; } | Dispatches the polled events . |
33,276 | public boolean readable ( final Object socketOrChannel ) { final PollItem it = filter ( socketOrChannel , READABLE ) ; if ( it == null ) { return false ; } return it . isReadable ( ) ; } | checks for read event |
33,277 | public boolean writable ( final Object socketOrChannel ) { final PollItem it = filter ( socketOrChannel , WRITABLE ) ; if ( it == null ) { return false ; } return it . isWritable ( ) ; } | checks for write event |
33,278 | public boolean error ( final Object socketOrChannel ) { final PollItem it = filter ( socketOrChannel , ERR ) ; if ( it == null ) { return false ; } return it . isError ( ) ; } | checks for error event |
33,279 | protected boolean add ( Object socketOrChannel , final ItemHolder holder ) { if ( socketOrChannel == null ) { Socket socket = holder . socket ( ) ; SelectableChannel ch = holder . item ( ) . getRawSocket ( ) ; if ( ch == null ) { assert ( socket != null ) ; socketOrChannel = socket ; } else if ( socket == null ) { socketOrChannel = ch ; } } assert ( socketOrChannel != null ) ; CompositePollItem aggregate = items . get ( socketOrChannel ) ; if ( aggregate == null ) { aggregate = new CompositePollItem ( socketOrChannel ) ; items . put ( socketOrChannel , aggregate ) ; } final boolean rc = aggregate . holders . add ( holder ) ; if ( rc ) { all . add ( aggregate ) ; } return rc ; } | add an item to this poller |
33,280 | protected Collection < ? extends ItemHolder > items ( ) { for ( CompositePollItem item : all ) { item . handler ( globalHandler ) ; } return all ; } | gets all the items of this poller |
33,281 | protected Iterable < ItemHolder > items ( final Object socketOrChannel ) { final CompositePollItem aggregate = items . get ( socketOrChannel ) ; if ( aggregate == null ) { return Collections . emptySet ( ) ; } return aggregate . holders ; } | gets all the items of this poller regarding the given input |
33,282 | protected PollItem filter ( final Object socketOrChannel , int events ) { if ( socketOrChannel == null ) { return null ; } CompositePollItem item = items . get ( socketOrChannel ) ; if ( item == null ) { return null ; } PollItem pollItem = item . item ( ) ; if ( pollItem == null ) { return null ; } if ( pollItem . hasEvent ( events ) ) { return pollItem ; } return null ; } | filters items to get the first one matching the criteria or null if none found |
33,283 | public String getShortString ( ) { String value = Wire . getShortString ( needle , needle . position ( ) ) ; forward ( value . length ( ) + 1 ) ; return value ; } | Get a string from the frame |
33,284 | public String getLongString ( ) { String value = Wire . getLongString ( needle , needle . position ( ) ) ; forward ( value . length ( ) + 4 ) ; return value ; } | Get a long string from the frame |
33,285 | public void putList ( Collection < String > elements ) { if ( elements == null ) { putNumber1 ( 0 ) ; } else { Utils . checkArgument ( elements . size ( ) < 256 , "Collection has to be smaller than 256 elements" ) ; putNumber1 ( elements . size ( ) ) ; for ( String string : elements ) { putString ( string ) ; } } } | Put a collection of strings to the frame |
33,286 | public void putMap ( Map < String , String > map ) { if ( map == null ) { putNumber1 ( 0 ) ; } else { Utils . checkArgument ( map . size ( ) < 256 , "Map has to be smaller than 256 elements" ) ; putNumber1 ( map . size ( ) ) ; for ( Entry < String , String > entry : map . entrySet ( ) ) { if ( entry . getKey ( ) . contains ( "=" ) ) { throw new IllegalArgumentException ( "Keys cannot contain '=' sign. " + entry ) ; } if ( entry . getValue ( ) . contains ( "=" ) ) { throw new IllegalArgumentException ( "Values cannot contain '=' sign. " + entry ) ; } String val = entry . getKey ( ) + "=" + entry . getValue ( ) ; putString ( val ) ; } } } | Put a map of strings to the frame |
33,287 | public void push ( T val ) { backChunk . values [ backPos ] = val ; backChunk = endChunk ; backPos = endPos ; if ( ++ endPos != size ) { return ; } Chunk < T > sc = spareChunk ; if ( sc != beginChunk ) { spareChunk = spareChunk . next ; endChunk . next = sc ; sc . prev = endChunk ; } else { endChunk . next = new Chunk < > ( size , memoryPtr ) ; memoryPtr += size ; endChunk . next . prev = endChunk ; } endChunk = endChunk . next ; endPos = 0 ; } | Adds an element to the back end of the queue . |
33,288 | public void unpush ( ) { if ( backPos > 0 ) { -- backPos ; } else { backPos = size - 1 ; backChunk = backChunk . prev ; } if ( endPos > 0 ) { -- endPos ; } else { endPos = size - 1 ; endChunk = endChunk . prev ; endChunk . next = null ; } } | unsynchronised thread . |
33,289 | public T pop ( ) { T val = beginChunk . values [ beginPos ] ; beginChunk . values [ beginPos ] = null ; beginPos ++ ; if ( beginPos == size ) { beginChunk = beginChunk . next ; beginChunk . prev = null ; beginPos = 0 ; } return val ; } | Removes an element from the front end of the queue . |
33,290 | private void rebuild ( ) { pollact = null ; pollSize = pollers . size ( ) ; if ( pollset != null ) { pollset . close ( ) ; } pollset = context . poller ( pollSize ) ; assert ( pollset != null ) ; pollact = new SPoller [ pollSize ] ; int itemNbr = 0 ; for ( SPoller poller : pollers ) { pollset . register ( poller . item ) ; pollact [ itemNbr ] = poller ; itemNbr ++ ; } dirty = false ; } | activity on pollers . Returns 0 on success - 1 on failure . |
33,291 | public int addPoller ( PollItem pollItem , IZLoopHandler handler , Object arg ) { if ( pollItem . getRawSocket ( ) == null && pollItem . getSocket ( ) == null ) { return - 1 ; } SPoller poller = new SPoller ( pollItem , handler , arg ) ; pollers . add ( poller ) ; dirty = true ; if ( verbose ) { System . out . printf ( "I: zloop: register %s poller (%s, %s)\n" , pollItem . getSocket ( ) != null ? pollItem . getSocket ( ) . getType ( ) : "RAW" , pollItem . getSocket ( ) , pollItem . getRawSocket ( ) ) ; } return 0 ; } | corresponding handler . |
33,292 | public int removeTimer ( Object arg ) { Objects . requireNonNull ( arg , "Argument has to be supplied" ) ; zombies . add ( arg ) ; if ( verbose ) { System . out . printf ( "I: zloop: cancel timer\n" ) ; } return 0 ; } | Returns 0 on success . |
33,293 | public ANRWatchDog setANRListener ( ANRListener listener ) { if ( listener == null ) { _anrListener = DEFAULT_ANR_LISTENER ; } else { _anrListener = listener ; } return this ; } | Sets an interface for when an ANR is detected . If not set the default behavior is to throw an error and crash the application . |
33,294 | public ANRWatchDog setANRInterceptor ( ANRInterceptor interceptor ) { if ( interceptor == null ) { _anrInterceptor = DEFAULT_ANR_INTERCEPTOR ; } else { _anrInterceptor = interceptor ; } return this ; } | Sets an interface to intercept ANRs before they are reported . If set you can define if given the current duration of the detected ANR and external context it is necessary to report the ANR . |
33,295 | public ANRWatchDog setInterruptionListener ( InterruptionListener listener ) { if ( listener == null ) { _interruptionListener = DEFAULT_INTERRUPTION_LISTENER ; } else { _interruptionListener = listener ; } return this ; } | Sets an interface for when the watchdog thread is interrupted . If not set the default behavior is to just log the interruption message . |
33,296 | private static Type processTypeForDescendantLookup ( Type type ) { if ( type instanceof ParameterizedType ) { return ( ( ParameterizedType ) type ) . getRawType ( ) ; } else { return type ; } } | Given a type returns the type that should be used for the purpose of looking up implementations of that type . |
33,297 | private static < T > Stream < T > generateStream ( T seed , Predicate < ? super T > hasNext , UnaryOperator < T > next ) { final Spliterator < T > spliterator = Spliterators . spliteratorUnknownSize ( new Iterator < T > ( ) { private T last = seed ; public boolean hasNext ( ) { return hasNext . test ( last ) ; } public T next ( ) { final T current = last ; last = next . apply ( last ) ; return current ; } } , Spliterator . ORDERED ) ; return StreamSupport . stream ( spliterator , false ) ; } | remove on Java 9 and replace with Stream . iterate |
33,298 | private static Set < TsBeanModel > writeBeanAndParentsFieldSpecs ( Writer writer , Settings settings , TsModel model , Set < TsBeanModel > emittedSoFar , TsBeanModel bean ) { if ( emittedSoFar . contains ( bean ) ) { return new HashSet < > ( ) ; } final TsBeanModel parentBean = getBeanModelByType ( model , bean . getParent ( ) ) ; final Set < TsBeanModel > emittedBeans = parentBean != null ? writeBeanAndParentsFieldSpecs ( writer , settings , model , emittedSoFar , parentBean ) : new HashSet < TsBeanModel > ( ) ; final String parentClassName = parentBean != null ? getBeanModelClassName ( parentBean ) + "Fields" : "Fields" ; writer . writeIndentedLine ( "" ) ; writer . writeIndentedLine ( "class " + getBeanModelClassName ( bean ) + "Fields extends " + parentClassName + " {" ) ; writer . writeIndentedLine ( settings . indentString + "constructor(parent?: Fields, name?: string) { super(parent, name); }" ) ; for ( TsPropertyModel property : bean . getProperties ( ) ) { writeBeanProperty ( writer , settings , model , bean , property ) ; } writer . writeIndentedLine ( "}" ) ; emittedBeans . add ( bean ) ; return emittedBeans ; } | Emits a bean and its parent beans before if needed . Returns the list of beans that were emitted . |
33,299 | private static boolean isOriginalTsType ( TsType type ) { if ( type instanceof TsType . BasicType ) { TsType . BasicType basicType = ( TsType . BasicType ) type ; return ! ( basicType . name . equals ( "null" ) || basicType . name . equals ( "undefined" ) ) ; } return true ; } | is this type an original TS type or a contextual information? null undefined and optional info are not original types everything else is original |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.