idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
13,400 | protected void changedCacheData ( String cache , final Streamable data ) { ObserverList < StaleCacheObserver > list = _cacheobs . get ( cache ) ; if ( list == null ) { return ; } list . apply ( new ObserverList . ObserverOp < StaleCacheObserver > ( ) { public boolean apply ( StaleCacheObserver observer ) { observer . changedCacheData ( data ) ; return true ; } } ) ; } | Called when possibly cached data has changed on one of our peer servers . |
13,401 | protected void droppedLock ( final NodeObject . Lock lock ) { _nodeobj . removeFromLocks ( lock ) ; _stats . locksHijacked ++ ; _dropobs . apply ( new ObserverList . ObserverOp < DroppedLockObserver > ( ) { public boolean apply ( DroppedLockObserver observer ) { observer . droppedLock ( lock ) ; return true ; } } ) ; } | Called when we have been forced to drop a lock . |
13,402 | protected void clientLoggedOn ( String nodeName , ClientInfo clinfo ) { PresentsSession session = _clmgr . getClient ( clinfo . username ) ; if ( session != null ) { log . info ( "Booting user that has connected on another node" , "username" , clinfo . username , "otherNode" , nodeName ) ; session . endSession ( ) ; } } | Called when we hear about a client logging on to another node . |
13,403 | protected void peerAcquiringLock ( PeerNode peer , NodeObject . Lock lock ) { String owner = queryLock ( lock ) ; if ( owner != null ) { log . warning ( "Refusing to ratify lock acquisition." , "lock" , lock , "node" , peer . getNodeName ( ) , "owner" , owner ) ; return ; } LockHandler handler = _locks . get ( lock ) ; if ( handler == null ) { createLockHandler ( peer , lock , true ) ; return ; } if ( hasPriority ( handler . getNodeName ( ) , peer . getNodeName ( ) ) ) { return ; } ResultListenerList < String > olisteners = handler . listeners ; handler . cancel ( ) ; handler = createLockHandler ( peer , lock , true ) ; handler . listeners = olisteners ; } | Called when a peer announces its intention to acquire a lock . |
13,404 | protected void peerReleasingLock ( PeerNode peer , NodeObject . Lock lock ) { String owner = queryLock ( lock ) ; if ( ! peer . getNodeName ( ) . equals ( owner ) ) { log . warning ( "Refusing to ratify lock release." , "lock" , lock , "node" , peer . getNodeName ( ) , "owner" , owner ) ; return ; } LockHandler handler = _locks . get ( lock ) ; if ( handler == null ) { createLockHandler ( peer , lock , false ) ; } else { log . warning ( "Received request to release resolving lock" , "node" , peer . getNodeName ( ) , "handler" , handler ) ; } } | Called when a peer announces its intention to release a lock . |
13,405 | protected void peerAddedLock ( String nodeName , NodeObject . Lock lock ) { if ( _nodeobj . locks . contains ( lock ) ) { log . warning ( "Client hijacked lock owned by this node" , "lock" , lock , "node" , nodeName ) ; droppedLock ( lock ) ; } LockHandler handler = _locks . get ( lock ) ; if ( handler != null ) { handler . peerAddedLock ( nodeName ) ; } } | Called when a peer adds a lock . |
13,406 | protected void peerUpdatedLock ( String nodeName , NodeObject . Lock lock ) { LockHandler handler = _locks . get ( lock ) ; if ( handler != null ) { handler . peerUpdatedLock ( nodeName ) ; } } | Called when a peer updates a lock . |
13,407 | protected byte [ ] flattenAction ( NodeAction action ) { try { ByteArrayOutputStream bout = new ByteArrayOutputStream ( ) ; ObjectOutputStream oout = new ObjectOutputStream ( bout ) ; oout . writeObject ( action ) ; return bout . toByteArray ( ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Failed to serialize node action [action=" + action + "]." , e ) ; } } | Flattens the supplied node action into bytes . |
13,408 | protected byte [ ] flattenRequest ( NodeRequest request ) { try { ByteArrayOutputStream bout = new ByteArrayOutputStream ( ) ; ObjectOutputStream oout = new ObjectOutputStream ( bout ) ; oout . writeObject ( request ) ; return bout . toByteArray ( ) ; } catch ( Exception e ) { throw new IllegalArgumentException ( "Failed to serialize node request [request=" + request + "]." , e ) ; } } | Flattens the supplied node request into bytes . |
13,409 | protected static String propertiesToString ( Properties properties ) { StringWriter stringWriter = new StringWriter ( ) ; String comments = Properties . class . getName ( ) ; try { properties . store ( stringWriter , comments ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } stringWriter . flush ( ) ; String result = stringWriter . toString ( ) ; List < String > lines = new ArrayList < > ( Arrays . asList ( result . split ( "\n" ) ) ) ; lines . remove ( 1 ) ; result = StringUtils . join ( lines , "\n" ) ; return result ; } | Serializes properties to String |
13,410 | public static String setProperty ( ArgumentUnit argumentUnit , String propertyName , String propertyValue ) { Properties properties = ArgumentUnitUtils . getProperties ( argumentUnit ) ; String result = ( String ) properties . setProperty ( propertyName , propertyValue ) ; ArgumentUnitUtils . setProperties ( argumentUnit , properties ) ; return result ; } | Sets the property |
13,411 | public static String getProperty ( ArgumentUnit argumentUnit , String propertyName ) { Properties properties = ArgumentUnitUtils . getProperties ( argumentUnit ) ; return ( String ) properties . get ( propertyName ) ; } | Returns the property value |
13,412 | public static boolean isImplicit ( ArgumentUnit argumentUnit ) throws IllegalStateException { String implicitProperty = ArgumentUnitUtils . getProperty ( argumentUnit , ArgumentUnitUtils . PROP_KEY_IS_IMPLICIT ) ; int length = argumentUnit . getEnd ( ) - argumentUnit . getBegin ( ) ; boolean zeroSize = length == 0 ; if ( implicitProperty != null && Boolean . valueOf ( implicitProperty ) && zeroSize ) { return true ; } if ( implicitProperty == null && ! zeroSize ) { return false ; } throw new IllegalStateException ( "argumentUnit is inconsistent. 'implicit' flag: " + implicitProperty + ", but length: " + length ) ; } | Returns true is the argumentUnit length is 0 and flag is set to implicit . If length is greater than zero and flag is not set to implicit returns false . In any other case throws an exception |
13,413 | public static void setIsImplicit ( ArgumentUnit argumentUnit , boolean implicit ) throws IllegalArgumentException { int length = argumentUnit . getEnd ( ) - argumentUnit . getBegin ( ) ; if ( length > 0 ) { throw new IllegalArgumentException ( "Cannot set 'implicit' property to component " + "with non-zero length (" + length + ")" ) ; } ArgumentUnitUtils . setProperty ( argumentUnit , ArgumentUnitUtils . PROP_KEY_IS_IMPLICIT , Boolean . valueOf ( implicit ) . toString ( ) ) ; } | Sets the implicit value to the argument |
13,414 | public static < E extends DSet . Entry > DSet < E > newDSet ( Iterable < ? extends E > source ) { return new DSet < E > ( source ) ; } | Creates a new DSet of the appropriate generic type . |
13,415 | public void writeObject ( ObjectOutputStream out ) throws IOException { out . writeInt ( _size ) ; for ( int ii = 0 ; ii < _size ; ii ++ ) { out . writeObject ( _entries [ ii ] ) ; } } | Custom writer method . |
13,416 | public void readObject ( ObjectInputStream in ) throws IOException , ClassNotFoundException { _size = in . readInt ( ) ; int capacity = INITIAL_CAPACITY ; while ( capacity < _size ) { capacity <<= 1 ; } @ SuppressWarnings ( "unchecked" ) E [ ] entries = ( E [ ] ) new Entry [ capacity ] ; _entries = entries ; for ( int ii = 0 ; ii < _size ; ii ++ ) { @ SuppressWarnings ( "unchecked" ) E entry = ( E ) in . readObject ( ) ; _entries [ ii ] = entry ; } } | Custom reader method . |
13,417 | public void addTranslation ( String oldname , String newname ) { if ( _translations == null ) { _translations = Maps . newHashMap ( ) ; } _translations . put ( oldname , newname ) ; } | Configures this object input stream with a mapping from an old class name to a new one . Serialized instances of the old class name will use the new class name when unserializing . |
13,418 | public String readIntern ( ) throws IOException { if ( _internmap == null ) { _internmap = Lists . newArrayList ( ) ; _internmap . add ( null ) ; } short code = readShort ( ) ; if ( code == 0 ) { return null ; } else if ( code < 0 ) { code *= - 1 ; String value = readUTF ( ) . intern ( ) ; mapIntern ( code , value ) ; return value ; } else { String value = ( code < _internmap . size ( ) ) ? _internmap . get ( code ) : null ; if ( value == null ) { log . warning ( "Internal stream error, no intern value" , "code" , code , "ois" , this , new Exception ( ) ) ; log . warning ( "ObjectInputStream mappings" , "map" , _internmap ) ; String errmsg = "Read intern code for which we have no registered value " + "metadata [code=" + code + "]" ; throw new RuntimeException ( errmsg ) ; } return value ; } } | Reads a pooled string value from the input stream . |
13,419 | protected ClassMapping readClassMapping ( ) throws IOException , ClassNotFoundException { if ( _classmap == null ) { _classmap = Lists . newArrayList ( ) ; _classmap . add ( null ) ; } short code = readShort ( ) ; if ( code == 0 ) { return null ; } else if ( code < 0 ) { code *= - 1 ; String cname = readUTF ( ) ; if ( _translations != null ) { String tname = _translations . get ( cname ) ; if ( tname != null ) { cname = tname ; } } return mapClass ( code , cname ) ; } else { ClassMapping cmap = ( code < _classmap . size ( ) ) ? _classmap . get ( code ) : null ; if ( cmap == null ) { log . warning ( "Internal stream error, no class metadata" , "code" , code , "ois" , this , new Exception ( ) ) ; log . warning ( "ObjectInputStream mappings" , "map" , _classmap ) ; String errmsg = "Read object code for which we have no registered class " + "metadata [code=" + code + "]" ; throw new RuntimeException ( errmsg ) ; } return cmap ; } } | Reads a class mapping from the stream . |
13,420 | protected ClassMapping mapClass ( short code , String cname ) throws IOException , ClassNotFoundException { ClassMapping cmap = createClassMapping ( code , cname ) ; _classmap . add ( code , cmap ) ; return cmap ; } | Creates adds and returns the class mapping for the specified code and class name . |
13,421 | protected ClassMapping createClassMapping ( short code , String cname ) throws IOException , ClassNotFoundException { ClassLoader loader = ( _loader != null ) ? _loader : Thread . currentThread ( ) . getContextClassLoader ( ) ; Class < ? > sclass = Class . forName ( cname , true , loader ) ; Streamer streamer = Streamer . getStreamer ( sclass ) ; if ( STREAM_DEBUG ) { log . info ( hashCode ( ) + ": New class '" + cname + "'" , "code" , code ) ; } if ( streamer == null ) { String errmsg = "Aiya! Unable to create streamer for newly seen class " + "[code=" + code + ", class=" + cname + "]" ; throw new RuntimeException ( errmsg ) ; } return new ClassMapping ( code , sclass , streamer ) ; } | Creates and returns a class mapping for the specified code and class name . |
13,422 | public boolean gotPong ( PongResponse pong ) { if ( _ping == null ) { return false ; } if ( _iter >= _deltas . length ) { return true ; } long send = _ping . getPackStamp ( ) , recv = pong . getUnpackStamp ( ) ; _ping = null ; long server = pong . getPackStamp ( ) , delay = pong . getProcessDelay ( ) ; long nettime = ( recv - send - delay ) / 2 ; _deltas [ _iter ] = recv - ( server + nettime ) ; log . debug ( "Calculated delta" , "delay" , delay , "nettime" , nettime , "delta" , _deltas [ _iter ] , "rtt" , ( recv - send ) ) ; return ( ++ _iter >= CLOCK_SYNC_PING_COUNT ) ; } | Must be called when the pong response arrives back from the server . |
13,423 | public void subscribe ( DObjectManager omgr ) { if ( _active ) { log . warning ( "Active safesub asked to resubscribe " + this + "." , new Exception ( ) ) ; return ; } _active = true ; if ( _object != null ) { log . warning ( "Incroyable! A safesub has an object and was " + "non-active!? " + this + "." , new Exception ( ) ) ; _subscriber . objectAvailable ( _object ) ; return ; } if ( _pending ) { return ; } _pending = true ; omgr . subscribeToObject ( _oid , this ) ; } | Initiates the subscription process . |
13,424 | public void unsubscribe ( DObjectManager omgr ) { if ( ! _active ) { if ( _object == null && ! _pending ) { return ; } log . warning ( "Inactive safesub asked to unsubscribe " + this + "." , new Exception ( ) ) ; } _active = false ; if ( _pending ) { if ( _object != null ) { log . warning ( "Incroyable! A safesub has an object and is " + "pending!? " + this + "." , new Exception ( ) ) ; } else { return ; } } if ( _object == null ) { log . warning ( "Zut alors! A safesub _was_ active and not " + "pending yet has no object!? " + this + "." , new Exception ( ) ) ; return ; } for ( ChangeListener listener : _listeners ) { _object . removeListener ( listener ) ; } _object = null ; omgr . unsubscribeFromObject ( _oid , this ) ; } | Terminates the object subscription . If the initial subscription has not yet completed the desire to terminate will be noted and the subscription will be terminated as soon as it completes . |
13,425 | public void clear ( final Name username ) { if ( _holds . contains ( username ) ) { _holds . remove ( username ) ; _omgr . postRunnable ( new Runnable ( ) { public void run ( ) { clear ( username ) ; } } ) ; return ; } _histories . remove ( username ) ; } | Clears the chat history for the specified user . |
13,426 | protected void prune ( long now , List < Entry > history ) { int prunepos = 0 ; for ( int ll = history . size ( ) ; prunepos < ll ; prunepos ++ ) { Entry entry = history . get ( prunepos ) ; if ( now - entry . message . timestamp < HISTORY_EXPIRATION ) { break ; } } history . subList ( 0 , prunepos ) . clear ( ) ; } | Prunes all messages from this history which are expired . |
13,427 | protected void reportSuccess ( ) { for ( int ii = 0 , ll = _listeners . size ( ) ; ii < ll ; ii ++ ) { ClientResolutionListener crl = _listeners . get ( ii ) ; try { _clobj . reference ( ) ; crl . clientResolved ( _username , _clobj ) ; } catch ( Exception e ) { log . warning ( "Client resolution listener choked in clientResolved() " + crl , e ) ; } } } | Reports success to our resolution listeners . |
13,428 | protected void reportFailure ( Exception cause ) { for ( int ii = 0 , ll = _listeners . size ( ) ; ii < ll ; ii ++ ) { ClientResolutionListener crl = _listeners . get ( ii ) ; try { crl . resolutionFailed ( _username , cause ) ; } catch ( Exception e ) { log . warning ( "Client resolution listener choked in resolutionFailed()" , "crl" , crl , "username" , _username , "cause" , cause , e ) ; } } } | Reports failure to our resolution listeners . |
13,429 | public MarcContentHandler setMarcListener ( String type , MarcListener listener ) { this . listeners . put ( type , listener ) ; return this ; } | Set MARC listener for a specific record type . |
13,430 | public boolean moveTo ( int placeId ) { if ( placeId < 0 ) { log . warning ( "Refusing moveTo(): invalid placeId " + placeId + "." ) ; return false ; } if ( ! mayMoveTo ( placeId , null ) ) { return false ; } boolean refuse = checkRepeatMove ( ) ; if ( _pendingPlaceId != - 1 ) { if ( refuse ) { log . warning ( "Refusing moveTo; We have a request outstanding" , "ppid" , _pendingPlaceId , "npid" , placeId ) ; return false ; } else { log . warning ( "Overriding stale moveTo request" , "ppid" , _pendingPlaceId , "npid" , placeId ) ; } } _pendingPlaceId = placeId ; log . info ( "Issuing moveTo(" + placeId + ")." ) ; _lservice . moveTo ( placeId , new LocationService . MoveListener ( ) { public void moveSucceeded ( PlaceConfig config ) { didMoveTo ( _pendingPlaceId , config ) ; _pendingPlaceId = - 1 ; handlePendingForcedMove ( ) ; } public void requestFailed ( String reason ) { int placeId = _pendingPlaceId ; _pendingPlaceId = - 1 ; log . info ( "moveTo failed" , "pid" , placeId , "reason" , reason ) ; handleFailure ( placeId , reason ) ; handlePendingForcedMove ( ) ; } } ) ; return true ; } | Requests that this client be moved to the specified place . A request will be made and when the response is received the location observers will be notified of success or failure . |
13,431 | public boolean leavePlace ( ) { if ( _pendingPlaceId != - 1 ) { return false ; } _lservice . leavePlace ( ) ; didLeavePlace ( ) ; _observers . apply ( _didChangeOp ) ; return true ; } | Issues a request to leave our current location . |
13,432 | public boolean mayMoveTo ( final int placeId , ResultListener < PlaceConfig > rl ) { final boolean [ ] vetoed = new boolean [ 1 ] ; _observers . apply ( new ObserverOp < LocationObserver > ( ) { public boolean apply ( LocationObserver obs ) { vetoed [ 0 ] = ( vetoed [ 0 ] || ! obs . locationMayChange ( placeId ) ) ; return true ; } } ) ; mayLeavePlace ( ) ; if ( rl != null ) { if ( vetoed [ 0 ] ) { rl . requestFailed ( new MoveVetoedException ( ) ) ; } else { _moveListener = rl ; } } return ! vetoed [ 0 ] ; } | This can be called by cooperating directors that need to coopt the moving process to extend it in some way or other . In such situations they should call this method before moving to a new location to check to be sure that all of the registered location observers are amenable to a location change . |
13,433 | protected void mayLeavePlace ( ) { if ( _controller != null ) { try { _controller . mayLeavePlace ( _plobj ) ; } catch ( Exception e ) { log . warning ( "Place controller choked in mayLeavePlace" , "plobj" , _plobj , e ) ; } } } | Called to inform our controller that we may be leaving the current place . |
13,434 | public void didMoveTo ( int placeId , PlaceConfig config ) { if ( _moveListener != null ) { _moveListener . requestCompleted ( config ) ; _moveListener = null ; } _previousPlaceId = _placeId ; _lastRequestTime = 0 ; didLeavePlace ( ) ; _placeId = placeId ; try { _controller = createController ( config ) ; if ( _controller == null ) { log . warning ( "Place config returned null controller" , "config" , config ) ; return ; } _controller . init ( _ctx , config ) ; subscribeToPlace ( ) ; } catch ( Exception e ) { log . warning ( "Failed to create place controller" , "config" , config , e ) ; handleFailure ( _placeId , LocationCodes . E_INTERNAL_ERROR ) ; } } | This can be called by cooperating directors that need to coopt the moving process to extend it in some way or other . In such situations they will be responsible for receiving the successful move response and they should let the location director know that the move has been effected . |
13,435 | public void didLeavePlace ( ) { if ( _subber != null ) { _subber . unsubscribe ( _ctx . getDObjectManager ( ) ) ; _subber = null ; } if ( _plobj != null && _controller != null ) { try { _controller . didLeavePlace ( _plobj ) ; } catch ( Exception e ) { log . warning ( "Place controller choked in didLeavePlace" , "plobj" , _plobj , e ) ; } } _plobj = null ; _controller = null ; _placeId = - 1 ; } | Called when we re leaving our current location . Informs the location s controller that we re departing unsubscribes from the location s place object and clears out our internal place information . |
13,436 | public void failedToMoveTo ( int placeId , String reason ) { if ( _moveListener != null ) { _moveListener . requestFailed ( new MoveFailedException ( reason ) ) ; _moveListener = null ; } _lastRequestTime = 0 ; handleFailure ( placeId , reason ) ; } | This can be called by cooperating directors that need to coopt the moving process to extend it in some way or other . If the coopted move request fails this failure can be propagated to the location observers if appropriate . |
13,437 | public boolean checkRepeatMove ( ) { long now = System . currentTimeMillis ( ) ; if ( now - _lastRequestTime < STALE_REQUEST_DURATION ) { return true ; } else { _lastRequestTime = now ; return false ; } } | Called to test and set a time stamp that we use to determine if a pending moveTo request is stale . |
13,438 | public void setFailureHandler ( FailureHandler handler ) { if ( _failureHandler != null ) { log . warning ( "Requested to set failure handler, but we've already got one. The " + "conflicting entities will likely need to perform more sophisticated " + "coordination to deal with failures." , "old" , _failureHandler , "new" , handler ) ; } else { _failureHandler = handler ; } } | Sets the failure handler which will recover from place object fetching failures . In the event that we are unable to fetch our place object after making a successful moveTo request we attempt to rectify the failure by moving back to the last known working location . Because entites that cooperate with the location director may need to become involved in this failure recovery we provide this interface whereby they can interject themseves into the failure recovery process and do their own failure recovery . |
13,439 | public void removeGlobals ( ) { Iterator < String > i = _imports . iterator ( ) ; while ( i . hasNext ( ) ) { String name = i . next ( ) ; if ( name . indexOf ( '.' ) == - 1 ) { i . remove ( ) ; } else if ( name . startsWith ( "java.lang" ) ) { i . remove ( ) ; } } } | Gets rid of primitive and java . lang imports . |
13,440 | public void removeSamePackage ( String pkg ) { Iterator < String > i = _imports . iterator ( ) ; while ( i . hasNext ( ) ) { String name = i . next ( ) ; if ( name . startsWith ( pkg ) && name . indexOf ( '.' , pkg . length ( ) + 1 ) == - 1 ) { i . remove ( ) ; } } } | Remove all classes that are in the same package . |
13,441 | public void translateClassArrays ( ) { ImportSet arrayTypes = new ImportSet ( ) ; Iterator < String > i = _imports . iterator ( ) ; while ( i . hasNext ( ) ) { String name = i . next ( ) ; int bracket = name . lastIndexOf ( '[' ) ; if ( bracket != - 1 && name . charAt ( bracket + 1 ) == 'L' ) { arrayTypes . add ( name . substring ( bracket + 2 , name . length ( ) - 1 ) ) ; } } addAll ( arrayTypes ) ; } | Inserts imports for the non - primitive classes contained in all array imports . |
13,442 | public void popIn ( ) { String front = _pushed . remove ( _pushed . size ( ) - 1 ) ; if ( front != null ) { _imports . add ( front ) ; } } | Re - adds the most recently popped import to the set . If a null value was pushed does nothing . |
13,443 | public void replace ( String ... replace ) { HashSet < String > toAdd = Sets . newHashSet ( ) ; Iterator < String > i = _imports . iterator ( ) ; while ( i . hasNext ( ) ) { String name = i . next ( ) ; for ( int j = 0 ; j < replace . length ; j += 2 ) { if ( name . equals ( replace [ j ] ) ) { toAdd . add ( replace [ j + 1 ] ) ; i . remove ( ) ; break ; } } } _imports . addAll ( toAdd ) ; } | Replaces any import exactly each find string with the corresponding replace string . See the description above . |
13,444 | public int removeAll ( String pattern ) { Pattern pat = makePattern ( pattern ) ; int removed = 0 ; Iterator < String > i = _imports . iterator ( ) ; while ( i . hasNext ( ) ) { String name = i . next ( ) ; if ( pat . matcher ( name ) . matches ( ) ) { i . remove ( ) ; ++ removed ; } } return removed ; } | Remove all imports matching the given pattern . |
13,445 | public List < List < String > > toGroups ( ) { List < String > list = Lists . newArrayList ( _imports ) ; Collections . sort ( list , new Comparator < String > ( ) { public int compare ( String class1 , String class2 ) { return ComparisonChain . start ( ) . compare ( findImportGroup ( class1 ) , findImportGroup ( class2 ) ) . compare ( class1 , class2 ) . result ( ) ; } } ) ; List < List < String > > result = Lists . newArrayList ( ) ; List < String > current = null ; int lastGroup = - 2 ; for ( String imp : list ) { int group = findImportGroup ( imp ) ; if ( group != lastGroup ) { if ( current == null || ! current . isEmpty ( ) ) { result . add ( current = Lists . < String > newArrayList ( ) ) ; } lastGroup = group ; } current . add ( imp ) ; } return result ; } | Converts the set of imports to groups of class names according to conventional package ordering and spacing . Within each group sorting is alphabetical . |
13,446 | public List < String > toList ( ) { ComparableArrayList < String > list = new ComparableArrayList < String > ( ) ; list . addAll ( _imports ) ; list . sort ( ) ; return list ; } | Convert the set of imports to a sorted list ready to be output to a generated file . |
13,447 | protected int findImportGroup ( String imp ) { int bestGroup = - 1 ; int bestPrefixLength = - 1 ; int ii = - 1 ; for ( String prefix : getImportGroups ( ) ) { ii ++ ; if ( ! imp . startsWith ( prefix ) ) { continue ; } if ( prefix . length ( ) > bestPrefixLength ) { bestPrefixLength = prefix . length ( ) ; bestGroup = ii ; } } return bestGroup ; } | Find the index of the best import group to use for the specified import . |
13,448 | protected static Pattern makePattern ( String input ) { StringBuilder pattern = new StringBuilder ( '^' ) ; while ( true ) { String [ ] parts = _splitter . split ( input , 2 ) ; pattern . append ( Pattern . quote ( parts [ 0 ] ) ) ; if ( parts . length == 1 ) { break ; } int length = parts [ 0 ] . length ( ) ; String wildcard = input . substring ( length , length + 1 ) ; if ( wildcard . equals ( "*" ) ) { pattern . append ( ".*" ) ; } else { System . err . println ( "Bad wildcard " + wildcard ) ; } input = parts [ 1 ] ; } pattern . append ( "$" ) ; return Pattern . compile ( pattern . toString ( ) ) ; } | Create a real regular expression from the dumbed down input . |
13,449 | public static Method getMethod ( String name , Object target , Map < String , Method > cache ) { Class < ? > tclass = target . getClass ( ) ; String key = tclass . getName ( ) + ":" + name ; Method method = cache . get ( key ) ; if ( method == null ) { method = findMethod ( tclass , name ) ; if ( method != null ) { cache . put ( key , method ) ; } } return method ; } | Locates and returns the first method in the supplied class whose name is equal to the specified name . If a method is located it will be cached in the supplied cache so that subsequent requests will immediately return the method from the cache rather than re - reflecting . |
13,450 | public static Method getMethod ( String name , Object target , Object [ ] args ) { Class < ? > tclass = target . getClass ( ) ; Method meth = null ; try { MethodFinder finder = new MethodFinder ( tclass ) ; meth = finder . findMethod ( name , args ) ; } catch ( NoSuchMethodException nsme ) { log . info ( "No such method" , "name" , name , "tclass" , tclass . getName ( ) , "args" , args , "error" , nsme ) ; } catch ( SecurityException se ) { log . warning ( "Unable to look up method?" , "tclass" , tclass . getName ( ) , "mname" , name ) ; } return meth ; } | Looks up the method on the specified object that has a signature that matches the supplied arguments array . This is very expensive so you shouldn t be doing this for something that happens frequently . |
13,451 | public static Method findMethod ( Class < ? > clazz , String name ) { Method [ ] methods = clazz . getMethods ( ) ; for ( Method method : methods ) { if ( method . getName ( ) . equals ( name ) ) { return method ; } } return null ; } | Locates and returns the first method in the supplied class whose name is equal to the specified name . |
13,452 | public void authenticateConnection ( Invoker invoker , final AuthingConnection conn , final ResultListener < AuthingConnection > onComplete ) { final AuthRequest req = conn . getAuthRequest ( ) ; final AuthResponseData rdata = createResponseData ( ) ; final AuthResponse rsp = new AuthResponse ( rdata ) ; invoker . postUnit ( new Invoker . Unit ( "authenticateConnection" ) { public boolean invoke ( ) { try { processAuthentication ( conn , rsp ) ; if ( AuthResponseData . SUCCESS . equals ( rdata . code ) && conn . getAuthName ( ) == null ) { throw new IllegalStateException ( "Authenticator failed to provide authname" ) ; } } catch ( AuthException e ) { rdata . code = e . getMessage ( ) ; } catch ( Exception e ) { log . warning ( "Error authenticating user" , "areq" , req , e ) ; rdata . code = AuthCodes . SERVER_ERROR ; } return true ; } public void handleResult ( ) { conn . setAuthResponse ( rsp ) ; conn . postMessage ( rsp ) ; if ( AuthResponseData . SUCCESS . equals ( rdata . code ) ) { onComplete . requestCompleted ( conn ) ; } } } ) ; } | Called by the connection management code when an authenticating connection has received its authentication request from the client . |
13,453 | public int append ( int newByte ) { int old = buffer2 [ pos ] ; buffer2 [ pos ] = newByte ; buffer [ pos ] = cs ? ( char ) newByte : Character . toLowerCase ( ( char ) newByte ) ; pos = ( ++ pos < buffer . length ) ? pos : 0 ; return old ; } | Append byte . |
13,454 | public boolean hasData ( ) { int apos = token . length - 1 ; int rpos = pos - 1 ; for ( ; rpos > - 1 && apos > - 1 ; rpos -- , apos -- ) { if ( buffer2 [ rpos ] != - 1 ) { return true ; } } for ( rpos = buffer2 . length - 1 ; apos > - 1 ; rpos -- , apos -- ) { if ( buffer2 [ rpos ] != - 1 ) { return true ; } } return false ; } | Has scan buffer any data? |
13,455 | public void clear ( int i ) { char ch = ( char ) - 1 ; int apos = i - 1 ; int rpos = pos - 1 ; for ( ; rpos > - 1 && apos > - 1 ; rpos -- , apos -- ) { buffer [ rpos ] = ch ; buffer2 [ rpos ] = - 1 ; } for ( rpos = buffer . length - 1 ; apos > - 1 ; rpos -- , apos -- ) { buffer [ rpos ] = ch ; buffer2 [ rpos ] = - 1 ; } } | Clear scan buffer at position . |
13,456 | public void moveTo ( int arg1 , LocationService . MoveListener arg2 ) { LocationMarshaller . MoveMarshaller listener2 = new LocationMarshaller . MoveMarshaller ( ) ; listener2 . listener = arg2 ; sendRequest ( MOVE_TO , new Object [ ] { Integer . valueOf ( arg1 ) , listener2 } ) ; } | from interface LocationService |
13,457 | public void speak ( ClientObject caller , String message , byte mode ) { BodyObject source = ( _locator != null ) ? _locator . forClient ( caller ) : ( BodyObject ) caller ; String errmsg = source . checkAccess ( ChatCodes . CHAT_ACCESS , null ) ; if ( errmsg != null ) { SpeakUtil . sendFeedback ( source , MessageManager . GLOBAL_BUNDLE , errmsg ) ; return ; } if ( ( mode == ChatCodes . BROADCAST_MODE ) || ( _validator != null && ! _validator . isValidSpeaker ( _speakObj , source , mode ) ) ) { log . warning ( "Refusing invalid speak request" , "source" , source . who ( ) , "speakObj" , _speakObj . which ( ) , "message" , message , "mode" , mode ) ; } else { sendSpeak ( source , message , mode ) ; } } | from interface SpeakProvider |
13,458 | protected void sendSpeak ( BodyObject source , String message , byte mode ) { SpeakUtil . sendSpeak ( _speakObj , source . getVisibleName ( ) , null , message , mode ) ; } | Sends the actual speak message . |
13,459 | protected ArgumentComponent selectMainArgumentComponent ( List < ArgumentComponent > argumentComponents ) { ArgumentComponent result = null ; int maxLength = Integer . MIN_VALUE ; for ( ArgumentComponent argumentComponent : argumentComponents ) { int length = argumentComponent . getEnd ( ) - argumentComponent . getBegin ( ) ; if ( length > maxLength ) { maxLength = length ; result = argumentComponent ; } } if ( result == null ) { throw new IllegalStateException ( "Couldn't find maximum arg. component" ) ; } return result ; } | Selects the main argument component from a list of components that are present in the sentence ; currently the longest |
13,460 | public static void requireAccess ( ClientObject clobj , Permission perm , Object context ) throws InvocationException { String errmsg = clobj . checkAccess ( perm , context ) ; if ( errmsg != null ) { throw new InvocationException ( errmsg ) ; } } | Requires that the specified client have the specified permissions . |
13,461 | public void writeTo ( ObjectOutputStream out ) throws IOException { out . writeShort ( _mask . length ) ; out . write ( _mask ) ; } | Writes this mask to the specified output stream . |
13,462 | public void readFrom ( ObjectInputStream in ) throws IOException { int length = in . readShort ( ) ; _mask = new byte [ length ] ; in . read ( _mask ) ; } | Reads this mask from the specified input stream . |
13,463 | public void init ( ConnectionManager cmgr , SocketChannel channel , long createStamp ) throws IOException { _cmgr = cmgr ; _channel = channel ; _lastEvent = createStamp ; _connectionId = ++ _lastConnectionId ; } | Initializes a connection object with a socket and related info . |
13,464 | public void networkFailure ( IOException ioe ) { if ( isClosed ( ) ) { log . warning ( "Failure reported on closed connection " + this + "." , new Exception ( ) ) ; return ; } _cmgr . connectionFailed ( this , ioe ) ; closeSocket ( ) ; } | Called when there is a failure reading or writing to this connection . We notify the connection manager and close ourselves down . |
13,465 | public boolean checkIdle ( long idleStamp ) { if ( _lastEvent > idleStamp ) { return false ; } if ( ! isClosed ( ) ) { log . info ( "Disconnecting non-communicative client" , "conn" , this , "idle" , ( System . currentTimeMillis ( ) - _lastEvent ) + "ms" ) ; } return true ; } | from interface NetEventHandler |
13,466 | protected void closeSocket ( ) { if ( _channel == null ) { return ; } log . debug ( "Closing channel " + this + "." ) ; try { _channel . close ( ) ; } catch ( IOException ioe ) { log . warning ( "Error closing connection" , "conn" , this , "error" , ioe ) ; } _channel = null ; } | Closes the socket associated with this connection . This happens when we receive EOF are requested to close down or when our connection fails . |
13,467 | public String checkToken ( BureauCredentials creds ) { Bureau bureau = _bureaus . get ( creds . clientId ) ; if ( bureau == null ) { return "Bureau " + creds . clientId + " not found" ; } if ( bureau . clientObj != null ) { return "Bureau " + creds . clientId + " already logged in" ; } if ( ! creds . areValid ( bureau . token ) ) { return "Bureau " + creds . clientId + " does not match credentials token" ; } return null ; } | Check the credentials to make sure this is one of our bureaus . |
13,468 | public void startAgent ( AgentObject agent ) { agent . setLocal ( AgentData . class , new AgentData ( ) ) ; Bureau bureau = _bureaus . get ( agent . bureauId ) ; if ( bureau != null && bureau . ready ( ) ) { _omgr . registerObject ( agent ) ; log . info ( "Bureau ready, sending createAgent" , "agent" , agent . which ( ) ) ; BureauSender . createAgent ( bureau . clientObj , agent . getOid ( ) ) ; bureau . agentStates . put ( agent , AgentState . STARTED ) ; bureau . summarize ( ) ; return ; } if ( bureau == null ) { LauncherEntry launcherEntry = _launchers . get ( agent . bureauType ) ; if ( launcherEntry == null ) { log . warning ( "Launcher not found" , "agent" , agent . which ( ) ) ; return ; } log . info ( "Creating new bureau" , "bureauId" , agent . bureauId , "launcher" , launcherEntry ) ; bureau = new Bureau ( ) ; bureau . bureauId = agent . bureauId ; bureau . token = generateToken ( bureau . bureauId ) ; bureau . launcherEntry = launcherEntry ; _invoker . postUnit ( new LauncherUnit ( bureau , _omgr ) ) ; _bureaus . put ( agent . bureauId , bureau ) ; } _omgr . registerObject ( agent ) ; bureau . agentStates . put ( agent , AgentState . PENDING ) ; log . info ( "Bureau not ready, pending agent" , "agent" , agent . which ( ) ) ; bureau . summarize ( ) ; } | Starts a new agent using the data in the given object creating a new bureau if necessary . |
13,469 | public void destroyAgent ( AgentObject agent ) { FoundAgent found = resolve ( null , agent . getOid ( ) , "destroyAgent" ) ; if ( found == null ) { return ; } log . info ( "Destroying agent" , "agent" , agent . which ( ) ) ; if ( found . state == AgentState . PENDING ) { found . bureau . agentStates . remove ( found . agent ) ; _omgr . destroyObject ( found . agent . getOid ( ) ) ; } else if ( found . state == AgentState . STARTED ) { found . bureau . agentStates . put ( found . agent , AgentState . STILL_BORN ) ; } else if ( found . state == AgentState . RUNNING ) { BureauSender . destroyAgent ( found . bureau . clientObj , agent . getOid ( ) ) ; found . bureau . agentStates . put ( found . agent , AgentState . DESTROYED ) ; } else if ( found . state == AgentState . DESTROYED || found . state == AgentState . STILL_BORN ) { log . warning ( "Ignoring request to destroy agent in unexpected state" , "state" , found . state , "agent" , found . agent . which ( ) ) ; } found . bureau . summarize ( ) ; } | Destroys a previously started agent using the data in the given object . |
13,470 | public PresentsSession lookupClient ( String bureauId ) { Bureau bureau = _bureaus . get ( bureauId ) ; if ( bureau == null ) { return null ; } return bureau . client ; } | Returns the active session for a bureau of the given id . |
13,471 | public Exception getLaunchError ( AgentObject agentObj ) { AgentData data = agentObj . getLocal ( AgentData . class ) ; if ( data == null ) { return null ; } return data . launchError ; } | If this agent s bureau encountered an error on launch return it . |
13,472 | protected void bureauInitialized ( ClientObject client , String bureauId ) { final Bureau bureau = _bureaus . get ( bureauId ) ; if ( bureau == null ) { log . warning ( "Initialization of non-existent bureau" , "bureauId" , bureauId ) ; return ; } bureau . clientObj = client ; log . info ( "Bureau created, launching pending agents" , "bureau" , bureau ) ; Set < AgentObject > pending = Sets . newHashSet ( ) ; for ( Map . Entry < AgentObject , AgentState > entry : bureau . agentStates . entrySet ( ) ) { if ( entry . getValue ( ) == AgentState . PENDING ) { pending . add ( entry . getKey ( ) ) ; } } for ( AgentObject agent : pending ) { log . info ( "Creating agent" , "agent" , agent . which ( ) ) ; BureauSender . createAgent ( bureau . clientObj , agent . getOid ( ) ) ; bureau . agentStates . put ( agent , AgentState . STARTED ) ; } bureau . summarize ( ) ; } | Callback for when the bureau client acknowledges starting up . Starts all pending agents and causes subsequent agent start requests to be sent directly to the bureau . |
13,473 | protected void agentCreated ( ClientObject client , int agentId ) { FoundAgent found = resolve ( client , agentId , "agentCreated" ) ; if ( found == null ) { return ; } log . info ( "Agent creation confirmed" , "agent" , found . agent . which ( ) ) ; if ( found . state == AgentState . STARTED ) { found . bureau . agentStates . put ( found . agent , AgentState . RUNNING ) ; found . agent . setClientOid ( client . getOid ( ) ) ; } else if ( found . state == AgentState . STILL_BORN ) { BureauSender . destroyAgent ( found . bureau . clientObj , agentId ) ; found . bureau . agentStates . put ( found . agent , AgentState . DESTROYED ) ; } else if ( found . state == AgentState . PENDING || found . state == AgentState . RUNNING || found . state == AgentState . DESTROYED ) { log . warning ( "Ignoring confirmation of creation of an agent in an unexpected state" , "state" , found . state , "agent" , found . agent . which ( ) ) ; } found . bureau . summarize ( ) ; } | Callback for when the bureau client acknowledges the creation of an agent . |
13,474 | protected void agentCreationFailed ( ClientObject client , int agentId ) { FoundAgent found = resolve ( client , agentId , "agentCreationFailed" ) ; if ( found == null ) { return ; } log . info ( "Agent creation failed" , "agent" , found . agent . which ( ) ) ; if ( found . state == AgentState . STARTED || found . state == AgentState . STILL_BORN ) { found . bureau . agentStates . remove ( found . agent ) ; _omgr . destroyObject ( found . agent . getOid ( ) ) ; } else if ( found . state == AgentState . PENDING || found . state == AgentState . RUNNING || found . state == AgentState . DESTROYED ) { log . warning ( "Ignoring failure of creation of an agent in an unexpected state" , "state" , found . state , "agent" , found . agent . which ( ) ) ; } found . bureau . summarize ( ) ; } | Callback for when the bureau client acknowledges the failure to create an agent . |
13,475 | protected void clientDestroyed ( Bureau bureau ) { log . info ( "Client destroyed, destroying all agents" , "bureau" , bureau ) ; for ( AgentObject agent : bureau . agentStates . keySet ( ) ) { _omgr . destroyObject ( agent . getOid ( ) ) ; } bureau . agentStates . clear ( ) ; if ( _bureaus . remove ( bureau . bureauId ) == null ) { log . info ( "Bureau not found to remove" , "bureau" , bureau ) ; } } | Callback for when a client is destroyed . |
13,476 | protected FoundAgent resolve ( ClientObject client , int agentId , String resolver ) { com . threerings . presents . dobj . DObject dobj = _omgr . getObject ( agentId ) ; if ( dobj == null ) { log . warning ( "Non-existent agent" , "function" , resolver , "agentId" , agentId ) ; return null ; } if ( ! ( dobj instanceof AgentObject ) ) { log . warning ( "Object not an agent" , "function" , resolver , "obj" , dobj . getClass ( ) ) ; return null ; } AgentObject agent = ( AgentObject ) dobj ; Bureau bureau = _bureaus . get ( agent . bureauId ) ; if ( bureau == null ) { log . warning ( "Bureau not found for agent" , "function" , resolver , "agent" , agent . which ( ) ) ; return null ; } if ( ! bureau . agentStates . containsKey ( agent ) ) { log . warning ( "Bureau does not have agent" , "function" , resolver , "agent" , agent . which ( ) ) ; return null ; } if ( client != null && bureau . clientObj != client ) { log . warning ( "Masquerading request" , "function" , resolver , "agent" , agent . which ( ) , "client" , bureau . clientObj , "client" , client ) ; return null ; } return new FoundAgent ( bureau , agent , bureau . agentStates . get ( agent ) ) ; } | Does lots of null checks and lookups and resolves the given information into FoundAgent . |
13,477 | protected String generateToken ( String bureauId ) { String tokenSource = bureauId + "@" + System . currentTimeMillis ( ) + "r" + Math . random ( ) ; return StringUtil . md5hex ( tokenSource ) ; } | Create a hard - to - guess token that the bureau can use to authenticate itself when it tries to log in . |
13,478 | protected void launchTimeoutExpired ( Bureau bureau ) { if ( bureau . clientObj != null ) { return ; } if ( ! _bureaus . containsKey ( bureau . bureauId ) ) { return ; } handleLaunchError ( bureau , null , "timeout" ) ; } | Called by the launcher unit timeout time after launching . |
13,479 | protected void handleLaunchError ( Bureau bureau , Exception error , String cause ) { if ( cause == null && error != null ) { cause = error . getMessage ( ) ; } log . info ( "Bureau failed to launch" , "bureau" , bureau , "cause" , cause ) ; for ( AgentObject agent : bureau . agentStates . keySet ( ) ) { agent . getLocal ( AgentData . class ) . launchError = error ; _omgr . destroyObject ( agent . getOid ( ) ) ; } bureau . agentStates . clear ( ) ; _bureaus . remove ( bureau . bureauId ) ; } | Called when something goes wrong with launching a bureau . |
13,480 | public void gotConfigInfo ( final String [ ] keys , final int [ ] oids ) { if ( ! isDisplayable ( ) ) { return ; } Integer indexes [ ] = new Integer [ keys . length ] ; for ( int ii = 0 ; ii < indexes . length ; ii ++ ) { indexes [ ii ] = ii ; } QuickSort . sort ( indexes , new Comparator < Integer > ( ) { public int compare ( Integer i1 , Integer i2 ) { return keys [ i1 ] . compareTo ( keys [ i2 ] ) ; } } ) ; for ( Integer ii : indexes ) { ObjectEditorPanel panel = new ObjectEditorPanel ( _ctx , keys [ ii ] , oids [ ii ] ) ; JScrollPane scrolly = new JScrollPane ( panel ) ; _oeditors . addTab ( keys [ ii ] , scrolly ) ; if ( keys [ ii ] . equals ( _defaultPane ) ) { _oeditors . setSelectedComponent ( scrolly ) ; } } } | Called in response to our getConfigInfo server - side service request . |
13,481 | public Chunk < byte [ ] , BytesReference > readChunk ( ) throws IOException { Chunk < byte [ ] , BytesReference > chunk = internalReadChunk ( ) ; if ( chunk != null ) { processChunk ( chunk ) ; } return chunk ; } | Read next chunk from this stream . |
13,482 | public boolean addChatterObserver ( ChatterObserver co ) { boolean added = _chatterObservers . add ( co ) ; co . chattersUpdated ( _chatters . listIterator ( ) ) ; return added ; } | Adds an observer that watches the chatters list and updates it immediately . |
13,483 | public void registerCommandHandler ( MessageBundle msg , String command , CommandHandler handler ) { handler . _usageKey = "m.usage_" + command ; String key = "c." + command ; handler . _aliases = msg . exists ( key ) ? msg . get ( key ) . split ( "\\s+" ) : new String [ ] { command } ; for ( String alias : handler . _aliases ) { _handlers . put ( alias , handler ) ; } } | Registers a chat command handler . |
13,484 | public void clearDisplays ( ) { _displays . apply ( new ObserverList . ObserverOp < ChatDisplay > ( ) { public boolean apply ( ChatDisplay observer ) { observer . clear ( ) ; return true ; } } ) ; } | Requests that all chat displays clear their contents . |
13,485 | public void displayInfo ( String bundle , String message ) { displaySystem ( bundle , message , SystemMessage . INFO , PLACE_CHAT_TYPE ) ; } | Display a system INFO message as if it had come from the server . The localtype of the message will be PLACE_CHAT_TYPE . |
13,486 | public void displayInfo ( String bundle , String message , String localtype ) { displaySystem ( bundle , message , SystemMessage . INFO , localtype ) ; } | Display a system INFO message as if it had come from the server . |
13,487 | public void displayFeedback ( String bundle , String message ) { displaySystem ( bundle , message , SystemMessage . FEEDBACK , PLACE_CHAT_TYPE ) ; } | Display a system FEEDBACK message as if it had come from the server . The localtype of the message will be PLACE_CHAT_TYPE . |
13,488 | public void displayAttention ( String bundle , String message ) { displaySystem ( bundle , message , SystemMessage . ATTENTION , PLACE_CHAT_TYPE ) ; } | Display a system ATTENTION message as if it had come from the server . The localtype of the message will be PLACE_CHAT_TYPE . |
13,489 | public void dispatchMessage ( ChatMessage message , String localType ) { setClientInfo ( message , localType ) ; dispatchPreparedMessage ( message ) ; } | Dispatches the provided message to our chat displays . |
13,490 | public String requestChat ( SpeakService speakSvc , String text , boolean record ) { if ( text . startsWith ( "/" ) ) { String command = text . substring ( 1 ) . toLowerCase ( ) ; String [ ] hist = new String [ 1 ] ; String args = "" ; int sidx = text . indexOf ( " " ) ; if ( sidx != - 1 ) { command = text . substring ( 1 , sidx ) . toLowerCase ( ) ; args = text . substring ( sidx + 1 ) . trim ( ) ; } Map < String , CommandHandler > possibleCommands = getCommandHandlers ( command ) ; switch ( possibleCommands . size ( ) ) { case 0 : StringTokenizer tok = new StringTokenizer ( text ) ; return MessageBundle . tcompose ( "m.unknown_command" , tok . nextToken ( ) ) ; case 1 : Map . Entry < String , CommandHandler > entry = possibleCommands . entrySet ( ) . iterator ( ) . next ( ) ; String cmdName = entry . getKey ( ) ; CommandHandler cmd = entry . getValue ( ) ; String result = cmd . handleCommand ( speakSvc , cmdName , args , hist ) ; if ( ! result . equals ( ChatCodes . SUCCESS ) ) { return result ; } if ( record ) { hist [ 0 ] = "/" + ( ( hist [ 0 ] == null ) ? command : hist [ 0 ] ) ; addToHistory ( hist [ 0 ] ) ; } return result ; default : StringBuilder buf = new StringBuilder ( ) ; for ( String pcmd : Sets . newTreeSet ( possibleCommands . keySet ( ) ) ) { buf . append ( " /" ) . append ( pcmd ) ; } return MessageBundle . tcompose ( "m.unspecific_command" , buf . toString ( ) ) ; } } String message = text . trim ( ) ; if ( StringUtil . isBlank ( message ) ) { return ChatCodes . SUCCESS ; } return deliverChat ( speakSvc , message , ChatCodes . DEFAULT_MODE ) ; } | Parses and delivers the supplied chat message . Slash command processing and mogrification are performed and the message is added to the chat history if appropriate . |
13,491 | public void requestBroadcast ( String message ) { message = filter ( message , null , true ) ; if ( message == null ) { displayFeedback ( _bundle , MessageBundle . compose ( "m.broadcast_failed" , "m.filtered" ) ) ; return ; } _cservice . broadcast ( message , new ChatService . InvocationListener ( ) { public void requestFailed ( String reason ) { reason = MessageBundle . compose ( "m.broadcast_failed" , reason ) ; displayFeedback ( _bundle , reason ) ; } } ) ; } | Requests to send a site - wide broadcast message . |
13,492 | public < T extends Name > void requestTell ( final T target , String msg , final ResultListener < T > rl ) { final String message = filter ( msg , target , true ) ; if ( message == null ) { if ( rl != null ) { rl . requestFailed ( null ) ; } return ; } ChatService . TellListener listener = new ChatService . TellListener ( ) { public void tellSucceeded ( long idletime , String awayMessage ) { success ( ) ; if ( awayMessage != null ) { awayMessage = filter ( awayMessage , target , false ) ; if ( awayMessage != null ) { String msg = MessageBundle . tcompose ( "m.recipient_afk" , target , awayMessage ) ; displayFeedback ( _bundle , msg ) ; } } if ( idletime > 0L ) { idletime += _ctx . getConfig ( ) . getValue ( IDLE_TIME_KEY , DEFAULT_IDLE_TIME ) ; String msg = MessageBundle . compose ( "m.recipient_idle" , MessageBundle . taint ( target ) , TimeUtil . getTimeOrderString ( idletime , TimeUtil . MINUTE ) ) ; displayFeedback ( _bundle , msg ) ; } } protected void success ( ) { dispatchMessage ( new TellFeedbackMessage ( target , message , false ) , ChatCodes . PLACE_CHAT_TYPE ) ; addChatter ( target ) ; if ( rl != null ) { rl . requestCompleted ( target ) ; } } public void requestFailed ( String reason ) { String msg = MessageBundle . compose ( "m.tell_failed" , MessageBundle . taint ( target ) , reason ) ; TellFeedbackMessage tfm = new TellFeedbackMessage ( target , msg , true ) ; tfm . bundle = _bundle ; dispatchMessage ( tfm , ChatCodes . PLACE_CHAT_TYPE ) ; if ( rl != null ) { rl . requestFailed ( null ) ; } } } ; _cservice . tell ( target , message , listener ) ; } | Requests that a tell message be delivered to the specified target user . |
13,493 | public void setAwayMessage ( String message ) { if ( message != null ) { message = filter ( message , null , true ) ; if ( message == null ) { message = "..." ; } } _cservice . away ( message ) ; } | Configures a message that will be automatically reported to anyone that sends a tell message to this client to indicate that we are busy or away from the keyboard . |
13,494 | public void addAuxiliarySource ( DObject source , String localtype ) { source . addListener ( this ) ; _auxes . put ( source . getOid ( ) , localtype ) ; } | Adds an additional object via which chat messages may arrive . The chat director assumes the caller will be managing the subscription to this object and will remain subscribed to it for as long as it remains in effect as an auxiliary chat source . |
13,495 | public String filter ( String msg , Name otherUser , boolean outgoing ) { _filterMessageOp . setMessage ( msg , otherUser , outgoing ) ; _filters . apply ( _filterMessageOp ) ; return _filterMessageOp . getMessage ( ) ; } | Run a message through all the currently registered filters . |
13,496 | protected void registerCommandHandlers ( ) { MessageBundle msg = _ctx . getMessageManager ( ) . getBundle ( _bundle ) ; registerCommandHandler ( msg , "help" , new HelpHandler ( ) ) ; registerCommandHandler ( msg , "clear" , new ClearHandler ( ) ) ; registerCommandHandler ( msg , "speak" , new SpeakHandler ( ) ) ; registerCommandHandler ( msg , "emote" , new EmoteHandler ( ) ) ; registerCommandHandler ( msg , "think" , new ThinkHandler ( ) ) ; registerCommandHandler ( msg , "tell" , new TellHandler ( ) ) ; registerCommandHandler ( msg , "broadcast" , new BroadcastHandler ( ) ) ; } | Registers all the chat - command handlers . |
13,497 | protected void processReceivedMessage ( ChatMessage msg , String localtype ) { String autoResponse = null ; Name speaker = null ; Name speakerDisplay = null ; byte mode = ( byte ) - 1 ; if ( msg instanceof UserMessage ) { UserMessage umsg = ( UserMessage ) msg ; speaker = umsg . speaker ; speakerDisplay = umsg . getSpeakerDisplayName ( ) ; mode = umsg . mode ; } else if ( msg instanceof UserSystemMessage ) { speaker = ( ( UserSystemMessage ) msg ) . speaker ; speakerDisplay = speaker ; } setClientInfo ( msg , localtype ) ; if ( speaker != null ) { if ( shouldFilter ( msg ) && ( msg . message = filter ( msg . message , speaker , false ) ) == null ) { return ; } if ( USER_CHAT_TYPE . equals ( localtype ) && mode == ChatCodes . DEFAULT_MODE ) { addChatter ( speaker ) ; BodyObject self = ( BodyObject ) _ctx . getClient ( ) . getClientObject ( ) ; if ( ! StringUtil . isBlank ( self . awayMessage ) ) { autoResponse = self . awayMessage ; } } } dispatchMessage ( msg , localtype ) ; if ( autoResponse != null ) { String amsg = MessageBundle . tcompose ( "m.auto_responded" , speakerDisplay , autoResponse ) ; displayFeedback ( _bundle , amsg ) ; } } | Processes and dispatches the specified chat message . |
13,498 | protected void addToHistory ( String cmd ) { _history . remove ( cmd ) ; _history . add ( cmd ) ; if ( _history . size ( ) > MAX_COMMAND_HISTORY ) { _history . remove ( 0 ) ; } } | Adds the specified command to the history . |
13,499 | protected String mogrifyChat ( String text , byte mode , boolean transformsAllowed , boolean capFirst ) { int tlen = text . length ( ) ; if ( tlen == 0 ) { return text ; } else if ( tlen > 7 && suppressTooManyCaps ( ) ) { int caps = 0 ; for ( int ii = 0 ; ii < tlen ; ii ++ ) { if ( Character . isUpperCase ( text . charAt ( ii ) ) ) { caps ++ ; if ( caps > ( tlen / 2 ) ) { text = text . toLowerCase ( ) ; break ; } } } } StringBuffer buf = new StringBuffer ( text ) ; buf = mogrifyChat ( buf , transformsAllowed , capFirst ) ; return buf . toString ( ) ; } | Mogrifies common literary crutches into more appealing chat or commands . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.