Examples of AppContext

  • sisc.AppContext
  • sisc.interpreter.AppContext
  • sun.awt.AppContext
    The AppContext is a table referenced by ThreadGroup which stores application service instances. (If you are not writing an application service, or don't know what one is, please do not use this class.) The AppContext allows applet access to what would otherwise be potentially dangerous services, such as the ability to peek at EventQueues or change the look-and-feel of a Swing application.

    Most application services use a singleton object to provide their services, either as a default (such as getSystemEventQueue or getDefaultToolkit) or as static methods with class data (System). The AppContext works with the former method by extending the concept of "default" to be ThreadGroup-specific. Application services lookup their singleton in the AppContext.

    For example, here we have a Foo service, with its pre-AppContext code:

     public class Foo { private static Foo defaultFoo = new Foo(); public static Foo getDefaultFoo() { return defaultFoo; } ... Foo service methods }

    The problem with the above is that the Foo service is global in scope, so that applets and other untrusted code can execute methods on the single, shared Foo instance. The Foo service therefore either needs to block its use by untrusted code using a SecurityManager test, or restrict its capabilities so that it doesn't matter if untrusted code executes it.

    Here's the Foo class written to use the AppContext:

     public class Foo { public static Foo getDefaultFoo() { Foo foo = (Foo)AppContext.getAppContext().get(Foo.class); if (foo == null) { foo = new Foo(); getAppContext().put(Foo.class, foo); } return foo; } ... Foo service methods }

    Since a separate AppContext can exist for each ThreadGroup, trusted and untrusted code have access to different Foo instances. This allows untrusted code access to "system-wide" services -- the service remains within the AppContext "sandbox". For example, say a malicious applet wants to peek all of the key events on the EventQueue to listen for passwords; if separate EventQueues are used for each ThreadGroup using AppContexts, the only key events that applet will be able to listen to are its own. A more reasonable applet request would be to change the Swing default look-and-feel; with that default stored in an AppContext, the applet's look-and-feel will change without disrupting other applets or potentially the browser itself.

    Because the AppContext is a facility for safely extending application service support to applets, none of its methods may be blocked by a a SecurityManager check in a valid Java implementation. Applets may therefore safely invoke any of its methods without worry of being blocked. Note: If a SecurityManager is installed which derives from sun.awt.AWTSecurityManager, it may override the AWTSecurityManager.getAppContext() method to return the proper AppContext based on the execution context, in the case where the default ThreadGroup-based AppContext indexing would return the main "system" AppContext. For example, in an applet situation, if a system thread calls into an applet, rather than returning the main "system" AppContext (the one corresponding to the system thread), an installed AWTSecurityManager may return the applet's AppContext based on the execution context. @author Thomas Ball @author Fred Ecks


  • Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        }
      }

      @Test
      public void testFailure() throws Exception {
        AppContext mockContext = mock(AppContext.class);
        OutputCommitter mockCommitter = mock(OutputCommitter.class);
        Clock mockClock = mock(Clock.class);
       
        CommitterEventHandler handler = new CommitterEventHandler(mockContext,
            mockCommitter, new TestingRMHeartbeatHandler());
        YarnConfiguration conf = new YarnConfiguration();
        conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
        JobContext mockJobContext = mock(JobContext.class);
        ApplicationAttemptId attemptid =
          ConverterUtils.toApplicationAttemptId("appattempt_1234567890000_0001_0");
        JobId jobId =  TypeConverter.toYarn(
            TypeConverter.fromYarn(attemptid.getApplicationId()));
       
        WaitForItHandler waitForItHandler = new WaitForItHandler();
       
        when(mockContext.getApplicationID()).thenReturn(attemptid.getApplicationId());
        when(mockContext.getApplicationAttemptId()).thenReturn(attemptid);
        when(mockContext.getEventHandler()).thenReturn(waitForItHandler);
        when(mockContext.getClock()).thenReturn(mockClock);
       
        doThrow(new YarnRuntimeException("Intentional Failure")).when(mockCommitter)
          .commitJob(any(JobContext.class));
       
        handler.init(conf);
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        TestingJobEventHandler jeh = new TestingJobEventHandler();
        dispatcher.register(JobEventType.class, jeh);

        SystemClock clock = new SystemClock();
        AppContext appContext = mock(AppContext.class);
        ApplicationAttemptId attemptid =
          ConverterUtils.toApplicationAttemptId("appattempt_1234567890000_0001_0");
        when(appContext.getApplicationID()).thenReturn(attemptid.getApplicationId());
        when(appContext.getApplicationAttemptId()).thenReturn(attemptid);
        when(appContext.getEventHandler()).thenReturn(
            dispatcher.getEventHandler());
        when(appContext.getClock()).thenReturn(clock);
        OutputCommitter committer = mock(OutputCommitter.class);
        TestingRMHeartbeatHandler rmhh =
            new TestingRMHeartbeatHandler();

        CommitterEventHandler ceh = new CommitterEventHandler(appContext,
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        }
      }

      @Test
      public void testBasic() throws Exception {
        AppContext mockContext = mock(AppContext.class);
        OutputCommitter mockCommitter = mock(OutputCommitter.class);
        Clock mockClock = mock(Clock.class);
       
        CommitterEventHandler handler = new CommitterEventHandler(mockContext,
            mockCommitter, new TestingRMHeartbeatHandler());
        YarnConfiguration conf = new YarnConfiguration();
        conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
        JobContext mockJobContext = mock(JobContext.class);
        ApplicationAttemptId attemptid =
          ConverterUtils.toApplicationAttemptId("appattempt_1234567890000_0001_0");
        JobId jobId =  TypeConverter.toYarn(
            TypeConverter.fromYarn(attemptid.getApplicationId()));
       
        WaitForItHandler waitForItHandler = new WaitForItHandler();
       
        when(mockContext.getApplicationID()).thenReturn(attemptid.getApplicationId());
        when(mockContext.getApplicationAttemptId()).thenReturn(attemptid);
        when(mockContext.getEventHandler()).thenReturn(waitForItHandler);
        when(mockContext.getClock()).thenReturn(mockClock);
       
        handler.init(conf);
        handler.start();
        try {
          handler.handle(new CommitterJobCommitEvent(jobId, mockJobContext));
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        }
      }

      @Test
      public void testFailure() throws Exception {
        AppContext mockContext = mock(AppContext.class);
        OutputCommitter mockCommitter = mock(OutputCommitter.class);
        Clock mockClock = mock(Clock.class);
       
        CommitterEventHandler handler = new CommitterEventHandler(mockContext,
            mockCommitter, new TestingRMHeartbeatHandler());
        YarnConfiguration conf = new YarnConfiguration();
        conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir);
        JobContext mockJobContext = mock(JobContext.class);
        ApplicationAttemptId attemptid =
          ConverterUtils.toApplicationAttemptId("appattempt_1234567890000_0001_0");
        JobId jobId =  TypeConverter.toYarn(
            TypeConverter.fromYarn(attemptid.getApplicationId()));
       
        WaitForItHandler waitForItHandler = new WaitForItHandler();
       
        when(mockContext.getApplicationID()).thenReturn(attemptid.getApplicationId());
        when(mockContext.getApplicationAttemptId()).thenReturn(attemptid);
        when(mockContext.getEventHandler()).thenReturn(waitForItHandler);
        when(mockContext.getClock()).thenReturn(mockClock);
       
        doThrow(new YarnRuntimeException("Intentional Failure")).when(mockCommitter)
          .commitJob(any(JobContext.class));
       
        handler.init(conf);
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        LOG.info("Running testHeartbeatHandler");

        Configuration conf = new Configuration();
        conf.setInt(MRJobConfig.MR_AM_TO_RM_HEARTBEAT_INTERVAL_MS, 1);
        ControlledClock clock = new ControlledClock(new SystemClock());
        AppContext appContext = mock(AppContext.class);
        when(appContext.getClock()).thenReturn(clock);
        when(appContext.getApplicationID()).thenReturn(
            ApplicationId.newInstance(1, 1));

        RMContainerAllocator allocator = new RMContainerAllocator(
            mock(ClientService.class), appContext) {
              @Override
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        CommitterEventHandler commitHandler =
            createCommitterEventHandler(dispatcher, committer);
        commitHandler.init(conf);
        commitHandler.start();

        AppContext mockContext = mock(AppContext.class);
        when(mockContext.isLastAMRetry()).thenReturn(false);
        JobImpl job = createStubbedJob(conf, dispatcher, 2, mockContext);
        JobId jobId = job.getID();
        job.handle(new JobEvent(jobId, JobEventType.JOB_INIT));
        assertJobState(job, JobStateInternal.INITED);
        job.handle(new JobStartEvent(jobId));
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        CommitterEventHandler commitHandler =
            createCommitterEventHandler(dispatcher, committer);
        commitHandler.init(conf);
        commitHandler.start();

        AppContext mockContext = mock(AppContext.class);
        when(mockContext.isLastAMRetry()).thenReturn(true);
        when(mockContext.hasSuccessfullyUnregistered()).thenReturn(false);
        JobImpl job = createRunningStubbedJob(conf, dispatcher, 2, mockContext);
        completeJobTasks(job);
        assertJobState(job, JobStateInternal.COMMITTING);

        syncBarrier.await();
        job.handle(new JobEvent(job.getID(), JobEventType.JOB_AM_REBOOT));
        assertJobState(job, JobStateInternal.REBOOT);
        // return the external state as ERROR since this is last retry.
        Assert.assertEquals(JobState.RUNNING, job.getState());
        when(mockContext.hasSuccessfullyUnregistered()).thenReturn(true);
        Assert.assertEquals(JobState.ERROR, job.getState());

        dispatcher.stop();
        commitHandler.stop();
      }
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        JobId jobId = TypeConverter.toYarn(jobID);
        final String diagMsg = "some diagnostic message";
        final JobDiagnosticsUpdateEvent diagUpdateEvent =
            new JobDiagnosticsUpdateEvent(jobId, diagMsg);
        MRAppMetrics mrAppMetrics = MRAppMetrics.create();
        AppContext mockContext = mock(AppContext.class);
        when(mockContext.hasSuccessfullyUnregistered()).thenReturn(true);
        JobImpl job = new JobImpl(jobId, Records
            .newRecord(ApplicationAttemptId.class), new Configuration(),
            mock(EventHandler.class),
            null, mock(JobTokenSecretManager.class), null,
            new SystemClock(), null,
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

        CommitterEventHandler commitHandler =
            createCommitterEventHandler(dispatcher, committer);
        commitHandler.init(conf);
        commitHandler.start();

        AppContext mockContext = mock(AppContext.class);
        when(mockContext.hasSuccessfullyUnregistered()).thenReturn(false);
        JobImpl job = createStubbedJob(conf, dispatcher, 2, mockContext);
        JobId jobId = job.getID();
        job.handle(new JobEvent(jobId, JobEventType.JOB_INIT));
        assertJobState(job, JobStateInternal.INITED);
        job.handle(new JobStartEvent(jobId));
        assertJobState(job, JobStateInternal.FAILED);

        job.handle(new JobEvent(jobId, JobEventType.JOB_TASK_COMPLETED));
        assertJobState(job, JobStateInternal.FAILED);
        job.handle(new JobEvent(jobId, JobEventType.JOB_TASK_ATTEMPT_COMPLETED));
        assertJobState(job, JobStateInternal.FAILED);
        job.handle(new JobEvent(jobId, JobEventType.JOB_MAP_TASK_RESCHEDULED));
        assertJobState(job, JobStateInternal.FAILED);
        job.handle(new JobEvent(jobId, JobEventType.JOB_TASK_ATTEMPT_FETCH_FAILURE));
        assertJobState(job, JobStateInternal.FAILED);
        Assert.assertEquals(JobState.RUNNING, job.getState());
        when(mockContext.hasSuccessfullyUnregistered()).thenReturn(true);
        Assert.assertEquals(JobState.FAILED, job.getState());

        dispatcher.stop();
        commitHandler.stop();
      }
    View Full Code Here

    Examples of org.apache.hadoop.mapreduce.v2.app.AppContext

      }

      private static CommitterEventHandler createCommitterEventHandler(
          Dispatcher dispatcher, OutputCommitter committer) {
        final SystemClock clock = new SystemClock();
        AppContext appContext = mock(AppContext.class);
        when(appContext.getEventHandler()).thenReturn(
            dispatcher.getEventHandler());
        when(appContext.getClock()).thenReturn(clock);
        RMHeartbeatHandler heartbeatHandler = new RMHeartbeatHandler() {
          @Override
          public long getLastHeartbeatTime() {
            return clock.getTime();
          }
          @Override
          public void runOnNextHeartbeat(Runnable callback) {
            callback.run();
          }
        };
        ApplicationAttemptId id =
          ConverterUtils.toApplicationAttemptId("appattempt_1234567890000_0001_0");
        when(appContext.getApplicationID()).thenReturn(id.getApplicationId());
        when(appContext.getApplicationAttemptId()).thenReturn(id);
        CommitterEventHandler handler =
            new CommitterEventHandler(appContext, committer, heartbeatHandler);
        dispatcher.register(CommitterEventType.class, handler);
        return handler;
      }
    View Full Code Here
    TOP
    Copyright © 2018 www.massapi.com. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.