Strategy for overloading game loop context handling

@throws SlickException Indicates a game failure
171008
protected void gameLoop() throws SlickException {
		int delta = getDelta();
		if (!Display.isVisible() && updateOnlyOnVisible) {
			try { Thread.sleep(100); } catch (Exception e) {}
		} else {
			try {
				updateAndRender(delta);
			} catch (SlickException e) {
				Log.error(e);
				running = false;
				return;
			}
		}

		updateFPS();

		Display.update();
		
		if (Display.isCloseRequested()) {
			if (game.closeRequested()) {
				running = false;
			}
		}
	}
1085386
private void invoke(Method method, Object instance, Object[] params) throws SlickXMLException {
		try {
			method.setAccessible(true);
			method.invoke(instance, params);
		} catch (IllegalArgumentException e) {
			throw new SlickXMLException("Failed to invoke: "+method+" for an XML attribute, is it valid?", e);
		} catch (IllegalAccessException e) {
			throw new SlickXMLException("Failed to invoke: "+method+" for an XML attribute, is it valid?", e);
		} catch (InvocationTargetException e) {
			throw new SlickXMLException("Failed to invoke: "+method+" for an XML attribute, is it valid?", e);
		} finally {
			method.setAccessible(false);
		}
	}
485737
void handleGet(Object value, 
                 MatchSpaceKey msg, 
                 EvalCache cache,
                 Object contextValue,
                 SearchResults result) 
      throws MatchingException, BadMessageFormatMatchingException 
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      tc.entry(this,
               cclass, 
               "handleGet", 
               new Object[] {value,msg,cache,contextValue,result});
    
    // Call the handleGet() method in the parent class but 
    // provide a context and we may need to call it multiple times
    if (value != null && value instanceof SetValEvaluationContext)
    {
      // The "value" we get back is a list of wrapped string values and
      // DOM nodes that we need to process individually
      ArrayList nodeList = ((SetValEvaluationContext)value).getWrappedNodeList();
      
      // Iterate over the nodes that were passed into us
      Iterator iter = nodeList.iterator();

      while(iter.hasNext())
      {
        WrappedNodeResults wrappedNode = (WrappedNodeResults)iter.next();
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
          tc.debug(this,cclass, "handleGet", "Processing node: " + wrappedNode); 
        
        // Need to be careful here, we propagate a Number, but the
        // context for subsequent operations is the parent node.
        // We retrieve a list of numbers each of which are processed
        // in turn
        ArrayList numberList = wrappedNode.getNumberList(id.getName());
        if(numberList != null)
        {
          Iterator iterNumber= numberList.iterator();
          
          while(iterNumber.hasNext())
          {
            Number num = (Number)iterNumber.next();

            // Need to pass in an XPathEvaluationContext
            SetValEvaluationContext xpEval = new SetValEvaluationContext(wrappedNode);
      
            super.handleGet(num, msg, cache, xpEval, result);
          } // eof while             
        } // eof if numberList not null        
      } // eof iteration over nodes
    } // value not null
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      tc.exit(this,cclass, "handleGet");    
  }
867906
private void init() throws SlickException {
		IntBuffer buffer = BufferUtils.createIntBuffer(1);
		EXTFramebufferObject.glGenFramebuffersEXT(buffer); 
		FBO = buffer.get();

		// for some reason FBOs won't work on textures unless you've absolutely just
		// created them.
		try {
			Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter());
			
			EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, FBO);
			EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 
														   EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT,
														   GL11.GL_TEXTURE_2D, tex.getTextureID(), 0);
			
			completeCheck();
			unbind();
			
			// Clear our destination area before using it
			clear();
			flush();
			
			// keep hold of the original content
			drawImage(image, 0, 0);
			image.setTexture(tex);
			
		} catch (Exception e) {
			throw new SlickException("Failed to create new texture for FBO");
		}
	}
1214655
protected void onException(SQLListenerContextImpl context, Exception e) {
        context.setException(e);
        listeners.exception(context);
    }
1244798
public void execute() throws MojoExecutionException {
        super.execute();
        try {
            lambdaFunctions.forEach(context -> {
                try {
                    deleteTriggers.andThen(deleteFunction).apply(
                            context.withFunctionArn(lambdaClient.getFunction(new GetFunctionRequest()
                                .withFunctionName(context.getFunctionName())).getConfiguration().getFunctionArn()));                      
                } catch (Exception e) {
                    getLog().error(e.getMessage());
                }
            });
        } catch (Exception e) {
            getLog().error(e.getMessage(), e);
        }
    }
782160
private void handleThrows() {
    Scope curScope = scope;
    while (curScope != null) {
      if (curScope.kind == Scope.Kind.TRY) {
        scope.mergeInto(curScope.next);
      }
      curScope = curScope.next;
    }
  }
1272059
static void accessFailed() throws Throwable
    {
        String controllerClassName = getControllerClass().getName();
        Logger.debug("Deadbolt: Access failure on [%s]",
                     controllerClassName);

        String responseFormat = null;
        if (getActionAnnotation(JSON.class) != null)
        {
            responseFormat = "json";
        }
        else if (getActionAnnotation(XML.class) != null)
        {
            responseFormat = "xml";
        }
        else if (getControllerAnnotation(JSON.class) != null)
        {
            responseFormat = "json";
        }
        else if (getControllerAnnotation(XML.class) != null)
        {
            responseFormat = "xml";
        }
        else
        {
            String defaultResponseFormat = Play.configuration.getProperty(DEFAULT_RESPONSE_FORMAT);
            if (!isEmpty(defaultResponseFormat))
            {
                responseFormat = defaultResponseFormat;
            }
        }

        if (!isEmpty(responseFormat))
        {
            request.format = responseFormat;
        }

        DEADBOLT_HANDLER.onAccessFailure(controllerClassName);

    }
1253450
public synchronized void execute() throws MojoExecutionException, MojoFailureException {
        try {
            doExecute();
        }
        catch (Exception e) {
            //
            // NOTE: Wrap to avoid truncating the stacktrace
            //

            if (e instanceof MojoExecutionException) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
            else if (e instanceof MojoFailureException) {
                MojoFailureException x = new MojoFailureException(e.getMessage());
                x.initCause(e);
                throw x;
            }
            else {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        }
    }
1122453
private void loadLoop() throws InterruptedException {
        boolean firstItem = true;
        boolean moreAvailable = true;

        // Loop until all loaded.
        while (moreAvailable) {
            // Thread interruptions terminate the loop.
            if (currentThread().isInterrupted()) {
                throw new InterruptedException();
            }
            try {
                setLoading(true);

                // Load next increment of items.
                final Result<? extends T> result = load();
                moreAvailable = result != null && result.getRemaining() > 0;
                setAvailable(result != null ? result.getRemaining() : 0);

                // If invalidated while shown, we lazily clear the data so the user doesn't see blank data while loading.
                final boolean needToClear = firstItem;
                firstItem = false;
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        List<? extends T> elements =
                                result != null ? result.getElements() : Collections.<T>emptyList();
                        if (needToClear) {
                            overwriteResult(elements);
                        } else {
                            appendResult(elements);
                        }
                        setLoading(false);
                    }
                });
            } catch (InterruptedException e) {
                throw e;
            } catch (InterruptedIOException e) {
                InterruptedException interruptedException = new InterruptedException();
                interruptedException.initCause(e);
                throw interruptedException;
            } catch (final Throwable e) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        notifyError(e);
                    }
                });
                mError = true;
                setLoading(false);
            }

            // Block until instructed to continue, even if an error occurred.
            // In this case, loading must be explicitly resumed.
            block();
        }
    }
464838
private void scheduleUpdate() {
		if (!isVisible()) {
			return;
		}
		
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				try {
					container.gameLoop();
				} catch (SlickException e) {
					e.printStackTrace();
				}
				container.checkDimensions();
				scheduleUpdate();
			}
		});
	}
569924
@Override
    public void visitClassContext(ClassContext classContext) {

        try {
            if ((collectionClass == null) || (mapClass == null)) {
                return;
            }
            stack = new OpcodeStack();
            fieldUserValues = new HashMap<>();
            classContext.getJavaClass().accept(this);
        } finally {
            fieldUserValues = null;
            stack = null;
        }
    }
691911
private void throwQError(final QConnectorError e) {
		this.executor.execute(new Runnable() {
			
			@Override
			public void run() {
				QConnectorAsyncImpl.this.listener.error(e);
			}
		});
	}
940129
public static void initExceptionHandler(Context context) {

        Log.d("AppRate", "Init AppRate ExceptionHandler");

        Thread.UncaughtExceptionHandler currentHandler = Thread.getDefaultUncaughtExceptionHandler();

        // Don't register again if already registered.
        if (!(currentHandler instanceof ExceptionHandler)) {

            // Register default exceptions handler.
            Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(currentHandler, context));
        }
    }
1320847
@Override
    public void visitClassContext(ClassContext classContext) {
        try {
            ignoreRegs = new BitSet();
            tryBlocks = new BitSet();
            catchHandlers = new BitSet();
            switchTargets = new BitSet();
            monitorSyncPCs = new ArrayList<>(5);
            stack = new OpcodeStack();
            super.visitClassContext(classContext);
        } finally {
            ignoreRegs = null;
            tryBlocks = null;
            catchHandlers = null;
            switchTargets = null;
            monitorSyncPCs = null;
            stack = null;
        }
    }
651398
private void handleRequest(long requestId, Object request, HandlerHolder handler) {
    @SuppressWarnings("unchecked")
    CompletableFuture<Object> responseFuture = handler.handler.apply(request);
    if (responseFuture != null) {
      responseFuture.whenComplete((response, error) -> {
        ThreadContext context = ThreadContext.currentContext();
        if (context == null) {
          this.context.executor().execute(() -> {
            if (error == null) {
              handleRequestSuccess(requestId, response, this.context);
            } else {
              handleRequestFailure(requestId, error, this.context);
            }
          });
        } else {
          if (error == null) {
            handleRequestSuccess(requestId, response, context);
          } else {
            handleRequestFailure(requestId, error, context);
          }
        }
      });
    }
  }
1140215
private static <E extends RuntimeException> E handleException(E ex) {
        if (JodaTime.hasExpectedBehavior())
            return ex;
        throw new IllegalStateException("Joda-time 2.2 or later version is required, but found version: " + JodaTime.getVersion(), ex);
    }