Example usage for java.lang IllegalStateException getMessage

List of usage examples for java.lang IllegalStateException getMessage

Introduction

In this page you can find the example usage for java.lang IllegalStateException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.example.android.mediarecorder.MainActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private boolean prepareVideoRecorder() {
    if (!preparePreview()) {
        return false;
    }//w  ww. ja v  a  2s. c o  m
    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);

    // BEGIN_INCLUDE (configure_media_recorder)
    mMediaRecorder = new MediaRecorder();

    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);

    // Step 2: Set sources
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
    mMediaRecorder.setProfile(profile);

    // orientation
    int rotation = getWindowManager().getDefaultDisplay().getRotation();
    Log.i("TESTING", "Sensor Orientation: " + sensorOrientation);
    if (sensorOrientation == SENSOR_ORIENTATION_DEFAULT_DEGREES) {
        Log.i("TESTING", "Recorder: DEFAULT ROTATION: " + DEFAULT_ORIENTATIONS.get(rotation));
        mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
    } else {
        Log.i("TESTING", "Recorder: INVERSING ROTATION: " + INVERSE_ORIENTATIONS.get(rotation));
        mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
    }

    // Step 4: Set output file
    mOutputFile = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO);
    if (mOutputFile == null) {
        return false;
    }
    mMediaRecorder.setOutputFile(mOutputFile.getPath());
    // END_INCLUDE (configure_media_recorder)

    // Step 5: Prepare configured MediaRecorder
    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    }
    return true;
}

From source file:org.globus.workspace.client.modes.Subscribe.java

protected void _handleSubscribeWithListen() throws ParameterProblem {

    if (this.eitherSubscriptionMaster != null) {
        throw new IllegalStateException("you may only make one "
                + "subscription master non-null (and copy its reference " + "to 'either' variable)");
    }/*  ww  w.  j a va 2 s  .c o m*/

    this.listeningSubscriptionMaster = SubscriptionMasterFactory.newListeningMaster(null, this.pr);

    this.eitherSubscriptionMaster = this.listeningSubscriptionMaster;

    if (this.dryrun) {
        final String dbg = "Dryrun, not starting to listen for notifications.";
        if (this.pr.useThis()) {
            this.pr.info(PrCodes.CREATE__DRYRUN, dbg);
        } else if (this.pr.useLogging()) {
            logger.info(dbg);
        }

        return; // *** EARLY RETURN ***
    }

    final String errPrefix = "Problem starting to listen for notifications: ";
    try {
        this.listeningSubscriptionMaster.listen(this.notificationListenerOverride_IPorHost,
                this.notificationListenerOverride_Port);
    } catch (IllegalStateException e) {
        throw new ParameterProblem(errPrefix + e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        throw new ParameterProblem(errPrefix + e.getMessage(), e);
    } catch (Exception e) {
        throw new ParameterProblem(errPrefix + e.getMessage(), e);
    }

    this.subscribeLaunch = new SubscribeLaunch(this.listeningSubscriptionMaster, this.nameToPrint, this.pr,
            this.stubConf, null);
}

From source file:org.apache.tinkerpop.gremlin.process.TraversalStrategiesTest.java

/**
 * Tests that {@link org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies#sortStrategies(java.util.List)}
 * works as advertised. This class defines a bunch of dummy strategies which define an order. It is verified
 * that the right order is being returned.
 *///from   www. j  a v a  2 s  . co m
@Test
public void testTraversalStrategySorting() {
    TraversalStrategy a = new StrategyA(), b = new StrategyB(), c = new StrategyC(), d = new StrategyD(),
            e = new StrategyE(), k = new StrategyK(), l = new StrategyL(), m = new StrategyM(),
            n = new StrategyN(), o = new StrategyO();

    List<TraversalStrategy<?>> s;

    //Dependency well defined
    s = Arrays.asList(b, a);
    s = TraversalStrategies.sortStrategies(s);
    assertEquals(2, s.size());
    assertEquals(a, s.get(0));
    assertEquals(b, s.get(1));

    //No dependency
    s = Arrays.asList(c, a);
    s = TraversalStrategies.sortStrategies(s);
    assertEquals(2, s.size());

    //Dependency well defined
    s = Arrays.asList(c, a, b);
    s = TraversalStrategies.sortStrategies(s);
    assertEquals(3, s.size());
    assertEquals(a, s.get(0));
    assertEquals(b, s.get(1));
    assertEquals(c, s.get(2));

    //Circular dependency => throws exception
    s = Arrays.asList(c, k, a, b);
    try {
        TraversalStrategies.sortStrategies(s);
        fail();
    } catch (IllegalStateException ex) {
        assertTrue(ex.getMessage().toLowerCase().contains("cyclic"));
    }

    //Dependency well defined
    s = Arrays.asList(d, c, a, e, b);
    s = TraversalStrategies.sortStrategies(s);
    assertEquals(5, s.size());
    assertEquals(a, s.get(0));
    assertEquals(b, s.get(1));
    assertEquals(d, s.get(2));
    assertEquals(c, s.get(3));
    assertEquals(e, s.get(4));

    //Circular dependency => throws exception
    s = Arrays.asList(d, c, k, a, e, b);
    try {
        TraversalStrategies.sortStrategies(s);
        fail();
    } catch (IllegalStateException ex) {
        assertTrue(ex.getMessage().toLowerCase().contains("cyclic"));
    }

    //Lots of strategies
    s = Arrays.asList(b, l, m, n, o, a);
    s = TraversalStrategies.sortStrategies(s);
    assertTrue(s.indexOf(a) < s.indexOf(b));

    // sort and then add more
    s = new ArrayList<>((List) Arrays.asList(b, a, c));
    s = TraversalStrategies.sortStrategies(s);
    assertEquals(3, s.size());
    assertEquals(a, s.get(0));
    assertEquals(b, s.get(1));
    assertEquals(c, s.get(2));
    s.add(d);
    s = TraversalStrategies.sortStrategies(s);
    assertEquals(4, s.size());
    assertEquals(a, s.get(0));
    assertEquals(b, s.get(1));
    assertEquals(d, s.get(2));
    assertEquals(c, s.get(3));
    s.add(e);
    s = TraversalStrategies.sortStrategies(s);
    assertEquals(5, s.size());
    assertEquals(a, s.get(0));
    assertEquals(b, s.get(1));
    assertEquals(d, s.get(2));
    assertEquals(c, s.get(3));
    assertEquals(e, s.get(4));

}

From source file:com.wirelust.sonar.plugins.bitbucket.PullRequestFacadeTest.java

@Test
public void shouldHandleBuildStatusFailure() throws Exception {
    setDefaultConfig();//from   w  ww.j a  v a  2s .c o  m

    // post global comment
    when(bitbucketV2Client.postBuildStatus(any(String.class), any(String.class), any(String.class),
            any(BuildStatus.class))).thenReturn(responseFailure);

    PullRequestFacade pullRequestFacade = new PullRequestFacade(configuration, apiClientFactory);

    try {
        pullRequestFacade.init(123, temporaryFolder.getRoot());

        Assert.fail();
    } catch (IllegalStateException e) {
        assertEquals("Unable to perform Bitbucket WS operation", e.getMessage());
    }
}

From source file:de.tudarmstadt.lt.n2n.annotators.RelationAnnotator.java

private void searchForPath(JCas aJCas) {
    List<Relation> relations_to_remove = new LinkedList<Relation>();
    for (Relation relation : JCasUtil.select(aJCas, Relation.class)) {
        Entity e1 = relation.getE1();
        Entity e2 = relation.getE2();
        Sentence covering_sentence = relation.getCoveringSentence();
        LOG.trace(//from  w  w  w.ja  v a2  s  . c om
                "searching for a shortest path in the dependency graph for relation ({}-{},{}-{}) in sentence [{}].",
                e1.getCoveredText(), e1.getBegin(), e2.getCoveredText(), e2.getBegin(),
                StringUtils.abbreviate(covering_sentence.getCoveredText(), 50));
        List<Dependency> dependency_path = null;
        try {
            dependency_path = find_path(e1, e2, JCasUtil.selectCovered(Dependency.class, covering_sentence));
            if (dependency_path == null) { // no path found
                relations_to_remove.add(relation);
                LOG.debug("Removing relation ({}-{},{}-{}) in sentence [{}]. No dependency path was found.",
                        e1.getCoveredText(), e1.getBegin(), e2.getCoveredText(), e2.getBegin(),
                        StringUtils.abbreviate(covering_sentence.getCoveredText(), 50));
                continue;
            }
        } catch (IllegalStateException e) {
            relations_to_remove.add(relation);
            LOG.warn(String.format("%s: '%s.'", e.getClass().getSimpleName(), e.getMessage()));
            continue;
        }

        int path_length = dependency_path.size(); // dependencies are edges thus the path length is len(edges)
        LOG.trace("Found shortest path with length {} for relation ({}-{},{}-{}) in sentence [{}].",
                path_length, e1.getCoveredText(), e1.getBegin(), e2.getCoveredText(), e2.getBegin(),
                StringUtils.abbreviate(covering_sentence.getCoveredText(), 50));

        // if the direct neighbor of either entities representative tokens is connected via 'nn' relation and the representative token is not the governor then ignore this edge
        if (_remove_immediate_nn_relations) {
            if (path_length > 0 && "nn".equals(dependency_path.get(0).getDependencyType())
                    && dependency_path.get(0).getDependent().equals(e1.getRepresentativeToken())) { // check first edge
                dependency_path.remove(0);
                path_length--;
                LOG.debug(
                        "The immediate connecting edge for e1 ({}-{}) in sentence [{}] is an 'nn' relation and e1 is the dependent. It is removed from the path. New path length is {}.",
                        e1.getCoveredText(), e1.getBegin(),
                        StringUtils.abbreviate(covering_sentence.getCoveredText(), 50), path_length);
            }
            if (path_length > 0 && "nn".equals(dependency_path.get(path_length - 1).getDependencyType())
                    && dependency_path.get(path_length - 1).getDependent()
                            .equals(e2.getRepresentativeToken())) { // check last edge
                dependency_path.remove(path_length - 1);
                path_length--;
                LOG.debug(
                        "The immediate connecting edge for e2 ({}-{}) in sentence [{}] is an 'nn' relation and e1 is the dependent. It is removed from the path. New path length is {}.",
                        e2.getCoveredText(), e2.getBegin(),
                        StringUtils.abbreviate(covering_sentence.getCoveredText(), 50), path_length);
            }
        }

        // if path is too short skip it
        if (path_length < _min_dependency_path_length) {
            LOG.debug(
                    "Path for relation ({}-{},{}-{}) in sentence [{}] is shorter than minlength={} ({}). Removing relation from cas index.",
                    e1.getCoveredText(), e1.getBegin(), e2.getCoveredText(), e2.getBegin(),
                    StringUtils.abbreviate(covering_sentence.getCoveredText(), 50), _min_dependency_path_length,
                    path_length);
            relations_to_remove.add(relation);
            continue;
        }

        // if path is too long skip it
        if (path_length > _max_dependency_path_length) {
            LOG.debug(
                    "Path for relation ({}-{},{}-{}) in sentence [{}] is longer than maxlength={} ({}). Removing relation from cas index.",
                    e1.getCoveredText(), e1.getBegin(), e2.getCoveredText(), e2.getBegin(),
                    StringUtils.abbreviate(covering_sentence.getCoveredText(), 50), _max_dependency_path_length,
                    path_length);
            relations_to_remove.add(relation);
            continue;
        }

        relation.setDependencyPath((FSArray) aJCas.getCas().createArrayFS(dependency_path.size()));
        for (int i = 0; i < dependency_path.size(); i++)
            relation.setDependencyPath(i, dependency_path.get(i));
    }

    for (Relation relation : relations_to_remove)
        relation.removeFromIndexes(aJCas);
}

From source file:nuclei.media.MediaService.java

@Override
public void onCreate() {
    super.onCreate();
    LOG.d("onCreate");

    mPackageValidator = new PackageValidator(this);

    boolean casting = false;
    try {/*from  www.  ja  va  2  s .  c  om*/
        VideoCastManager.getInstance().addVideoCastConsumer(mCastConsumer);
        casting = VideoCastManager.getInstance().isConnected() || VideoCastManager.getInstance().isConnecting();
    } catch (IllegalStateException err) {
        LOG.e("Error registering cast consumer : " + err.getMessage());
    }

    Playback playback;

    // Start a new MediaSession
    mSession = new MediaSessionCompat(this, "NucleiMediaService",
            new ComponentName(getApplicationContext(), MediaButtonReceiver.class), null);
    mSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

    mMediaRouter = MediaRouter.getInstance(getApplicationContext());
    setSessionToken(mSession.getSessionToken());

    try {
        mMediaNotificationManager = new MediaNotificationManager(this);
    } catch (RemoteException e) {
        throw new IllegalStateException("Could not create a MediaNotificationManager", e);
    }

    mSessionExtras = new Bundle();

    if (casting) {
        mSessionExtras.putString(EXTRA_CONNECTED_CAST, VideoCastManager.getInstance().getDeviceName());
        mMediaRouter.setMediaSessionCompat(mSession);
        playback = PlaybackFactory.createCastPlayback(MediaService.this);
    } else
        playback = PlaybackFactory.createLocalPlayback(MediaService.this);

    mPlaybackManager = new PlaybackManager(this, playback);

    mSession.setCallback(mPlaybackManager.getMediaSessionCallback());

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    mediaButtonIntent.setComponent(new ComponentName(this, MediaService.class));
    mSession.setMediaButtonReceiver(PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0));

    CarHelper.setSlotReservationFlags(mSessionExtras, true, true, true);
    mSession.setExtras(mSessionExtras);

    mPlaybackManager.updatePlaybackState(null, true);

    registerCarConnectionReceiver();
}

From source file:com.streamreduce.core.service.ConnectionServiceImpl.java

private void validateOutboundConfigurations(Set<OutboundConfiguration> outboundConfigurations)
        throws InvalidCredentialsException, IOException {
    if (CollectionUtils.isEmpty(outboundConfigurations)) {
        return;/*from  w  w w. j av  a  2s .  c  om*/
    }

    ExternalIntegrationClient externalClient = null;
    try {
        for (OutboundConfiguration outboundConfiguration : outboundConfigurations) {
            if (outboundConfiguration.getProtocol().equals("s3")) {
                AWSClient awsClient = new AWSClient(outboundConfiguration);
                externalClient = awsClient;
                externalClient.validateConnection();
                try {
                    awsClient.createBucket(outboundConfiguration);
                } catch (IllegalStateException e) { //thrown when a bucket name is already taken
                    throw new InvalidOutboundConfigurationException(e.getMessage(), e);
                }
            } else if (outboundConfiguration.getProtocol().equals("webhdfs")) {
                externalClient = new WebHDFSClient(outboundConfiguration);
                externalClient.validateConnection();
            }
        }
    } finally {
        if (externalClient != null) {
            externalClient.cleanUp();
        }
    }
}

From source file:org.apache.sentry.core.common.transport.SentryTransportPool.java

/**
 * Get an open transport instance./*from  w ww.  j av a  2  s . c  om*/
 * The instance can be connected to any of the available servers.
 * We are trying to randomly load-balance between servers (unless it is
 * disabled in configuration).
 *
 * @return connected transport
 * @throws Exception if connection tto both servers fails
 */
public TTransportWrapper getTransport() throws Exception {
    List<HostAndPort> servers;
    // If we are doing load balancing and there is more then one server,
    // shuffle them before obtaining connection
    if (doLoadBalancing && (endpoints.size() > 1)) {
        servers = new ArrayList<>(endpoints);
        Collections.shuffle(servers);
    } else {
        servers = endpoints;
    }

    // Try to get a connection from one of the pools.
    Exception failure = null;
    boolean ignoreEmptyPool = true;
    for (int attempt = 0; attempt < 2; attempt++) {
        // First only attempt to borrow from pools which have some idle connections
        // If this fails, try with all pools
        for (HostAndPort addr : servers) {
            if (isPoolEnabled && ignoreEmptyPool && (pool.getNumIdle(addr) == 0)) {
                LOGGER.debug("Ignoring empty pool {}", addr);
                ignoreEmptyPool = false;
                continue;
            }
            try {
                TTransportWrapper transport = isPoolEnabled ? pool.borrowObject(addr)
                        : transportFactory.getTransport(addr);
                LOGGER.debug("[{}] obtained transport {}", id, transport);
                if (LOGGER.isDebugEnabled() && isPoolEnabled) {
                    LOGGER.debug("Currently {} active connections, {} idle connections", pool.getNumActive(),
                            pool.getNumIdle());
                }
                return transport;
            } catch (IllegalStateException e) {
                // Should not happen
                LOGGER.error("Unexpected error from pool {}", id, e);
                failure = e;
            } catch (Exception e) {
                LOGGER.error("Failed to obtain transport for {}: {}", addr, e.getMessage());
                failure = e;
            }
        }
        ignoreEmptyPool = false;
    }
    // Failed to borrow connect to any endpoint
    assert failure != null;
    throw failure;
}

From source file:org.apache.nifi.processors.standard.SplitText.java

/**
 * Will split the incoming stream releasing all splits as FlowFile at once.
 */// w  w  w .ja  v  a2s.c  o  m
@Override
public void onTrigger(ProcessContext context, ProcessSession processSession) throws ProcessException {
    FlowFile sourceFlowFile = processSession.get();
    if (sourceFlowFile == null) {
        return;
    }
    AtomicBoolean error = new AtomicBoolean();
    List<SplitInfo> computedSplitsInfo = new ArrayList<>();
    AtomicReference<SplitInfo> headerSplitInfoRef = new AtomicReference<>();
    processSession.read(sourceFlowFile, new InputStreamCallback() {
        @Override
        public void process(InputStream in) throws IOException {
            TextLineDemarcator demarcator = new TextLineDemarcator(in);
            SplitInfo splitInfo = null;
            long startOffset = 0;

            // Compute fragment representing the header (if available)
            long start = System.nanoTime();
            try {
                if (SplitText.this.headerLineCount > 0) {
                    splitInfo = SplitText.this.computeHeader(demarcator, startOffset,
                            SplitText.this.headerLineCount, null, null);
                    if ((splitInfo != null) && (splitInfo.lineCount < SplitText.this.headerLineCount)) {
                        error.set(true);
                        getLogger().error("Unable to split " + sourceFlowFile
                                + " due to insufficient amount of header lines. Required "
                                + SplitText.this.headerLineCount + " but was " + splitInfo.lineCount
                                + ". Routing to failure.");
                    }
                } else if (SplitText.this.headerMarker != null) {
                    splitInfo = SplitText.this.computeHeader(demarcator, startOffset, Long.MAX_VALUE,
                            SplitText.this.headerMarker.getBytes(StandardCharsets.UTF_8), null);
                }
                headerSplitInfoRef.set(splitInfo);
            } catch (IllegalStateException e) {
                error.set(true);
                getLogger().error(e.getMessage() + " Routing to failure.", e);
            }

            // Compute and collect fragments representing the individual splits
            if (!error.get()) {
                if (headerSplitInfoRef.get() != null) {
                    startOffset = headerSplitInfoRef.get().length;
                }
                long preAccumulatedLength = startOffset;
                while ((splitInfo = SplitText.this.nextSplit(demarcator, startOffset, SplitText.this.lineCount,
                        splitInfo, preAccumulatedLength)) != null) {
                    computedSplitsInfo.add(splitInfo);
                    startOffset += splitInfo.length;
                }
                long stop = System.nanoTime();
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Computed splits in " + (stop - start) + " milliseconds.");
                }
            }
        }
    });

    if (error.get()) {
        processSession.transfer(sourceFlowFile, REL_FAILURE);
    } else {
        final String fragmentId = UUID.randomUUID().toString();
        List<FlowFile> splitFlowFiles = this.generateSplitFlowFiles(fragmentId, sourceFlowFile,
                headerSplitInfoRef.get(), computedSplitsInfo, processSession);
        final FlowFile originalFlowFile = FragmentAttributes.copyAttributesToOriginal(processSession,
                sourceFlowFile, fragmentId, splitFlowFiles.size());
        processSession.transfer(originalFlowFile, REL_ORIGINAL);
        if (!splitFlowFiles.isEmpty()) {
            processSession.transfer(splitFlowFiles, REL_SPLITS);
        }
    }
}

From source file:org.jolokia.handler.list.MBeanInfoData.java

/**
 * Add an exception which occurred during extraction of an {@link MBeanInfo} for
 * a certain {@link ObjectName} to this map.
 *
 * @param pName MBean name for which the error occurred
 * @param pExp exception occurred/*from  www . java2 s  .c o  m*/
 * @throws IllegalStateException if this method decides to rethrow the exception
 */
public void handleException(ObjectName pName, IllegalStateException pExp) {
    // This happen happens for JBoss 7.1 in some cases.
    if (pathStack.size() == 0) {
        addException(pName, pExp);
    } else {
        throw new IllegalStateException(
                "IllegalStateException for MBean " + pName + " (" + pExp.getMessage() + ")", pExp);
    }
}