idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
25,300 | private void performDownload ( HttpResponse response , File destFile ) throws IOException { HttpEntity entity = response . getEntity ( ) ; if ( entity == null ) { return ; } long contentLength = entity . getContentLength ( ) ; if ( contentLength >= 0 ) { size = toLengthText ( contentLength ) ; } processedBytes = 0 ; lo... | Save an HTTP response to a file |
25,301 | private void stream ( InputStream is , File destFile ) throws IOException { try { startProgress ( ) ; OutputStream os = new FileOutputStream ( destFile ) ; boolean finished = false ; try { byte [ ] buf = new byte [ 1024 * 10 ] ; int read ; while ( ( read = is . read ( buf ) ) >= 0 ) { os . write ( buf , 0 , read ) ; pr... | Copy bytes from an input stream to a file and log progress |
25,302 | private String getCachedETag ( HttpHost host , String file ) { Map < String , Object > cachedETags = readCachedETags ( ) ; @ SuppressWarnings ( "unchecked" ) Map < String , Object > hostMap = ( Map < String , Object > ) cachedETags . get ( host . toURI ( ) ) ; if ( hostMap == null ) { return null ; } @ SuppressWarnings... | Get the cached ETag for the given host and file |
25,303 | private File makeDestFile ( URL src ) { if ( dest == null ) { throw new IllegalArgumentException ( "Please provide a download destination" ) ; } File destFile = dest ; if ( destFile . isDirectory ( ) ) { String name = src . toString ( ) ; if ( name . endsWith ( "/" ) ) { name = name . substring ( 0 , name . length ( ) ... | Generates the path to an output file for a given source URL . Creates all necessary parent directories for the destination file . |
25,304 | private void addAuthentication ( HttpHost host , Credentials credentials , AuthScheme authScheme , HttpClientContext context ) { AuthCache authCache = context . getAuthCache ( ) ; if ( authCache == null ) { authCache = new BasicAuthCache ( ) ; context . setAuthCache ( authCache ) ; } CredentialsProvider credsProvider =... | Add authentication information for the given host |
25,305 | private String toLengthText ( long bytes ) { if ( bytes < 1024 ) { return bytes + " B" ; } else if ( bytes < 1024 * 1024 ) { return ( bytes / 1024 ) + " KB" ; } else if ( bytes < 1024 * 1024 * 1024 ) { return String . format ( "%.2f MB" , bytes / ( 1024.0 * 1024.0 ) ) ; } else { return String . format ( "%.2f GB" , byt... | Converts a number of bytes to a human - readable string |
25,306 | public void close ( ) throws IOException { for ( CloseableHttpClient c : cachedClients . values ( ) ) { c . close ( ) ; } cachedClients . clear ( ) ; } | Close all HTTP clients created by this factory |
25,307 | public static Provider getCurrentProvider ( boolean useSwingEventQueue ) { Provider provider ; if ( Platform . isX11 ( ) ) { provider = new X11Provider ( ) ; } else if ( Platform . isWindows ( ) ) { provider = new WindowsProvider ( ) ; } else if ( Platform . isMac ( ) ) { provider = new CarbonProvider ( ) ; } else { LO... | Get global hotkey provider for current platform |
25,308 | protected void fireEvent ( HotKey hotKey ) { HotKeyEvent event = new HotKeyEvent ( hotKey ) ; if ( useSwingEventQueue ) { SwingUtilities . invokeLater ( event ) ; } else { if ( eventQueue == null ) { eventQueue = Executors . newSingleThreadExecutor ( ) ; } eventQueue . execute ( event ) ; } } | Helper method fro providers to fire hotkey event in a separate thread |
25,309 | public Object newInstance ( String resource ) { try { String name = resource . startsWith ( "/" ) ? resource : "/" + resource ; File file = new File ( this . getClass ( ) . getResource ( name ) . toURI ( ) ) ; return newInstance ( classLoader . parseClass ( new GroovyCodeSource ( file ) , true ) ) ; } catch ( Exception... | Creates an object instance from the Groovy resource |
25,310 | private void addTypes ( Injector injector , List < Class < ? > > types ) { for ( Binding < ? > binding : injector . getBindings ( ) . values ( ) ) { Key < ? > key = binding . getKey ( ) ; Type type = key . getTypeLiteral ( ) . getType ( ) ; if ( hasAnnotatedMethods ( type ) ) { types . add ( ( ( Class < ? > ) type ) ) ... | Adds steps types from given injector and recursively its parent |
25,311 | public void map ( Story story , MetaFilter metaFilter ) { if ( metaFilter . allow ( story . getMeta ( ) ) ) { boolean allowed = false ; for ( Scenario scenario : story . getScenarios ( ) ) { Meta inherited = scenario . getMeta ( ) . inheritFrom ( story . getMeta ( ) ) ; if ( metaFilter . allow ( inherited ) ) { allowed... | Maps a story if it is allowed by the meta filter |
25,312 | protected MetaMatcher createMetaMatcher ( String filterAsString , Map < String , MetaMatcher > metaMatchers ) { for ( String key : metaMatchers . keySet ( ) ) { if ( filterAsString . startsWith ( key ) ) { return metaMatchers . get ( key ) ; } } if ( filterAsString . startsWith ( GROOVY ) ) { return new GroovyMetaMatch... | Creates a MetaMatcher based on the filter content . |
25,313 | public static URL codeLocationFromClass ( Class < ? > codeLocationClass ) { String pathOfClass = codeLocationClass . getName ( ) . replace ( "." , "/" ) + ".class" ; URL classResource = codeLocationClass . getClassLoader ( ) . getResource ( pathOfClass ) ; String codeLocationPath = removeEnd ( getPathFromURL ( classRes... | Creates a code location URL from a class |
25,314 | public static URL codeLocationFromPath ( String filePath ) { try { return new File ( filePath ) . toURI ( ) . toURL ( ) ; } catch ( Exception e ) { throw new InvalidCodeLocation ( filePath ) ; } } | Creates a code location URL from a file path |
25,315 | public static URL codeLocationFromURL ( String url ) { try { return new URL ( url ) ; } catch ( Exception e ) { throw new InvalidCodeLocation ( url ) ; } } | Creates a code location URL from a URL |
25,316 | public void run ( Configuration configuration , List < CandidateSteps > candidateSteps , Story story ) throws Throwable { run ( configuration , candidateSteps , story , MetaFilter . EMPTY ) ; } | Runs a Story with the given configuration and steps . |
25,317 | public void run ( Configuration configuration , List < CandidateSteps > candidateSteps , Story story , MetaFilter filter ) throws Throwable { run ( configuration , candidateSteps , story , filter , null ) ; } | Runs a Story with the given configuration and steps applying the given meta filter . |
25,318 | public void run ( Configuration configuration , List < CandidateSteps > candidateSteps , Story story , MetaFilter filter , State beforeStories ) throws Throwable { run ( configuration , new ProvidedStepsFactory ( candidateSteps ) , story , filter , beforeStories ) ; } | Runs a Story with the given configuration and steps applying the given meta filter and staring from given state . |
25,319 | public void run ( Configuration configuration , InjectableStepsFactory stepsFactory , Story story , MetaFilter filter , State beforeStories ) throws Throwable { RunContext context = new RunContext ( configuration , stepsFactory , story . getPath ( ) , filter ) ; if ( beforeStories != null ) { context . stateIs ( before... | Runs a Story with the given steps factory applying the given meta filter and staring from given state . |
25,320 | public Story storyOfPath ( Configuration configuration , String storyPath ) { String storyAsText = configuration . storyLoader ( ) . loadStoryAsText ( storyPath ) ; return configuration . storyParser ( ) . parseStory ( storyAsText , storyPath ) ; } | Returns the parsed story from the given path |
25,321 | public Story storyOfText ( Configuration configuration , String storyAsText , String storyId ) { return configuration . storyParser ( ) . parseStory ( storyAsText , storyId ) ; } | Returns the parsed story from the given text |
25,322 | public Object newInstance ( String className ) { try { return classLoader . loadClass ( className ) . newInstance ( ) ; } catch ( Exception e ) { throw new ScalaInstanceNotFound ( className ) ; } } | Creates an object instance from the Scala class name |
25,323 | public Map < String , String > values ( ) { Map < String , String > values = new LinkedHashMap < > ( ) ; for ( Row each : delegates ) { for ( Entry < String , String > entry : each . values ( ) . entrySet ( ) ) { String name = entry . getKey ( ) ; if ( ! values . containsKey ( name ) ) { values . put ( name , entry . g... | Returns values aggregated from all the delegates without overriding values that already exist . |
25,324 | public List < Object > stepsInstances ( List < CandidateSteps > candidateSteps ) { List < Object > instances = new ArrayList < > ( ) ; for ( CandidateSteps steps : candidateSteps ) { if ( steps instanceof Steps ) { instances . add ( ( ( Steps ) steps ) . instance ( ) ) ; } } return instances ; } | Returns the steps instances associated to CandidateSteps |
25,325 | public List < StepCandidate > prioritise ( String stepAsText , List < StepCandidate > candidates ) { return prioritisingStrategy . prioritise ( stepAsText , candidates ) ; } | Prioritises the list of step candidates that match a given step . |
25,326 | protected String format ( String key , String defaultPattern , Object ... args ) { String escape = escape ( defaultPattern ) ; String s = lookupPattern ( key , escape ) ; Object [ ] objects = escapeAll ( args ) ; return MessageFormat . format ( s , objects ) ; } | Formats event output by key usually equal to the method name . |
25,327 | protected Object [ ] escape ( final Format format , Object ... args ) { Transformer < Object , Object > escapingTransformer = new Transformer < Object , Object > ( ) { public Object transform ( Object object ) { return format . escapeValue ( object ) ; } } ; List < Object > list = Arrays . asList ( ArrayUtils . clone (... | Escapes args string values according to format |
25,328 | protected void print ( String text ) { String tableStart = format ( PARAMETER_TABLE_START , PARAMETER_TABLE_START ) ; String tableEnd = format ( PARAMETER_TABLE_END , PARAMETER_TABLE_END ) ; boolean containsTable = text . contains ( tableStart ) && text . contains ( tableEnd ) ; String textToPrint = containsTable ? tra... | Prints text to output stream replacing parameter start and end placeholders |
25,329 | private List < ParameterConverter > methodReturningConverters ( final Class < ? > type ) { final List < ParameterConverter > converters = new ArrayList < > ( ) ; for ( final Method method : type . getMethods ( ) ) { if ( method . isAnnotationPresent ( AsParameterConverter . class ) ) { converters . add ( new MethodRetu... | Create parameter converters from methods annotated with |
25,330 | static InjectionProvider < ? > [ ] toArray ( final Set < InjectionProvider < ? > > injectionProviders ) { return injectionProviders . toArray ( new InjectionProvider < ? > [ injectionProviders . size ( ) ] ) ; } | Set to array . |
25,331 | public Trader retrieveTrader ( String name ) { for ( Trader trader : traders ) { if ( trader . getName ( ) . equals ( name ) ) { return trader ; } } return mockTradePersister ( ) . retrieveTrader ( name ) ; } | Method used as dynamical parameter converter |
25,332 | private Class < ? > beanType ( String name ) { Class < ? > type = context . getType ( name ) ; if ( ClassUtils . isCglibProxyClass ( type ) ) { return AopProxyUtils . ultimateTargetClass ( context . getBean ( name ) ) ; } return type ; } | Return the bean type untangling the proxy if needed |
25,333 | private boolean findBinding ( Injector injector , Class < ? > type ) { boolean found = false ; for ( Key < ? > key : injector . getBindings ( ) . keySet ( ) ) { if ( key . getTypeLiteral ( ) . getRawType ( ) . equals ( type ) ) { found = true ; break ; } } if ( ! found && injector . getParent ( ) != null ) { return fin... | Finds binding for a type in the given injector and if not found recurses to its parent |
25,334 | public List < String > scan ( ) { try { JarFile jar = new JarFile ( jarURL . getFile ( ) ) ; try { List < String > result = new ArrayList < > ( ) ; Enumeration < JarEntry > en = jar . entries ( ) ; while ( en . hasMoreElements ( ) ) { JarEntry entry = en . nextElement ( ) ; String path = entry . getName ( ) ; boolean m... | Scans the jar file and returns the paths that match the includes and excludes . |
25,335 | public String getMethodSignature ( ) { if ( method != null ) { String methodSignature = method . toString ( ) ; return methodSignature . replaceFirst ( "public void " , "" ) ; } return null ; } | Method signature without public void prefix |
25,336 | public Configuration configuration ( ) { return new MostUsefulConfiguration ( ) . useStoryLoader ( new LoadFromClasspath ( this . getClass ( ) ) ) . useStoryReporterBuilder ( new StoryReporterBuilder ( ) . withDefaultFormats ( ) . withFormats ( Format . CONSOLE , Format . TXT ) ) ; } | Here we specify the configuration starting from default MostUsefulConfiguration and changing only what is needed |
25,337 | public GetAssignmentGroupOptions includes ( List < Include > includes ) { List < Include > assignmentDependents = Arrays . asList ( Include . DISCUSSION_TOPIC , Include . ASSIGNMENT_VISIBILITY , Include . SUBMISSION ) ; if ( includes . stream ( ) . anyMatch ( assignmentDependents :: contains ) && ! includes . contains ... | Additional objects to include with the requested group . Note that all the optional includes depend on assignments also being included . |
25,338 | private void ensureToolValidForCreation ( ExternalTool tool ) { if ( StringUtils . isAnyBlank ( tool . getName ( ) , tool . getPrivacyLevel ( ) , tool . getConsumerKey ( ) , tool . getSharedSecret ( ) ) ) { throw new IllegalArgumentException ( "External tool requires all of the following for creation: name, privacy lev... | Ensure that a tool object is valid for creation . The API requires certain fields to be filled out . Throws an IllegalArgumentException if the conditions are not met . |
25,339 | public GetSingleConversationOptions filters ( List < String > filters ) { if ( filters . size ( ) == 1 ) { addSingleItem ( "filter" , filters . get ( 0 ) ) ; } else { optionsMap . put ( "filter[]" , filters ) ; } return this ; } | Used when setting the visible field in the response . See the List Conversations docs for details |
25,340 | public < T extends CanvasReader > T getReader ( Class < T > type , OauthToken oauthToken ) { return getReader ( type , oauthToken , null ) ; } | Get a reader implementation class to perform API calls with . |
25,341 | public < T extends CanvasReader > T getReader ( Class < T > type , OauthToken oauthToken , Integer paginationPageSize ) { LOG . debug ( "Factory call to instantiate class: " + type . getName ( ) ) ; RestClient restClient = new RefreshingRestClient ( ) ; @ SuppressWarnings ( "unchecked" ) Class < T > concreteClass = ( C... | Get a reader implementation class to perform API calls with while specifying an explicit page size for paginated API calls . This gets translated to a per_page = parameter on API requests . Note that Canvas does not guarantee it will honor this page size request . There is an explicit maximum page size on the server si... |
25,342 | public < T extends CanvasWriter > T getWriter ( Class < T > type , OauthToken oauthToken ) { return getWriter ( type , oauthToken , false ) ; } | Get a writer implementation to push data into Canvas . |
25,343 | public < T extends CanvasWriter > T getWriter ( Class < T > type , OauthToken oauthToken , Boolean serializeNulls ) { LOG . debug ( "Factory call to instantiate class: " + type . getName ( ) ) ; RestClient restClient = new RefreshingRestClient ( ) ; @ SuppressWarnings ( "unchecked" ) Class < T > concreteClass = ( Class... | Get a writer implementation to push data into Canvas while being able to control the behavior of blank values . If the serializeNulls parameter is set to true this writer will serialize null fields in the JSON being sent to Canvas . This is required if you want to explicitly blank out a value that is currently set to s... |
25,344 | public ListActiveCoursesInAccountOptions searchTerm ( String searchTerm ) { if ( searchTerm == null || searchTerm . length ( ) < 3 ) { throw new IllegalArgumentException ( "Search term must be at least 3 characters" ) ; } addSingleItem ( "search_term" , searchTerm ) ; return this ; } | Filter on a search term . Can be course name code or full ID . Must be at least 3 characters |
25,345 | public ListExternalToolsOptions searchTerm ( String searchTerm ) { if ( searchTerm == null || searchTerm . length ( ) < 3 ) { throw new IllegalArgumentException ( "Search term must be at least 3 characters" ) ; } addSingleItem ( "search_term" , searchTerm ) ; return this ; } | Only return tools with a name matching this partial string |
25,346 | private List < EnrollmentTerm > parseEnrollmentTermList ( final List < Response > responses ) { return responses . stream ( ) . map ( this :: parseEnrollmentTermList ) . flatMap ( Collection :: stream ) . collect ( Collectors . toList ( ) ) ; } | a useless object at the top level of the response JSON for no reason at all . |
25,347 | private Response sendJsonPostOrPut ( OauthToken token , String url , String json , int connectTimeout , int readTimeout , String method ) throws IOException { LOG . debug ( "Sending JSON " + method + " to URL: " + url ) ; Response response = new Response ( ) ; HttpClient httpClient = createHttpClient ( connectTimeout ,... | PUT and POST are identical calls except for the header specifying the method |
25,348 | protected void addEnumList ( String key , List < ? extends Enum > list ) { optionsMap . put ( key , list . stream ( ) . map ( i -> i . toString ( ) ) . collect ( Collectors . toList ( ) ) ) ; } | Add a list of enums to the options map |
25,349 | public void setLargePayloadSupportEnabled ( AmazonS3 s3 , String s3BucketName ) { if ( s3 == null || s3BucketName == null ) { String errorMessage = "S3 client and/or S3 bucket name cannot be null." ; LOG . error ( errorMessage ) ; throw new AmazonClientException ( errorMessage ) ; } if ( isLargePayloadSupportEnabled ( ... | Enables support for large - payload messages . |
25,350 | private String readLine ( boolean trim ) throws IOException { boolean done = false ; boolean sawCarriage = false ; int removalBytes = 0 ; while ( ! done ) { if ( isReadBufferEmpty ( ) ) { offset = 0 ; end = 0 ; int bytesRead = inputStream . read ( buffer , end , Math . min ( DEFAULT_READ_COUNT , buffer . length - end )... | Reads a line from the input stream where a line is terminated by \ r \ n or \ r \ n |
25,351 | private void copyToStrBuffer ( byte [ ] buffer , int offset , int length ) { Preconditions . checkArgument ( length >= 0 ) ; if ( strBuffer . length - strBufferIndex < length ) { expandStrBuffer ( length ) ; } System . arraycopy ( buffer , offset , strBuffer , strBufferIndex , Math . min ( length , MAX_ALLOWABLE_BUFFER... | Copies from buffer to our internal strBufferIndex expanding the internal buffer if necessary |
25,352 | public String read ( int numBytes ) throws IOException { Preconditions . checkArgument ( numBytes >= 0 ) ; Preconditions . checkArgument ( numBytes <= MAX_ALLOWABLE_BUFFER_SIZE ) ; int numBytesRemaining = numBytes ; if ( ! isReadBufferEmpty ( ) ) { int length = Math . min ( end - offset , numBytesRemaining ) ; copyToSt... | Reads numBytes bytes and returns the corresponding string |
25,353 | public DefaultStreamingEndpoint languages ( List < String > languages ) { addPostParameter ( Constants . LANGUAGE_PARAM , Joiner . on ( ',' ) . join ( languages ) ) ; return this ; } | Filter for public tweets on these languages . |
25,354 | public void process ( ) { if ( client . isDone ( ) || executorService . isTerminated ( ) ) { throw new IllegalStateException ( "Client is already stopped" ) ; } Runnable runner = new Runnable ( ) { public void run ( ) { try { while ( ! client . isDone ( ) ) { String msg = messageQueue . take ( ) ; try { parseMessage ( ... | Forks off a runnable with the executor provided . Multiple calls are allowed but the listeners must be threadsafe . |
25,355 | public void stop ( int waitMillis ) throws InterruptedException { try { if ( ! isDone ( ) ) { setExitStatus ( new Event ( EventType . STOPPED_BY_USER , String . format ( "Stopped by user: waiting for %d ms" , waitMillis ) ) ) ; } if ( ! waitForFinish ( waitMillis ) ) { logger . warn ( "{} Client thread failed to finish... | Stops the current connection . No reconnecting will occur . Kills thread + cleanup . Waits for the loop to end |
25,356 | public void fireEvent ( final WorkerEvent event , final Worker worker , final String queue , final Job job , final Object runner , final Object result , final Throwable t ) { final ConcurrentSet < WorkerListener > listeners = this . eventListenerMap . get ( event ) ; if ( listeners != null ) { for ( final WorkerListene... | Notify all WorkerListeners currently registered for the given WorkerEvent . |
25,357 | public static List < String > createBacktrace ( final Throwable t ) { final List < String > bTrace = new LinkedList < String > ( ) ; for ( final StackTraceElement ste : t . getStackTrace ( ) ) { bTrace . add ( BT_PREFIX + ste . toString ( ) ) ; } if ( t . getCause ( ) != null ) { addCauseToBacktrace ( t . getCause ( ) ... | Creates a Resque backtrace from a Throwable s stack trace . Includes causes . |
25,358 | private static void addCauseToBacktrace ( final Throwable cause , final List < String > bTrace ) { if ( cause . getMessage ( ) == null ) { bTrace . add ( BT_CAUSED_BY_PREFIX + cause . getClass ( ) . getName ( ) ) ; } else { bTrace . add ( BT_CAUSED_BY_PREFIX + cause . getClass ( ) . getName ( ) + ": " + cause . getMess... | Add a cause to the backtrace . |
25,359 | public static < K , V > Map < K , V > map ( final Entry < ? extends K , ? extends V > ... entries ) { final Map < K , V > map = new LinkedHashMap < K , V > ( entries . length ) ; for ( final Entry < ? extends K , ? extends V > entry : entries ) { map . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } return map ; ... | A convenient way of creating a map on the fly . |
25,360 | public static < K > Set < K > set ( final K ... keys ) { return new LinkedHashSet < K > ( Arrays . asList ( keys ) ) ; } | Creates a Set out of the given keys |
25,361 | public static boolean nullSafeEquals ( final Object obj1 , final Object obj2 ) { return ( ( obj1 == null && obj2 == null ) || ( obj1 != null && obj2 != null && obj1 . equals ( obj2 ) ) ) ; } | Test for equality . |
25,362 | private long size ( final Jedis jedis , final String queueName ) { final String key = key ( QUEUE , queueName ) ; final long size ; if ( JedisUtils . isDelayedQueue ( jedis , key ) ) { size = jedis . zcard ( key ) ; } else { size = jedis . llen ( key ) ; } return size ; } | Size of a queue . |
25,363 | private List < Job > getJobs ( final Jedis jedis , final String queueName , final long jobOffset , final long jobCount ) throws Exception { final String key = key ( QUEUE , queueName ) ; final List < Job > jobs = new ArrayList < > ( ) ; if ( JedisUtils . isDelayedQueue ( jedis , key ) ) { final Set < Tuple > elements =... | Get list of Jobs from a queue . |
25,364 | @ SuppressWarnings ( "unchecked" ) public void setVars ( final Map < String , ? extends Object > vars ) { this . vars = ( Map < String , Object > ) vars ; } | Set the named arguments . |
25,365 | public void setUnknownField ( final String name , final Object value ) { this . unknownFields . put ( name , value ) ; } | Set an unknown field . |
25,366 | public void setUnknownFields ( final Map < String , Object > unknownFields ) { this . unknownFields . clear ( ) ; this . unknownFields . putAll ( unknownFields ) ; } | Set all unknown fields |
25,367 | public void addJobType ( final String jobName , final Class < ? > jobType ) { checkJobType ( jobName , jobType ) ; this . jobTypes . put ( jobName , jobType ) ; } | Allow the given job type to be executed . |
25,368 | public void removeJobType ( final Class < ? > jobType ) { if ( jobType == null ) { throw new IllegalArgumentException ( "jobType must not be null" ) ; } this . jobTypes . values ( ) . remove ( jobType ) ; } | Disallow the job type from being executed . |
25,369 | public void setJobTypes ( final Map < String , ? extends Class < ? > > jobTypes ) { checkJobTypes ( jobTypes ) ; this . jobTypes . clear ( ) ; this . jobTypes . putAll ( jobTypes ) ; } | Clear any current allowed job types and use the given set . |
25,370 | protected void checkJobTypes ( final Map < String , ? extends Class < ? > > jobTypes ) { if ( jobTypes == null ) { throw new IllegalArgumentException ( "jobTypes must not be null" ) ; } for ( final Entry < String , ? extends Class < ? > > entry : jobTypes . entrySet ( ) ) { try { checkJobType ( entry . getKey ( ) , ent... | Verify the given job types are all valid . |
25,371 | protected void checkJobType ( final String jobName , final Class < ? > jobType ) { if ( jobName == null ) { throw new IllegalArgumentException ( "jobName must not be null" ) ; } if ( jobType == null ) { throw new IllegalArgumentException ( "jobType must not be null" ) ; } if ( ! ( Runnable . class . isAssignableFrom ( ... | Determine if a job name and job type are valid . |
25,372 | public static void doPublish ( final Jedis jedis , final String namespace , final String channel , final String jobJson ) { jedis . publish ( JesqueUtils . createKey ( namespace , CHANNEL , channel ) , jobJson ) ; } | Helper method that encapsulates the minimum logic for publishing a job to a channel . |
25,373 | public static < T > T createObject ( final Class < T > clazz , final Object ... args ) throws NoSuchConstructorException , AmbiguousConstructorException , ReflectiveOperationException { return findConstructor ( clazz , args ) . newInstance ( args ) ; } | Create an object of the given type using a constructor that matches the supplied arguments . |
25,374 | public static < T > T createObject ( final Class < T > clazz , final Object [ ] args , final Map < String , Object > vars ) throws NoSuchConstructorException , AmbiguousConstructorException , ReflectiveOperationException { return invokeSetters ( findConstructor ( clazz , args ) . newInstance ( args ) , vars ) ; } | Create an object of the given type using a constructor that matches the supplied arguments and invoke the setters with the supplied variables . |
25,375 | @ SuppressWarnings ( "rawtypes" ) private static < T > Constructor < T > findConstructor ( final Class < T > clazz , final Object ... args ) throws NoSuchConstructorException , AmbiguousConstructorException { final Object [ ] cArgs = ( args == null ) ? new Object [ 0 ] : args ; Constructor < T > constructorToUse = null... | Find a Constructor on the given type that matches the given arguments . |
25,376 | public static < T > T invokeSetters ( final T instance , final Map < String , Object > vars ) throws ReflectiveOperationException { if ( instance != null && vars != null ) { final Class < ? > clazz = instance . getClass ( ) ; final Method [ ] methods = clazz . getMethods ( ) ; for ( final Entry < String , Object > entr... | Invoke the setters for the given variables on the given instance . |
25,377 | protected static void checkQueues ( final Iterable < String > queues ) { if ( queues == null ) { throw new IllegalArgumentException ( "queues must not be null" ) ; } for ( final String queue : queues ) { if ( queue == null || "" . equals ( queue ) ) { throw new IllegalArgumentException ( "queues' members must not be nu... | Verify that the given queues are all valid . |
25,378 | protected String failMsg ( final Throwable thrwbl , final String queue , final Job job ) throws IOException { final JobFailure failure = new JobFailure ( ) ; failure . setFailedAt ( new Date ( ) ) ; failure . setWorker ( this . name ) ; failure . setQueue ( queue ) ; failure . setPayload ( job ) ; failure . setThrowabl... | Create and serialize a JobFailure . |
25,379 | protected String statusMsg ( final String queue , final Job job ) throws IOException { final WorkerStatus status = new WorkerStatus ( ) ; status . setRunAt ( new Date ( ) ) ; status . setQueue ( queue ) ; status . setPayload ( job ) ; return ObjectMapperFactory . get ( ) . writeValueAsString ( status ) ; } | Create and serialize a WorkerStatus . |
25,380 | protected String pauseMsg ( ) throws IOException { final WorkerStatus status = new WorkerStatus ( ) ; status . setRunAt ( new Date ( ) ) ; status . setPaused ( isPaused ( ) ) ; return ObjectMapperFactory . get ( ) . writeValueAsString ( status ) ; } | Create and serialize a WorkerStatus for a pause event . |
25,381 | protected String createName ( ) { final StringBuilder buf = new StringBuilder ( 128 ) ; try { buf . append ( InetAddress . getLocalHost ( ) . getHostName ( ) ) . append ( COLON ) . append ( ManagementFactory . getRuntimeMXBean ( ) . getName ( ) . split ( "@" ) [ 0 ] ) . append ( '-' ) . append ( this . workerId ) . app... | Creates a unique name suitable for use with Resque . |
25,382 | public void join ( final long millis ) throws InterruptedException { for ( final Thread thread : this . threads ) { thread . join ( millis ) ; } } | Join to internal threads and wait millis time per thread or until all threads are finished if millis is 0 . |
25,383 | protected static void checkChannels ( final Iterable < String > channels ) { if ( channels == null ) { throw new IllegalArgumentException ( "channels must not be null" ) ; } for ( final String channel : channels ) { if ( channel == null || "" . equals ( channel ) ) { throw new IllegalArgumentException ( "channels' memb... | Verify that the given channels are all valid . |
25,384 | public static < V > V doWorkInPool ( final Pool < Jedis > pool , final PoolWork < Jedis , V > work ) throws Exception { if ( pool == null ) { throw new IllegalArgumentException ( "pool must not be null" ) ; } if ( work == null ) { throw new IllegalArgumentException ( "work must not be null" ) ; } final V result ; final... | Perform the given work with a Jedis connection from the given pool . |
25,385 | public static < V > V doWorkInPoolNicely ( final Pool < Jedis > pool , final PoolWork < Jedis , V > work ) { final V result ; try { result = doWorkInPool ( pool , work ) ; } catch ( RuntimeException re ) { throw re ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } return result ; } | Perform the given work with a Jedis connection from the given pool . Wraps any thrown checked exceptions in a RuntimeException . |
25,386 | public static Pool < Jedis > createJedisPool ( final Config jesqueConfig , final GenericObjectPoolConfig poolConfig ) { if ( jesqueConfig == null ) { throw new IllegalArgumentException ( "jesqueConfig must not be null" ) ; } if ( poolConfig == null ) { throw new IllegalArgumentException ( "poolConfig must not be null" ... | A simple helper method that creates a pool of connections to Redis using the supplied configurations . |
25,387 | public static void doEnqueue ( final Jedis jedis , final String namespace , final String queue , final String jobJson ) { jedis . sadd ( JesqueUtils . createKey ( namespace , QUEUES ) , queue ) ; jedis . rpush ( JesqueUtils . createKey ( namespace , QUEUE , queue ) , jobJson ) ; } | Helper method that encapsulates the minimum logic for adding a job to a queue . |
25,388 | public static void doBatchEnqueue ( final Jedis jedis , final String namespace , final String queue , final List < String > jobJsons ) { Pipeline pipelined = jedis . pipelined ( ) ; pipelined . sadd ( JesqueUtils . createKey ( namespace , QUEUES ) , queue ) ; for ( String jobJson : jobJsons ) { pipelined . rpush ( Jesq... | Helper method that encapsulates the minimum logic for adding jobs to a queue . |
25,389 | public static void doPriorityEnqueue ( final Jedis jedis , final String namespace , final String queue , final String jobJson ) { jedis . sadd ( JesqueUtils . createKey ( namespace , QUEUES ) , queue ) ; jedis . lpush ( JesqueUtils . createKey ( namespace , QUEUE , queue ) , jobJson ) ; } | Helper method that encapsulates the minimum logic for adding a high priority job to a queue . |
25,390 | public static boolean doAcquireLock ( final Jedis jedis , final String namespace , final String lockName , final String lockHolder , final int timeout ) { final String key = JesqueUtils . createKey ( namespace , lockName ) ; String existingLockHolder = jedis . get ( key ) ; if ( ( existingLockHolder != null ) && existi... | Helper method that encapsulates the logic to acquire a lock . |
25,391 | public ConfigBuilder withHost ( final String host ) { if ( host == null || "" . equals ( host ) ) { throw new IllegalArgumentException ( "host must not be null or empty: " + host ) ; } this . host = host ; return this ; } | Configs created by this ConfigBuilder will have the given Redis hostname . |
25,392 | public ConfigBuilder withSentinels ( final Set < String > sentinels ) { if ( sentinels == null || sentinels . size ( ) < 1 ) { throw new IllegalArgumentException ( "sentinels is null or empty: " + sentinels ) ; } this . sentinels = sentinels ; return this ; } | Configs created by this ConfigBuilder will use the given Redis sentinels . |
25,393 | public ConfigBuilder withMasterName ( final String masterName ) { if ( masterName == null || "" . equals ( masterName ) ) { throw new IllegalArgumentException ( "masterName is null or empty: " + masterName ) ; } this . masterName = masterName ; return this ; } | Configs created by this ConfigBuilder will use the given Redis master name . |
25,394 | public static boolean ensureJedisConnection ( final Jedis jedis ) { final boolean jedisOK = testJedisConnection ( jedis ) ; if ( ! jedisOK ) { try { jedis . quit ( ) ; } catch ( Exception e ) { } try { jedis . disconnect ( ) ; } catch ( Exception e ) { } jedis . connect ( ) ; } return jedisOK ; } | Ensure that the given connection is established . |
25,395 | public static boolean reconnect ( final Jedis jedis , final int reconAttempts , final long reconnectSleepTime ) { int i = 1 ; do { try { jedis . disconnect ( ) ; try { Thread . sleep ( reconnectSleepTime ) ; } catch ( Exception e2 ) { } jedis . connect ( ) ; } catch ( JedisConnectionException jce ) { } catch ( Exceptio... | Attempt to reconnect to Redis . |
25,396 | public static boolean isRegularQueue ( final Jedis jedis , final String key ) { return LIST . equalsIgnoreCase ( jedis . type ( key ) ) ; } | Determines if the queue identified by the given key is a regular queue . |
25,397 | public static boolean isDelayedQueue ( final Jedis jedis , final String key ) { return ZSET . equalsIgnoreCase ( jedis . type ( key ) ) ; } | Determines if the queue identified by the given key is a delayed queue . |
25,398 | public static boolean isKeyUsed ( final Jedis jedis , final String key ) { return ! NONE . equalsIgnoreCase ( jedis . type ( key ) ) ; } | Determines if the queue identified by the given key is used . |
25,399 | public static boolean canUseAsDelayedQueue ( final Jedis jedis , final String key ) { final String type = jedis . type ( key ) ; return ( ZSET . equalsIgnoreCase ( type ) || NONE . equalsIgnoreCase ( type ) ) ; } | Determines if the queue identified by the given key can be used as a delayed queue . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.