Example usage for javax.management AttributeNotFoundException printStackTrace

List of usage examples for javax.management AttributeNotFoundException printStackTrace

Introduction

In this page you can find the example usage for javax.management AttributeNotFoundException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.netsteadfast.greenstep.util.HostUtils.java

public static int getHttpPort() {
    int port = 8080;
    MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
    ObjectName name;/*  w w  w  .j  ava 2  s .  c  om*/
    try {
        name = new ObjectName("Catalina", "type", "Server");
        try {
            Server server = (Server) mBeanServer.getAttribute(name, "managedResource");
            Service[] services = server.findServices();
            for (Service service : services) {
                for (Connector connector : service.findConnectors()) {
                    ProtocolHandler protocolHandler = connector.getProtocolHandler();
                    if (protocolHandler instanceof Http11Protocol
                            || protocolHandler instanceof Http11AprProtocol
                            || protocolHandler instanceof Http11NioProtocol) {
                        port = connector.getPort();
                    }
                }
            }
        } catch (AttributeNotFoundException e) {
            e.printStackTrace();
        } catch (InstanceNotFoundException e) {
            e.printStackTrace();
        } catch (MBeanException e) {
            e.printStackTrace();
        } catch (ReflectionException e) {
            e.printStackTrace();
        }
    } catch (MalformedObjectNameException e) {
        e.printStackTrace();
    }
    return port;
}

From source file:com.cyberway.issue.crawler.framework.CrawlScope.java

public void listUsedFiles(List<String> list) {
    // Add seed file
    try {//from ww w .j a va 2 s.c  o m
        File file = getSettingsHandler().getPathRelativeToWorkingDirectory((String) getAttribute(ATTR_SEEDS));
        list.add(file.getAbsolutePath());
    } catch (AttributeNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MBeanException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ReflectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.ecyrd.management.SimpleMBean.java

/**
 *  Gets multiple attributes at the same time.
 *  //from w ww .  jav a2  s  . c  o  m
 *  @param arg0 The attribute names to get
 *  @return A list of attributes 
 */
public AttributeList getAttributes(String[] arg0) {
    AttributeList list = new AttributeList();

    for (int i = 0; i < arg0.length; i++) {
        try {
            list.add(new Attribute(arg0[i], getAttribute(arg0[i])));
        } catch (AttributeNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MBeanException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ReflectionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return list;
}

From source file:com.ecyrd.management.SimpleMBean.java

public AttributeList setAttributes(AttributeList arg0) {
    AttributeList result = new AttributeList();
    for (Iterator i = arg0.iterator(); i.hasNext();) {
        Attribute attr = (Attribute) i.next();

        ////from   www . ja  v  a  2 s  .  co  m
        //  Attempt to set the attribute.  If it succeeds (no exception),
        //  then we just add it to the list of successfull sets.
        //
        try {
            setAttribute(attr);
            result.add(attr);
        } catch (AttributeNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvalidAttributeValueException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MBeanException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ReflectionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return result;
}

From source file:dk.netarkivet.harvester.tools.TwitterDecidingScope.java

/**
 * This routine makes any necessary Twitter API calls and queues the content discovered.
 *
 * @param controller The controller for this crawl.
 *///from   ww w .ja v  a2 s .  co m
@Override
public void initialize(CrawlController controller) {
    super.initialize(controller);
    twitter = (new TwitterFactory()).getInstance();
    keywords = null;
    try {
        keywords = (StringList) super.getAttribute(ATTR_KEYWORDS);
        pages = ((Integer) super.getAttribute(ATTR_PAGES)).intValue();
        geoLocations = (StringList) super.getAttribute(ATTR_GEOLOCATIONS);
        language = (String) super.getAttribute(ATTR_LANG);
        if (language == null) {
            language = "all";
        }
        resultsPerPage = (Integer) super.getAttribute(ATTR_RESULTS_PER_PAGE);
        queueLinks = (Boolean) super.getAttribute(ATTR_QUEUE_LINKS);
        queueUserStatus = (Boolean) super.getAttribute(ATTR_QUEUE_USER_STATUS);
        queueUserStatusLinks = (Boolean) super.getAttribute(ATTR_QUEUE_USER_STATUS_LINKS);
        queueKeywordLinks = (Boolean) super.getAttribute(ATTR_QUEUE_KEYWORD_LINKS);
    } catch (AttributeNotFoundException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
    } catch (MBeanException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
    } catch (ReflectionException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
    }
    for (Object keyword : keywords) {
        log.info("Twitter Scope keyword: {}", keyword);
    }
    // If keywords or geoLocations is missing, add a list with a single empty string so that the main loop is
    // executed at least once.
    if (keywords == null || keywords.isEmpty()) {
        keywords = new StringList("keywords", "empty keyword list", new String[] { "" });
    }
    if (geoLocations == null || geoLocations.isEmpty()) {
        geoLocations = new StringList("geolocations", "empty geolocation list", new String[] { "" });
    }
    log.info("Twitter Scope will queue {} page(s) of results.", pages);
    // Nested loop over keywords, geo_locations and pages.
    for (Object keyword : keywords) {
        String keywordString = (String) keyword;
        for (Object geoLocation : geoLocations) {
            String urlQuery = (String) keyword;
            Query query = new Query();
            query.setRpp(resultsPerPage);
            if (language != null && !language.equals("")) {
                query.setLang(language);
                urlQuery += " lang:" + language;
                keywordString += " lang:" + language;
            }
            urlQuery = "http://twitter.com/search/" + URLEncoder.encode(urlQuery);
            if (queueKeywordLinks) {
                addSeedIfLegal(urlQuery);
            }
            for (int page = 1; page <= pages; page++) {
                query.setPage(page);
                if (!keyword.equals("")) {
                    query.setQuery(keywordString);
                }
                if (!geoLocation.equals("")) {
                    String[] locationArray = ((String) geoLocation).split(",");
                    try {
                        GeoLocation location = new GeoLocation(Double.parseDouble(locationArray[0]),
                                Double.parseDouble(locationArray[1]));
                        query.setGeoCode(location, Double.parseDouble(locationArray[2]), locationArray[3]);
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }
                }
                try {
                    final QueryResult result = twitter.search(query);
                    List<Tweet> tweets = result.getTweets();
                    for (Tweet tweet : tweets) {
                        long id = tweet.getId();
                        String fromUser = tweet.getFromUser();
                        String tweetUrl = "http://www.twitter.com/" + fromUser + "/status/" + id;
                        addSeedIfLegal(tweetUrl);
                        tweetCount++;
                        if (queueLinks) {
                            extractEmbeddedLinks(tweet);
                        }
                        if (queueUserStatus) {
                            String statusUrl = "http://twitter.com/" + tweet.getFromUser() + "/";
                            addSeedIfLegal(statusUrl);
                            linkCount++;
                            if (queueUserStatusLinks) {
                                queueUserStatusLinks(tweet.getFromUser());
                            }
                        }
                    }
                } catch (TwitterException e1) {
                    log.error(e1.getMessage());
                }
            }
        }

    }
    System.out.println(
            TwitterDecidingScope.class + " added " + tweetCount + " tweets and " + linkCount + " other links.");
}

From source file:com.cyberway.issue.crawler.settings.XMLSettingsHandler.java

private File getSettingsDirectory() {
    String settingsDirectoryName = null;
    try {/*from  w  ww .  j  a v  a2s  . c  o m*/
        settingsDirectoryName = (String) getOrder().getAttribute(CrawlOrder.ATTR_SETTINGS_DIRECTORY);
    } catch (AttributeNotFoundException e) {
        e.printStackTrace();
    } catch (MBeanException e) {
        e.printStackTrace();
    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    return getPathRelativeToWorkingDirectory(settingsDirectoryName);
}

From source file:com.cyberway.issue.crawler.settings.XMLSettingsHandler.java

/**
 * Add any files being used by any of the Modules making up the settings to
 * the list./*from  w ww.j  av  a2s  . c  o m*/
 *
 * @param mbean A ModuleType to interrogate for files. Any child modules
 *           will be recursively interrogated.
 * @param list The list to add found files to.
 */
private void recursiveFindSecondaryFiles(ComplexType mbean, ArrayList<String> list) {
    MBeanInfo info = mbean.getMBeanInfo();
    MBeanAttributeInfo[] a = info.getAttributes();
    // Interrogate the current module
    if (mbean instanceof ModuleType) {
        ((ModuleType) mbean).listUsedFiles(list);
    }

    // Recursively interrogate all sub modules that are of ModuleType
    for (int n = 0; n < a.length; n++) {
        if (a[n] == null) {
            // Error null attribute.
        } else {
            ModuleAttributeInfo att = (ModuleAttributeInfo) a[n];
            Object currentAttribute;
            try {
                currentAttribute = mbean.getAttribute(att.getName());
                if (currentAttribute instanceof ComplexType) {
                    recursiveFindSecondaryFiles((ComplexType) currentAttribute, list);
                }
            } catch (AttributeNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (MBeanException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ReflectionException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

From source file:com.cyberway.issue.crawler.fetcher.FetchHTTP.java

protected void listUsedFiles(List<String> list) {
    // List the cookies files
    // Add seed file
    try {//from   w w  w. j a  v  a  2s  . co  m
        String tmp = (String) getAttribute(ATTR_LOAD_COOKIES);
        if (tmp != null && tmp.length() > 0) {
            File file = getSettingsHandler().getPathRelativeToWorkingDirectory(tmp);
            list.add(file.getAbsolutePath());
        }
        tmp = (String) getAttribute(ATTR_SAVE_COOKIES);
        if (tmp != null && tmp.length() > 0) {
            File file = getSettingsHandler().getPathRelativeToWorkingDirectory(tmp);
            list.add(file.getAbsolutePath());
        }
    } catch (AttributeNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MBeanException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ReflectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.eclipse.gyrex.monitoring.internal.mbeans.MetricSetMBean.java

@Override
public AttributeList getAttributes(final String[] attributes) {
    final AttributeList attributeList = new AttributeList();
    for (final String attributeName : attributes) {
        try {/*from  w  ww. j ava  2 s  .c  o  m*/
            attributeList.add(new Attribute(attributeName, getAttribute(attributeName)));
        } catch (final AttributeNotFoundException e) {
            // ignore
        } catch (final MBeanException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (final ReflectionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return attributeList;
}