idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
4,800
public synchronized PacketTransportEndpoint createEndpoint ( ) throws JMSException { if ( closed || transport . isClosed ( ) ) throw new FFMQException ( "Transport is closed" , "TRANSPORT_CLOSED" ) ; PacketTransportEndpoint endpoint = new PacketTransportEndpoint ( nextEndpointId ++ , this ) ; registeredEndpoints . put ( Integer . valueOf ( endpoint . getId ( ) ) , endpoint ) ; return endpoint ; }
Create a new transport endpoint
4,801
public static String replaceDoubleSingleQuotes ( String value ) { int idx = value . indexOf ( "''" ) ; if ( idx == - 1 ) return value ; int len = value . length ( ) ; int pos = 0 ; StringBuilder sb = new StringBuilder ( len ) ; while ( idx != - 1 ) { if ( idx > pos ) { sb . append ( value . substring ( pos , idx ) ) ; pos += ( idx - pos ) ; } sb . append ( "'" ) ; pos += 2 ; idx = value . indexOf ( "''" , pos ) ; } if ( pos < len ) sb . append ( value . substring ( pos , len ) ) ; return sb . toString ( ) ; }
Replace double single quotes in the target string
4,802
public static Number parseNumber ( String numberAsString ) throws InvalidSelectorException { if ( numberAsString == null ) return null ; try { if ( numberAsString . indexOf ( '.' ) != - 1 || numberAsString . indexOf ( 'e' ) != - 1 || numberAsString . indexOf ( 'E' ) != - 1 ) { return new Double ( numberAsString ) ; } else return Long . valueOf ( numberAsString ) ; } catch ( NumberFormatException e ) { throw new InvalidSelectorException ( "Invalid numeric value : " + numberAsString ) ; } }
Parse a number as string
4,803
public static SagaType startsNewSaga ( final Class < ? extends Saga > sagaClass ) { checkNotNull ( sagaClass , "The type of the saga has to be defined." ) ; SagaType sagaType = new SagaType ( ) ; sagaType . startsNew = true ; sagaType . sagaClass = sagaClass ; return sagaType ; }
Creates a type indicating to start a complete new saga .
4,804
public static SagaType continueSaga ( final Class < ? extends Saga > sagaClass ) { checkNotNull ( sagaClass , "The type of the saga has to be defined." ) ; SagaType sagaType = new SagaType ( ) ; sagaType . startsNew = false ; sagaType . sagaClass = sagaClass ; return sagaType ; }
Creates a type continuing a saga with an instance key that has yet to be defined .
4,805
private AbstractMessage fetchNext ( ) throws JMSException { if ( nextMessage != null ) return nextMessage ; nextMessage = localQueue . browse ( cursor , parsedSelector ) ; if ( nextMessage == null ) close ( ) ; return nextMessage ; }
Fetch the next browsable message in the associated queue
4,806
public KEY readKey ( final MESSAGE message , final LookupContext context ) { return extractFunction . key ( message , context ) ; }
Read the saga instance key from the provided message .
4,807
public static AbstractMessage makeInternalCopy ( Message srcMessage ) throws JMSException { if ( srcMessage instanceof AbstractMessage ) { AbstractMessage msg = ( AbstractMessage ) srcMessage ; if ( msg . isInternalCopy ( ) ) return msg ; AbstractMessage dup = duplicate ( srcMessage ) ; dup . setInternalCopy ( true ) ; return dup ; } AbstractMessage dup = duplicate ( srcMessage ) ; dup . setInternalCopy ( true ) ; return dup ; }
Create an internal copy of the message if necessary
4,808
public static AbstractMessage normalize ( Message srcMessage ) throws JMSException { if ( srcMessage instanceof AbstractMessage ) return ( AbstractMessage ) srcMessage ; return duplicate ( srcMessage ) ; }
Convert the message to native type if necessary
4,809
public static AbstractMessage duplicate ( Message srcMessage ) throws JMSException { AbstractMessage msgCopy ; if ( srcMessage instanceof AbstractMessage ) msgCopy = ( ( AbstractMessage ) srcMessage ) . copy ( ) ; else if ( srcMessage instanceof TextMessage ) msgCopy = duplicateTextMessage ( ( TextMessage ) srcMessage ) ; else if ( srcMessage instanceof ObjectMessage ) msgCopy = duplicateObjectMessage ( ( ObjectMessage ) srcMessage ) ; else if ( srcMessage instanceof BytesMessage ) msgCopy = duplicateBytesMessage ( ( BytesMessage ) srcMessage ) ; else if ( srcMessage instanceof MapMessage ) msgCopy = duplicateMapMessage ( ( MapMessage ) srcMessage ) ; else if ( srcMessage instanceof StreamMessage ) msgCopy = duplicateStreamMessage ( ( StreamMessage ) srcMessage ) ; else msgCopy = duplicateMessage ( srcMessage ) ; return msgCopy ; }
Create an independant copy of the given message
4,810
private void fastadd ( int wo , int off ) { this . buffer . add ( off - this . sizeinwords ) ; this . buffer . add ( wo ) ; this . sizeinwords = off + 1 ; }
same as add but without updating the cardinality counter strictly for internal use .
4,811
public Iterator < Integer > iterator ( ) { final IntIterator under = this . getIntIterator ( ) ; return new Iterator < Integer > ( ) { public boolean hasNext ( ) { return under . hasNext ( ) ; } public Integer next ( ) { return new Integer ( under . next ( ) ) ; } public void remove ( ) { throw new UnsupportedOperationException ( "bitsets do not support remove" ) ; } } ; }
Allow you to iterate over the set bits .
4,812
public IntIterator getIntIterator ( ) { return new IntIterator ( ) { int wordindex ; int i = 0 ; IntArray buf ; int currentword ; public IntIterator init ( IntArray b ) { this . buf = b ; this . wordindex = this . buf . get ( this . i ) ; this . currentword = this . buf . get ( this . i + 1 ) ; return this ; } public boolean hasNext ( ) { return this . currentword != 0 ; } public int next ( ) { final int offset = Integer . numberOfTrailingZeros ( this . currentword ) ; this . currentword ^= 1 << offset ; final int answer = this . wordindex * WORDSIZE + offset ; if ( this . currentword == 0 ) { this . i += 2 ; if ( this . i < this . buf . size ( ) ) { this . currentword = this . buf . get ( this . i + 1 ) ; this . wordindex += this . buf . get ( this . i ) + 1 ; } } return answer ; } } . init ( this . buffer ) ; }
Build a fast iterator over the set bits .
4,813
public SparseBitmap and ( SparseBitmap o ) { SparseBitmap a = new SparseBitmap ( ) ; and2by2 ( a , this , o ) ; return a ; }
Compute the bit - wise logical and with another bitmap .
4,814
public static void and2by2 ( BitmapContainer container , SparseBitmap bitmap1 , SparseBitmap bitmap2 ) { int it1 = 0 ; int it2 = 0 ; int p1 = bitmap1 . buffer . get ( it1 ) , p2 = bitmap2 . buffer . get ( it2 ) ; int buff ; while ( true ) { if ( p1 < p2 ) { if ( it1 + 2 >= bitmap1 . buffer . size ( ) ) break ; it1 += 2 ; p1 += bitmap1 . buffer . get ( it1 ) + 1 ; } else if ( p1 > p2 ) { if ( it2 + 2 >= bitmap2 . buffer . size ( ) ) break ; it2 += 2 ; p2 += bitmap2 . buffer . get ( it2 ) + 1 ; } else { if ( ( buff = bitmap1 . buffer . get ( it1 + 1 ) & bitmap2 . buffer . get ( it2 + 1 ) ) != 0 ) { container . add ( buff , p1 ) ; } if ( ( it1 + 2 >= bitmap1 . buffer . size ( ) ) || ( it2 + 2 >= bitmap2 . buffer . size ( ) ) ) break ; it1 += 2 ; it2 += 2 ; p1 += bitmap1 . buffer . get ( it1 ) + 1 ; p2 += bitmap2 . buffer . get ( it2 ) + 1 ; } } }
Computes the bit - wise logical exclusive and of two bitmaps .
4,815
public SparseBitmap or ( SparseBitmap o ) { SparseBitmap a = new SparseBitmap ( ) ; or2by2 ( a , this , o ) ; return a ; }
Computes the bit - wise logical or with another bitmap .
4,816
public static void or2by2 ( BitmapContainer container , SparseBitmap bitmap1 , SparseBitmap bitmap2 ) { int it1 = 0 ; int it2 = 0 ; int p1 = bitmap1 . buffer . get ( it1 ) ; int p2 = bitmap2 . buffer . get ( it2 ) ; if ( ( it1 < bitmap1 . buffer . size ( ) ) && ( it2 < bitmap2 . buffer . size ( ) ) ) while ( true ) { if ( p1 < p2 ) { container . add ( bitmap1 . buffer . get ( it1 + 1 ) , p1 ) ; it1 += 2 ; if ( it1 >= bitmap1 . buffer . size ( ) ) break ; p1 += bitmap1 . buffer . get ( it1 ) + 1 ; } else if ( p1 > p2 ) { container . add ( bitmap2 . buffer . get ( it2 + 1 ) , p2 ) ; it2 += 2 ; if ( it2 >= bitmap2 . buffer . size ( ) ) break ; p2 += bitmap2 . buffer . get ( it2 ) + 1 ; } else { container . add ( bitmap1 . buffer . get ( it1 + 1 ) | bitmap2 . buffer . get ( it2 + 1 ) , p1 ) ; it1 += 2 ; it2 += 2 ; if ( it1 < bitmap1 . buffer . size ( ) ) p1 += bitmap1 . buffer . get ( it1 ) + 1 ; if ( it2 < bitmap2 . buffer . size ( ) ) p2 += bitmap2 . buffer . get ( it2 ) + 1 ; if ( ( it1 >= bitmap1 . buffer . size ( ) ) || ( it2 >= bitmap2 . buffer . size ( ) ) ) break ; } } if ( it1 < bitmap1 . buffer . size ( ) ) { while ( true ) { container . add ( bitmap1 . buffer . get ( it1 + 1 ) , p1 ) ; it1 += 2 ; if ( it1 == bitmap1 . buffer . size ( ) ) break ; p1 += bitmap1 . buffer . get ( it1 ) + 1 ; } } if ( it2 < bitmap2 . buffer . size ( ) ) { while ( true ) { container . add ( bitmap2 . buffer . get ( it2 + 1 ) , p2 ) ; it2 += 2 ; if ( it2 == bitmap2 . buffer . size ( ) ) break ; p2 += bitmap2 . buffer . get ( it2 ) + 1 ; } } }
Computes the bit - wise logical or of two bitmaps .
4,817
public SparseBitmap xor ( SparseBitmap o ) { SparseBitmap a = new SparseBitmap ( ) ; xor2by2 ( a , this , o ) ; return a ; }
Computes the bit - wise logical exclusive or with another bitmap .
4,818
public static SparseBitmap and ( SparseBitmap ... bitmaps ) { if ( bitmaps . length == 0 ) return new SparseBitmap ( ) ; else if ( bitmaps . length == 1 ) return bitmaps [ 0 ] ; else if ( bitmaps . length == 2 ) return bitmaps [ 0 ] . and ( bitmaps [ 1 ] ) ; PriorityQueue < SparseBitmap > pq = new PriorityQueue < SparseBitmap > ( bitmaps . length , smallfirst ) ; for ( SparseBitmap x : bitmaps ) pq . add ( x ) ; while ( pq . size ( ) > 1 ) { SparseBitmap x1 = pq . poll ( ) ; SparseBitmap x2 = pq . poll ( ) ; pq . add ( x1 . and ( x2 ) ) ; } return pq . poll ( ) ; }
Computes the bit - wise and aggregate over several bitmaps .
4,819
public SkippableIterator getSkippableIterator ( ) { return new SkippableIterator ( ) { int pos = 0 ; int p = 0 ; public SkippableIterator init ( ) { this . p = SparseBitmap . this . buffer . get ( 0 ) ; return this ; } public void advance ( ) { this . pos += 2 ; if ( this . pos < SparseBitmap . this . buffer . size ( ) ) this . p += SparseBitmap . this . buffer . get ( this . pos ) + 1 ; } public void advanceUntil ( int min ) { advance ( ) ; while ( hasValue ( ) && ( getCurrentWordOffset ( ) < min ) ) { advance ( ) ; } } public int getCurrentWord ( ) { return SparseBitmap . this . buffer . get ( this . pos + 1 ) ; } public int getCurrentWordOffset ( ) { return this . p ; } public boolean hasValue ( ) { return this . pos < SparseBitmap . this . buffer . size ( ) ; } } . init ( ) ; }
Gets the skippable iterator .
4,820
public static boolean match ( SkippableIterator o1 , SkippableIterator o2 ) { while ( o1 . getCurrentWordOffset ( ) != o2 . getCurrentWordOffset ( ) ) { if ( o1 . getCurrentWordOffset ( ) < o2 . getCurrentWordOffset ( ) ) { o1 . advanceUntil ( o2 . getCurrentWordOffset ( ) ) ; if ( ! o1 . hasValue ( ) ) return false ; } if ( o1 . getCurrentWordOffset ( ) > o2 . getCurrentWordOffset ( ) ) { o2 . advanceUntil ( o1 . getCurrentWordOffset ( ) ) ; if ( ! o2 . hasValue ( ) ) return false ; } } return true ; }
Synchronize two iterators
4,821
public int cardinality ( ) { int answer = 0 ; for ( int k = 0 ; k < this . buffer . size ( ) ; k += 2 ) { answer += Integer . bitCount ( this . buffer . get ( k + 1 ) ) ; } return answer ; }
Compute the cardinality .
4,822
Collection < Exception > finish ( ) { return Lists . reverse ( finishers ) . stream ( ) . flatMap ( f -> f . get ( ) . map ( Stream :: of ) . orElse ( Stream . empty ( ) ) ) . collect ( Collectors . toList ( ) ) ; }
Call finishers on all started modules .
4,823
public Collection < Exception > error ( final Object message , final Throwable error ) { return Lists . reverse ( errorHandlers ) . stream ( ) . flatMap ( f -> f . apply ( message , error ) . map ( Stream :: of ) . orElse ( Stream . empty ( ) ) ) . collect ( Collectors . toList ( ) ) ; }
Execute error method on started modules .
4,824
private static Optional < Exception > tryExecute ( final Runnable runnable , final SagaModule module ) { Exception executionException ; try { runnable . run ( ) ; executionException = null ; } catch ( Exception ex ) { executionException = ex ; LOG . error ( "Error executing function on module {}" , module , ex ) ; } return Optional . ofNullable ( executionException ) ; }
Executes the provided runnable without throwing possible exceptions .
4,825
protected void fillSettings ( Settings settings ) { settings . setStringProperty ( "name" , name ) ; settings . setIntProperty ( "persistentStore.initialBlockCount" , initialBlockCount ) ; settings . setIntProperty ( "persistentStore.maxBlockCount" , maxBlockCount ) ; settings . setIntProperty ( "persistentStore.autoExtendAmount" , autoExtendAmount ) ; settings . setIntProperty ( "persistentStore.blockSize" , blockSize ) ; if ( rawDataFolder != null ) settings . setStringProperty ( "persistentStore.dataFolder" , rawDataFolder ) ; settings . setIntProperty ( "memoryStore.maxMessages" , maxNonPersistentMessages ) ; settings . setBooleanProperty ( "persistentStore.useJournal" , useJournal ) ; if ( rawJournalFolder != null ) settings . setStringProperty ( "persistentStore.journal.dataFolder" , rawJournalFolder ) ; settings . setLongProperty ( "persistentStore.journal.maxFileSize" , maxJournalSize ) ; settings . setIntProperty ( "persistentStore.journal.maxWriteBatchSize" , maxWriteBatchSize ) ; settings . setIntProperty ( "persistentStore.journal.maxUnflushedJournalSize" , maxUnflushedJournalSize ) ; settings . setIntProperty ( "persistentStore.journal.maxUncommittedStoreSize" , maxUncommittedStoreSize ) ; settings . setIntProperty ( "persistentStore.journal.outputBufferSize" , journalOutputBuffer ) ; settings . setBooleanProperty ( "persistentStore.journal.preAllocateFiles" , preAllocateFiles ) ; settings . setIntProperty ( "persistentStore.syncMethod" , storageSyncMethod ) ; settings . setBooleanProperty ( "temporary" , temporary ) ; settings . setBooleanProperty ( "memoryStore.overflowToPersistent" , overflowToPersistent ) ; }
Append nodes to the XML definition
4,826
public void registerConsumer ( LocalMessageConsumer consumer ) { consumersLock . writeLock ( ) . lock ( ) ; try { localConsumers . add ( consumer ) ; } finally { consumersLock . writeLock ( ) . unlock ( ) ; } }
Register a message consumer on this queue
4,827
public void unregisterConsumer ( LocalMessageConsumer consumer ) { consumersLock . writeLock ( ) . lock ( ) ; try { localConsumers . remove ( consumer ) ; } finally { consumersLock . writeLock ( ) . unlock ( ) ; } }
Unregister a message listener
4,828
public static File [ ] getDescriptorFiles ( File definitionDir , final String prefix , final String suffix ) { return definitionDir . listFiles ( new FileFilter ( ) { public boolean accept ( File pathname ) { if ( ! pathname . isFile ( ) || ! pathname . canRead ( ) ) return false ; String name = pathname . getName ( ) ; return name . toLowerCase ( ) . endsWith ( suffix ) && name . startsWith ( prefix ) ; } } ) ; }
Find all descriptor files with the given prefix in a target folder
4,829
public static String getShortClassName ( Class < ? > clazz ) { String className = clazz . getName ( ) ; int idx = className . lastIndexOf ( '.' ) ; return ( idx == - 1 ? className : className . substring ( idx + 1 ) ) ; }
Get the short name of the given class
4,830
public static String getCallerMethodName ( int offset ) { StackTraceElement [ ] stack = new Exception ( ) . getStackTrace ( ) ; return stack [ offset + 1 ] . getMethodName ( ) ; }
Get the name of the caller method
4,831
public void close ( ) { if ( ! manageSockets ) throw new IllegalStateException ( "Cannot close an un-managed socket factory" ) ; synchronized ( createdSockets ) { Iterator < ServerSocket > sockets = createdSockets . iterator ( ) ; while ( sockets . hasNext ( ) ) { ServerSocket socket = sockets . next ( ) ; try { socket . close ( ) ; } catch ( Exception e ) { log . error ( "Could not close server socket" , e ) ; } } createdSockets . clear ( ) ; } }
Cleanup sockets created by this factory
4,832
private KeyReader tryGetKeyReader ( final Class < ? extends Saga > sagaClazz , final Object message ) { KeyReader reader ; try { Optional < KeyReader > cachedReader = knownReaders . get ( SagaMessageKey . forMessage ( sagaClazz , message ) , ( ) -> { KeyReader foundReader = findReader ( sagaClazz , message ) ; return Optional . fromNullable ( foundReader ) ; } ) ; reader = cachedReader . orNull ( ) ; } catch ( Exception ex ) { LOG . error ( "Error searching for reader to extract saga key. sagatype = {}, message = {}" , sagaClazz , message , ex ) ; reader = null ; } return reader ; }
Does not throw an exception when accessing the loading cache for key readers .
4,833
private KeyReader findReaderMatchingExactType ( final Iterable < KeyReader > readers , final Class < ? > messageType ) { KeyReader messageKeyReader = null ; for ( KeyReader reader : readers ) { if ( reader . getMessageClass ( ) . equals ( messageType ) ) { messageKeyReader = reader ; break ; } } return messageKeyReader ; }
Search for reader based on message class .
4,834
private Collection < KeyReader > findReader ( final Class < ? extends Saga > sagaClazz , final Class < ? > messageClazz ) { Saga saga = sagaProviderFactory . createProvider ( sagaClazz ) . get ( ) ; Collection < KeyReader > readers = saga . keyReaders ( ) ; if ( readers == null ) { readers = new ArrayList < > ( ) ; } return readers ; }
Search for a reader based on saga type .
4,835
public static void checkQueueName ( String queueName ) throws JMSException { if ( queueName == null ) throw new FFMQException ( "Queue name is not set" , "INVALID_DESTINATION_NAME" ) ; if ( queueName . length ( ) > FFMQConstants . MAX_QUEUE_NAME_SIZE ) throw new FFMQException ( "Queue name '" + queueName + "' is too long (" + queueName . length ( ) + " > " + FFMQConstants . MAX_QUEUE_NAME_SIZE + ")" , "INVALID_DESTINATION_NAME" ) ; checkDestinationName ( queueName ) ; }
Check the validity of a queue name
4,836
public static void checkTopicName ( String topicName ) throws JMSException { if ( topicName == null ) throw new FFMQException ( "Topic name is not set" , "INVALID_DESTINATION_NAME" ) ; if ( topicName . length ( ) > FFMQConstants . MAX_TOPIC_NAME_SIZE ) throw new FFMQException ( "Topic name '" + topicName + "' is too long (" + topicName . length ( ) + " > " + FFMQConstants . MAX_TOPIC_NAME_SIZE + ")" , "INVALID_DESTINATION_NAME" ) ; checkDestinationName ( topicName ) ; }
Check the validity of a topic name
4,837
protected void writeTo ( JournalFile journalFile ) throws JournalException { journalFile . writeByte ( type ) ; journalFile . writeLong ( transactionId ) ; }
Write the operation to the given journal file
4,838
public AbstractDescriptor read ( File descriptorFile , Class < ? extends AbstractXMLDescriptorHandler > handlerClass ) throws JMSException { if ( ! descriptorFile . canRead ( ) ) throw new FFMQException ( "Can't read descriptor file : " + descriptorFile . getAbsolutePath ( ) , "FS_ERROR" ) ; log . debug ( "Parsing descriptor : " + descriptorFile . getAbsolutePath ( ) ) ; AbstractXMLDescriptorHandler handler ; try { handler = handlerClass . newInstance ( ) ; SAXParserFactory factory = SAXParserFactory . newInstance ( ) ; SAXParser parser = factory . newSAXParser ( ) ; FileInputStream in = new FileInputStream ( descriptorFile ) ; parser . parse ( in , handler ) ; in . close ( ) ; } catch ( Exception e ) { throw new FFMQException ( "Cannot parse descriptor file : " + descriptorFile . getAbsolutePath ( ) , "PARSE_ERROR" , e ) ; } AbstractDescriptor descriptor = handler . getDescriptor ( ) ; descriptor . setDescriptorFile ( descriptorFile ) ; return descriptor ; }
Read and parse an XML descriptor file
4,839
private InvocationMethod tryGetMethod ( final InvokerKey key ) { InvocationMethod invocationMethod = null ; try { invocationMethod = invocationMethods . get ( key ) ; } catch ( Exception ex ) { LOG . warn ( "Error fetching method to invoke method {}" , key , ex ) ; } return invocationMethod ; }
Finds the method to invoke without causing an exception .
4,840
protected void remoteInit ( ) throws JMSException { CreateConsumerQuery query = new CreateConsumerQuery ( ) ; query . setConsumerId ( id ) ; query . setSessionId ( session . getId ( ) ) ; query . setDestination ( destination ) ; query . setMessageSelector ( messageSelector ) ; query . setNoLocal ( noLocal ) ; transportEndpoint . blockingRequest ( query ) ; }
Initialize the remote endpoint for this consumer
4,841
private void prefetchFromDestination ( ) throws JMSException { if ( closed ) return ; if ( traceEnabled ) log . trace ( "#" + id + " Prefetching more from destination " + destination ) ; PrefetchQuery query = new PrefetchQuery ( ) ; query . setSessionId ( session . getId ( ) ) ; query . setConsumerId ( id ) ; transportEndpoint . nonBlockingRequest ( query ) ; }
Prefetch messages from destination
4,842
public static String replaceSystemProperties ( String value ) { if ( value == null || value . length ( ) == 0 ) return value ; StringBuilder sb = new StringBuilder ( ) ; int pos = 0 ; int start ; while ( ( start = value . indexOf ( "${" , pos ) ) != - 1 ) { if ( start > pos ) sb . append ( value . substring ( pos , start ) ) ; int end = value . indexOf ( '}' , start + 2 ) ; if ( end == - 1 ) { pos = start ; break ; } String varName = value . substring ( start + 2 , end ) ; String varValue = System . getProperty ( varName , "${" + varName + "}" ) ; sb . append ( varValue ) ; pos = end + 1 ; } if ( pos < value . length ( ) ) sb . append ( value . substring ( pos ) ) ; return sb . toString ( ) ; }
Replace system properties in the given string value
4,843
public JournalBuilder setArchived ( File to ) { if ( ! to . exists ( ) ) { throw new IllegalArgumentException ( "<" + to + "> does not exist" ) ; } if ( ! to . isDirectory ( ) ) { throw new IllegalArgumentException ( "<" + to + "> is not a directory" ) ; } this . directoryArchive = to ; return this ; }
Set the directory used to archive cleaned up log files also enabling archiving .
4,844
public PacketTransport createPacketTransport ( String id , URI transportURI , Settings settings ) throws PacketTransportException { String protocol = transportURI . getScheme ( ) ; if ( protocol == null ) protocol = PacketTransportType . TCP ; if ( protocol . equals ( PacketTransportType . TCP ) || protocol . equals ( PacketTransportType . TCPS ) ) { return new TcpPacketTransport ( id , transportURI , settings ) ; } if ( protocol . equals ( PacketTransportType . TCPNIO ) ) { return new NIOTcpPacketTransport ( id , ClientEnvironment . getMultiplexer ( ) , transportURI , settings ) ; } throw new PacketTransportException ( "Unsupported transport protocol : " + protocol ) ; }
Create a packet transport instance to handle the given URI
4,845
public synchronized T borrow ( ) throws JMSException { if ( closed ) throw new ObjectPoolException ( "Object pool is closed" ) ; int availableCount = available . size ( ) ; if ( availableCount > 0 ) return available . remove ( availableCount - 1 ) ; if ( all . size ( ) < maxSize ) return extendPool ( ) ; switch ( exhaustionPolicy ) { case WHEN_EXHAUSTED_FAIL : throw new ObjectPoolException ( "Pool is exhausted (maxSize=" + maxSize + ")" ) ; case WHEN_EXHAUSTED_BLOCK : return waitForAvailability ( ) ; case WHEN_EXHAUSTED_WAIT : return waitForAvailability ( waitTimeout , true ) ; case WHEN_EXHAUSTED_RETURN_NULL : return null ; case WHEN_EXHAUSTED_WAIT_RETURN_NULL : return waitForAvailability ( waitTimeout , false ) ; default : throw new ObjectPoolException ( "Invalid exhaustion policy : " + exhaustionPolicy ) ; } }
Borrow an object from the pool
4,846
public synchronized void release ( T poolObject ) { if ( closed ) return ; if ( pendingWaits > 0 ) { available . add ( poolObject ) ; notifyAll ( ) ; } else { if ( available . size ( ) >= maxIdle ) { all . remove ( poolObject ) ; internalDestroyPoolObject ( poolObject ) ; } else available . add ( poolObject ) ; } }
Return an object to the pool
4,847
public void close ( ) { synchronized ( closeLock ) { if ( closed ) return ; closed = true ; } synchronized ( this ) { Iterator < T > allObjects = all . iterator ( ) ; while ( allObjects . hasNext ( ) ) { T poolObject = allObjects . next ( ) ; internalDestroyPoolObject ( poolObject ) ; } all . clear ( ) ; available . clear ( ) ; notifyAll ( ) ; } }
Close the pool destroying all objects
4,848
public final void wakeUpMessageListener ( ) { try { while ( ! closed ) { synchronized ( session . deliveryLock ) { AbstractMessage message = receiveFromDestination ( 0 , true ) ; if ( message == null ) break ; message . ensureDeserializationLevel ( MessageSerializationLevel . FULL ) ; message . setSession ( session ) ; boolean listenerFailed = false ; try { messageListener . onMessage ( message ) ; } catch ( Throwable e ) { listenerFailed = true ; if ( shouldLogListenersFailures ( ) ) log . error ( "Message listener failed" , e ) ; } if ( autoAcknowledge ) { if ( listenerFailed ) session . recover ( ) ; else session . acknowledge ( ) ; } } } } catch ( JMSException e ) { ErrorTools . log ( e , log ) ; } }
Wake up the consumer message listener
4,849
public static < MESSAGE , KEY > KeyReader < MESSAGE , KEY > forMessage ( final Class < MESSAGE > messageClass , final KeyExtractFunction < MESSAGE , KEY > extractFunction ) { return FunctionKeyReader . create ( messageClass , extractFunction ) ; }
Create a new key reader for a specific message class .
4,850
public final void dispatch ( AbstractMessage message ) throws JMSException { LocalConnection conn = ( LocalConnection ) getConnection ( ) ; if ( conn . isSecurityEnabled ( ) ) { Destination destination = message . getJMSDestination ( ) ; if ( destination instanceof Queue ) { String queueName = ( ( Queue ) destination ) . getQueueName ( ) ; if ( conn . isRegisteredTemporaryQueue ( queueName ) ) { } else if ( queueName . equals ( FFMQConstants . ADM_REQUEST_QUEUE ) ) { conn . checkPermission ( Resource . SERVER , Action . REMOTE_ADMIN ) ; } else if ( queueName . equals ( FFMQConstants . ADM_REPLY_QUEUE ) ) { if ( conn . getSecurityContext ( ) != null ) throw new FFMQException ( "Access denied to administration queue " + queueName , "ACCESS_DENIED" ) ; } else { conn . checkPermission ( destination , Action . PRODUCE ) ; } } else if ( destination instanceof Topic ) { String topicName = ( ( Topic ) destination ) . getTopicName ( ) ; if ( conn . isRegisteredTemporaryTopic ( topicName ) ) { } else { conn . checkPermission ( destination , Action . PRODUCE ) ; } } else throw new InvalidDestinationException ( "Unsupported destination : " + destination ) ; } if ( debugEnabled ) log . debug ( this + " [PUT] in " + message . getJMSDestination ( ) + " - " + message ) ; externalAccessLock . readLock ( ) . lock ( ) ; try { checkNotClosed ( ) ; pendingPuts . add ( message ) ; if ( ! transacted ) commitUpdates ( false , null , true ) ; } finally { externalAccessLock . readLock ( ) . unlock ( ) ; } }
Called from producers when sending a message
4,851
public final void rollbackUndelivered ( List < String > undeliveredMessageIDs ) throws JMSException { externalAccessLock . readLock ( ) . lock ( ) ; try { checkNotClosed ( ) ; rollbackUpdates ( false , true , undeliveredMessageIDs ) ; } finally { externalAccessLock . readLock ( ) . unlock ( ) ; } }
Rollback undelivered get operations in this session
4,852
public MessageConsumer createConsumer ( IntegerID consumerId , Destination destination , String messageSelector , boolean noLocal ) throws JMSException { externalAccessLock . readLock ( ) . lock ( ) ; try { checkNotClosed ( ) ; LocalMessageConsumer consumer = new LocalMessageConsumer ( engine , this , destination , messageSelector , noLocal , consumerId , null ) ; registerConsumer ( consumer ) ; consumer . initDestination ( ) ; return consumer ; } finally { externalAccessLock . readLock ( ) . unlock ( ) ; } }
Create a consumer with the given id
4,853
protected final void deleteQueue ( String queueName ) throws JMSException { transactionSet . removeUpdatesForQueue ( queueName ) ; engine . deleteQueue ( queueName ) ; }
Delete a queue
4,854
public synchronized void register ( String clientID ) throws InvalidClientIDException { if ( ! clientIDs . add ( clientID ) ) { log . error ( "Client ID already exists : " + clientID ) ; throw new InvalidClientIDException ( "Client ID already exists : " + clientID ) ; } log . debug ( "Registered clientID : " + clientID ) ; }
Register a new client ID
4,855
protected void sync ( ) throws JournalException { try { flushBuffer ( ) ; switch ( storageSyncMethod ) { case StorageSyncMethod . FD_SYNC : output . getFD ( ) . sync ( ) ; break ; case StorageSyncMethod . CHANNEL_FORCE_NO_META : channel . force ( false ) ; break ; default : throw new JournalException ( "Unsupported sync method : " + storageSyncMethod ) ; } } catch ( IOException e ) { log . error ( "[" + baseName + "] Cannot create sync journal file : " + file . getAbsolutePath ( ) , e ) ; throw new JournalException ( "Could not sync journal file : " + file . getAbsolutePath ( ) , e ) ; } }
Force file content sync to disk
4,856
public void closeAndDelete ( ) throws JournalException { close ( ) ; if ( ! file . delete ( ) ) if ( file . exists ( ) ) throw new JournalException ( "Cannot delete journal file : " + file . getAbsolutePath ( ) ) ; }
Close and delete the journal file
4,857
public File closeAndRecycle ( ) throws JournalException { File recycledFile = new File ( file . getAbsolutePath ( ) + RECYCLED_SUFFIX ) ; if ( ! file . renameTo ( recycledFile ) ) throw new JournalException ( "Cannot rename journal file " + file . getAbsolutePath ( ) + " to " + recycledFile . getAbsolutePath ( ) ) ; try { fillWithZeroes ( recycledFile . length ( ) , writeBuffer . length ) ; } catch ( IOException e ) { throw new JournalException ( "Cannot clear journal file : " + recycledFile . getAbsolutePath ( ) , e ) ; } sync ( ) ; close ( ) ; return recycledFile ; }
Close and recycle the journal file
4,858
public static synchronized NIOTcpMultiplexer getMultiplexer ( ) throws PacketTransportException { if ( multiplexer == null ) multiplexer = new NIOTcpMultiplexer ( getSettings ( ) , true ) ; return multiplexer ; }
Get the multiplexer singleton instance
4,859
public static synchronized AsyncTaskManager getAsyncTaskManager ( ) throws JMSException { if ( asyncTaskManager == null ) { int threadPoolMinSize = getSettings ( ) . getIntProperty ( FFMQCoreSettings . ASYNC_TASK_MANAGER_DELIVERY_THREAD_POOL_MINSIZE , 0 ) ; int threadPoolMaxIdle = getSettings ( ) . getIntProperty ( FFMQCoreSettings . ASYNC_TASK_MANAGER_DELIVERY_THREAD_POOL_MAXIDLE , 5 ) ; int threadPoolMaxSize = getSettings ( ) . getIntProperty ( FFMQCoreSettings . ASYNC_TASK_MANAGER_DELIVERY_THREAD_POOL_MAXSIZE , 10 ) ; asyncTaskManager = new AsyncTaskManager ( "AsyncTaskManager-client-delivery" , threadPoolMinSize , threadPoolMaxIdle , threadPoolMaxSize ) ; } return asyncTaskManager ; }
Get the async . task manager singleton instance
4,860
public void unsubscribe ( String clientID , String subscriptionName ) throws JMSException { String subscriberID = clientID + "-" + subscriptionName ; subscriptionsLock . writeLock ( ) . lock ( ) ; try { LocalTopicSubscription subscription = subscriptionMap . get ( subscriberID ) ; if ( subscription == null ) return ; if ( isConsumerRegistered ( subscriberID ) ) throw new FFMQException ( "Subscription " + subscriptionName + " is still in use" , "SUBSCRIPTION_STILL_IN_USE" ) ; subscriptionMap . remove ( subscriberID ) ; removeSubscription ( subscription ) ; } finally { subscriptionsLock . writeLock ( ) . unlock ( ) ; } }
Unsubscribe all durable consumers for a given client ID and subscription name
4,861
public static JSONObject getJSONObject ( HttpPost request , Integer method , HashMap < String , String > params ) throws JSONException { switch ( method ) { case METHOD_PUT : case METHOD_DELETE : case METHOD_POST : return doPostRequest ( request , params ) ; default : throw new RuntimeException ( "Wrong http method requested" ) ; } }
Get JSON response for POST
4,862
private static JSONObject doPostRequest ( HttpPost httpPost , HashMap < String , String > params ) throws JSONException { JSONObject json = null ; HttpClient postClient = HttpClientBuilder . create ( ) . build ( ) ; HttpResponse response ; try { response = postClient . execute ( httpPost ) ; if ( response . getStatusLine ( ) . getStatusCode ( ) == 200 ) { HttpEntity entity = response . getEntity ( ) ; if ( entity != null ) { InputStream instream = entity . getContent ( ) ; String result = convertStreamToString ( instream ) ; instream . close ( ) ; json = new JSONObject ( result ) ; } } else { json = UpworkRestClient . genError ( response ) ; } } catch ( ClientProtocolException e ) { json = UpworkRestClient . genError ( HTTP_RESPONSE_503 , "Exception: ClientProtocolException" ) ; } catch ( IOException e ) { json = UpworkRestClient . genError ( HTTP_RESPONSE_503 , "Exception: IOException" ) ; } catch ( JSONException e ) { json = UpworkRestClient . genError ( HTTP_RESPONSE_503 , "Exception: JSONException" ) ; } catch ( Exception e ) { json = UpworkRestClient . genError ( HTTP_RESPONSE_503 , "Exception: Exception " + e . toString ( ) ) ; } finally { httpPost . abort ( ) ; } return json ; }
Execute POST request
4,863
private static JSONObject doGetRequest ( HttpGet httpGet ) throws JSONException { JSONObject json = null ; HttpClient httpClient = HttpClientBuilder . create ( ) . build ( ) ; HttpResponse response ; try { response = httpClient . execute ( httpGet ) ; if ( response . getStatusLine ( ) . getStatusCode ( ) == 200 ) { HttpEntity entity = response . getEntity ( ) ; if ( entity != null ) { InputStream instream = entity . getContent ( ) ; String result = convertStreamToString ( instream ) ; instream . close ( ) ; json = new JSONObject ( result ) ; } } else { json = UpworkRestClient . genError ( response ) ; } } catch ( ClientProtocolException e ) { json = UpworkRestClient . genError ( HTTP_RESPONSE_503 , "Exception: ClientProtocolException" ) ; } catch ( IOException e ) { json = UpworkRestClient . genError ( HTTP_RESPONSE_503 , "Exception: IOException" ) ; } catch ( JSONException e ) { json = UpworkRestClient . genError ( HTTP_RESPONSE_503 , "Exception: JSONException" ) ; } catch ( Exception e ) { json = UpworkRestClient . genError ( HTTP_RESPONSE_503 , "Exception: Exception " + e . toString ( ) ) ; } finally { httpGet . abort ( ) ; } return json ; }
Execute GET request
4,864
public JSONObject actions ( String reference , HashMap < String , String > params ) throws JSONException { return oClient . post ( "/offers/v1/contractors/offers/" + reference , params ) ; }
Run a specific action
4,865
public JSONObject getOwned ( String freelancerReference , HashMap < String , String > params ) throws JSONException { return oClient . get ( "/finreports/v2/financial_account_owner/" + freelancerReference , params ) ; }
Generate Financial Reports for an owned Account
4,866
public JSONObject invite ( String jobKey , HashMap < String , String > params ) throws JSONException { return oClient . post ( "/hr/v1/jobs/" + jobKey + "/candidates" , params ) ; }
Invite to Interview
4,867
public JSONObject create ( HashMap < String , String > params ) throws JSONException { return oClient . post ( "/hr/v3/fp/milestones" , params ) ; }
Create a new Milestone
4,868
public JSONObject submitBonus ( String teamReference , HashMap < String , String > params ) throws JSONException { return oClient . post ( "/hr/v2/teams/" + teamReference + "/adjustments" , params ) ; }
Submit a Custom Payment
4,869
public void onNewIntent ( Intent intent ) { super . onNewIntent ( intent ) ; Uri uri = intent . getData ( ) ; if ( uri != null && uri . getScheme ( ) . equals ( OAUTH_CALLBACK_SCHEME ) ) { String verifier = uri . getQueryParameter ( OAuth . OAUTH_VERIFIER ) ; new UpworkRetrieveAccessTokenTask ( ) . execute ( verifier ) ; } }
Callback once we are done with the authorization of this app
4,870
public JSONObject getByContract ( String contractId , String ts ) throws JSONException { return oClient . get ( "/team/v3/snapshots/contracts/" + contractId + "/" + ts ) ; }
Get snapshot info by specific contract
4,871
public JSONObject updateByContract ( String contractId , String ts , HashMap < String , String > params ) throws JSONException { return oClient . put ( "/team/v3/snapshots/contracts/" + contractId + "/" + ts , params ) ; }
Update snapshot by specific contract
4,872
public JSONObject deleteByContract ( String contractId , String ts ) throws JSONException { return oClient . delete ( "/team/v3/snapshots/contracts/" + contractId + "/" + ts ) ; }
Delete snapshot by specific contract
4,873
@ SuppressWarnings ( "unchecked" ) public < T > T lookup ( final String id ) { for ( final IdentifiableController controller : identifiables ) { if ( controller . getId ( ) . equals ( id ) ) { return ( T ) controller ; } } throw new IllegalArgumentException ( "Could not find a controller with the ID '" + id + "'" ) ; }
Returns a controller instance with the given ID .
4,874
public JSONObject getByContract ( String contract , String date , HashMap < String , String > params ) throws JSONException { return oClient . get ( "/team/v3/workdiaries/contracts/" + contract + "/" + date , params ) ; }
Get Work Diary by Contract
4,875
private JSONObject _getByType ( String company , String team , String code ) throws JSONException { String url = "" ; if ( code != null ) { url = "/" + code ; } return oClient . get ( "/otask/v1/tasks/companies/" + company + "/teams/" + team + "/tasks" + url ) ; }
Get by type
4,876
public JSONObject requestApproval ( HashMap < String , String > params ) throws JSONException { return oClient . post ( "/hr/v3/fp/submissions" , params ) ; }
Freelancer submits work for the client to approve
4,877
public JSONObject approve ( String submissionId , HashMap < String , String > params ) throws JSONException { return oClient . put ( "/hr/v3/fp/submissions/" + submissionId + "/approve" , params ) ; }
Approve an existing Submission
4,878
public HashMap < String , String > getAccessTokenSet ( String verifier ) { try { mOAuthProvider . retrieveAccessToken ( mOAuthConsumer , verifier ) ; } catch ( OAuthException e ) { e . printStackTrace ( ) ; } return setTokenWithSecret ( mOAuthConsumer . getToken ( ) , mOAuthConsumer . getTokenSecret ( ) ) ; }
Get access token - secret pair
4,879
public final HashMap < String , String > setTokenWithSecret ( String aToken , String aSecret ) { HashMap < String , String > token = new HashMap < String , String > ( ) ; accessToken = aToken ; accessSecret = aSecret ; mOAuthConsumer . setTokenWithSecret ( accessToken , accessSecret ) ; token . put ( "token" , accessToken ) ; token . put ( "secret" , accessSecret ) ; return token ; }
Setup access token and secret for OAuth client
4,880
public JSONObject get ( String url , HashMap < String , String > params ) throws JSONException { return sendGetRequest ( url , METHOD_GET , params ) ; }
Send signed OAuth GET request
4,881
public JSONObject post ( String url , HashMap < String , String > params ) throws JSONException { return sendPostRequest ( url , METHOD_POST , params ) ; }
Send signed OAuth POST request
4,882
public JSONObject put ( String url ) throws JSONException { return sendPostRequest ( url , METHOD_PUT , new HashMap < String , String > ( ) ) ; }
Send signed OAuth PUT request
4,883
public JSONObject delete ( String url , HashMap < String , String > params ) throws JSONException { return sendPostRequest ( url , METHOD_DELETE , params ) ; }
Send signed OAuth DELETE request
4,884
private String _getAuthorizationUrl ( String oauthCallback ) { String url = null ; try { url = mOAuthProvider . retrieveRequestToken ( mOAuthConsumer , oauthCallback ) ; } catch ( OAuthException e ) { e . printStackTrace ( ) ; } return url ; }
Get authorization URL use provided callback URL
4,885
private JSONObject sendGetRequest ( String url , Integer type , HashMap < String , String > params ) throws JSONException { String fullUrl = getFullUrl ( url ) ; HttpGet request = new HttpGet ( fullUrl ) ; if ( params != null ) { URI uri ; String query = "" ; try { URIBuilder uriBuilder = new URIBuilder ( request . getURI ( ) ) ; for ( Map . Entry < String , String > entry : params . entrySet ( ) ) { String key = entry . getKey ( ) ; String value = entry . getValue ( ) ; query = query + key + "=" + value . replace ( "&" , "&amp;" ) + "&" ; } uriBuilder . setCustomQuery ( query ) ; uri = uriBuilder . build ( ) ; request = new HttpGet ( fullUrl + "?" + uri . getRawQuery ( ) . replace ( "&amp;" , "%26" ) ) ; } catch ( URISyntaxException e ) { e . printStackTrace ( ) ; } } try { mOAuthConsumer . sign ( request ) ; } catch ( OAuthException e ) { e . printStackTrace ( ) ; } return UpworkRestClient . getJSONObject ( request , type ) ; }
Send signed GET OAuth request
4,886
private JSONObject sendPostRequest ( String url , Integer type , HashMap < String , String > params ) throws JSONException { String fullUrl = getFullUrl ( url ) ; HttpPost request = new HttpPost ( fullUrl ) ; switch ( type ) { case METHOD_PUT : case METHOD_DELETE : String oValue ; if ( type == METHOD_PUT ) { oValue = "put" ; } else { oValue = "delete" ; } params . put ( OVERLOAD_PARAM , oValue ) ; case METHOD_POST : break ; default : throw new RuntimeException ( "Wrong http method requested" ) ; } JSONObject json = new JSONObject ( ) ; for ( Map . Entry < String , String > entry : params . entrySet ( ) ) { json . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } request . setHeader ( "Content-Type" , "application/json" ) ; try { request . setEntity ( new StringEntity ( json . toString ( ) ) ) ; } catch ( UnsupportedEncodingException e1 ) { e1 . printStackTrace ( ) ; } try { mOAuthConsumer . sign ( request ) ; } catch ( OAuthException e ) { e . printStackTrace ( ) ; } return UpworkRestClient . getJSONObject ( request , type , params ) ; }
Send signed POST OAuth request
4,887
public JSONObject getByFreelancersTeam ( String freelancerTeamReference , HashMap < String , String > params ) throws JSONException { return oClient . get ( "/finreports/v2/provider_teams/" + freelancerTeamReference + "/billings" , params ) ; }
Generate Billing Reports for a Specific Freelancer s Team
4,888
public JSONObject getByFreelancersCompany ( String freelancerCompanyReference , HashMap < String , String > params ) throws JSONException { return oClient . get ( "/finreports/v2/provider_companies/" + freelancerCompanyReference + "/billings" , params ) ; }
Generate Billing Reports for a Specific Freelancer s Company
4,889
public JSONObject getByBuyersTeam ( String buyerTeamReference , HashMap < String , String > params ) throws JSONException { return oClient . get ( "/finreports/v2/buyer_teams/" + buyerTeamReference + "/billings" , params ) ; }
Generate Billing Reports for a Specific Buyer s Team
4,890
public JSONObject getByBuyersCompany ( String buyerCompanyReference , HashMap < String , String > params ) throws JSONException { return oClient . get ( "/finreports/v2/buyer_companies/" + buyerCompanyReference + "/billings" , params ) ; }
Generate Billing Reports for a Specific Buyer s Company
4,891
public JSONObject getByCompany ( String company , String fromDate , String tillDate , HashMap < String , String > params ) throws JSONException { return oClient . get ( "/team/v3/workdays/companies/" + company + "/" + fromDate + "," + tillDate , params ) ; }
Get Workdays by Company
4,892
public JSONObject getByContract ( String contract , String fromDate , String tillDate , HashMap < String , String > params ) throws JSONException { return oClient . get ( "/team/v3/workdays/contracts/" + contract + "/" + fromDate + "," + tillDate , params ) ; }
Get Workdays by Contract
4,893
public JSONObject postJob ( HashMap < String , String > params ) throws JSONException { return oClient . post ( "/hr/v2/jobs" , params ) ; }
Post a new job
4,894
public JSONObject editJob ( String key , HashMap < String , String > params ) throws JSONException { return oClient . put ( "/hr/v2/jobs/" + key , params ) ; }
Edit existent job
4,895
public JSONObject deleteJob ( String key , HashMap < String , String > params ) throws JSONException { return oClient . delete ( "/hr/v2/jobs/" + key , params ) ; }
Delete existent job
4,896
public JSONObject getList ( HashMap < String , String > params ) throws JSONException { return oClient . get ( "/offers/v1/clients/offers" , params ) ; }
Get list of offers
4,897
public JSONObject getSpecific ( String reference , HashMap < String , String > params ) throws JSONException { return oClient . get ( "/offers/v1/clients/offers/" + reference , params ) ; }
Get specific offer
4,898
public JSONObject getByAgency ( String company , String agency , HashMap < String , String > params ) throws JSONException { return _getByType ( company , null , agency , params , false ) ; }
Generating Agency Specific Reports
4,899
public JSONObject getByCompany ( String company , HashMap < String , String > params ) throws JSONException { return _getByType ( company , null , null , params , false ) ; }
Generating Company Wide Reports