Java Code Examples for org.elasticsearch.client.Client

The following examples show how to use org.elasticsearch.client.Client. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: crate   Source File: ReadOnlyNodeIntegrationTest.java    License: Apache License 2.0 6 votes vote down vote up
public ReadOnlyNodeIntegrationTest() {
    super(new SQLTransportExecutor(
        new SQLTransportExecutor.ClientProvider() {
            @Override
            public Client client() {
                // make sure we use the read-only client
                return internalCluster().client(internalCluster().getNodeNames()[1]);
            }

            @Override
            public String pgUrl() {
                return null;
            }

            @Override
            public SQLOperations sqlOperations() {
                return internalCluster().getInstance(SQLOperations.class, internalCluster().getNodeNames()[1]);
            }
        }
    ));
}
 
Example 2
Source Project: elasticsearch-sql   Source File: CSVResultRestExecutor.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Client client, Map<String, String> params, QueryAction queryAction, RestChannel channel) throws Exception {
    Object queryResult = QueryActionElasticExecutor.executeAnyAction(client, queryAction);

    boolean flat = getBooleanOrDefault(params,"flat",false);
    String separator = ",";
    if(params.containsKey("separator")){
     separator = params.get("separator");
    }
    boolean includeScore = getBooleanOrDefault(params,"_score",false);
    boolean includeType = getBooleanOrDefault(params,"_type",false);
    boolean includeId = getBooleanOrDefault(params,"_id",false);
    boolean includeScrollId = getBooleanOrDefault(params,"_scroll_id",false);
    CSVResult result  = new CSVResultsExtractor(includeScore,includeType,includeId,includeScrollId,queryAction).extractResults(queryResult,flat,separator);
    String newLine = "\n";
    if(params.containsKey("newLine")){
     newLine = params.get("newLine");
    }
    boolean showHeader = getBooleanOrDefault(params, "showHeader", true);
    String csvString = buildString(separator, result, newLine, showHeader);
    BytesRestResponse bytesRestResponse = new BytesRestResponse(RestStatus.OK, csvString);
    channel.sendResponse(bytesRestResponse);
}
 
Example 3
Source Project: Elasticsearch   Source File: RestGetRepositoriesAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY);
    GetRepositoriesRequest getRepositoriesRequest = getRepositoryRequest(repositories);
    getRepositoriesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getRepositoriesRequest.masterNodeTimeout()));
    getRepositoriesRequest.local(request.paramAsBoolean("local", getRepositoriesRequest.local()));
    settingsFilter.addFilterSettingParams(request);
    client.admin().cluster().getRepositories(getRepositoriesRequest, new RestBuilderListener<GetRepositoriesResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetRepositoriesResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            for (RepositoryMetaData repositoryMetaData : response.repositories()) {
                RepositoriesMetaData.toXContent(repositoryMetaData, builder, request);
            }
            builder.endObject();

            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example 4
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest()
            .routingTable(false)
            .nodes(false);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    client.admin().cluster().state(clusterStateRequest, new RestBuilderListener<ClusterStateResponse>(channel) {
        @Override
        public RestResponse buildResponse(ClusterStateResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();

            builder.startObject("persistent");
            response.getState().metaData().persistentSettings().toXContent(builder, request);
            builder.endObject();

            builder.startObject("transient");
            response.getState().metaData().transientSettings().toXContent(builder, request);
            builder.endObject();

            builder.endObject();

            return new BytesRestResponse(RestStatus.OK, builder);
        }
    });
}
 
Example 5
Source Project: Gather-Platform   Source File: ESClient.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Client getClient() {
    if (!staticValue.isNeedEs()) {
        LOG.info("已在配置文件中声明不需要ES,如需要ES,请在配置文件中进行配置");
        return null;
    }
    if (client != null) return client;
    try {
        LOG.info("正在初始化ElasticSearch客户端," + staticValue.getEsHost());
        Settings settings = Settings.builder()
                .put("cluster.name", staticValue.getEsClusterName()).build();
        client = new PreBuiltTransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(staticValue.getEsHost()), 9300));
        final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth()
                .setTimeout(TimeValue.timeValueMinutes(1)).execute().actionGet();
        if (healthResponse.isTimedOut()) {
            LOG.error("ES客户端初始化失败");
        } else {
            LOG.info("ES客户端初始化成功");
        }
    } catch (IOException e) {
        LOG.fatal("构建ElasticSearch客户端失败!");
    }
    return client;
}
 
Example 6
private void FlumeESSinkAndTestData(List<Event> searchEvents)
		throws EventDeliveryException, IOException, FileNotFoundException {
	flumeESSinkService.processEvents(searchEvents);

	Client client = searchClientService.getClient();
	client.admin().indices().refresh(Requests.refreshRequest()).actionGet();

	String indexName = "recentlyviewed" + '-'
			+ ElasticSearchIndexRequestBuilderFactory.df.format(new Date());
	long totalCount = client.prepareCount(indexName).get().getCount();
	System.out.println("Search total count is: " + totalCount);

	SearchHits hits = client.prepareSearch(indexName).get().getHits();
	System.out.println("Total hits: " + hits.getTotalHits());
	for (SearchHit searchHit : hits) {
		System.out.println(searchHit.getSource());
	}
}
 
Example 7
@Override
public Event getEvent(final long snifferId, final String eventId) {
	return clientTpl.executeWithClient(new ClientCallback<Event>() {
		@Override
		public Event execute(final Client client) {
			try {
				final SearchResponse r = client.prepareSearch(indexNamingStrategy.getRetrievalNames(snifferId))
						.setIndicesOptions(IndicesOptions.lenientExpandOpen())
						.setQuery(QueryBuilders.idsQuery().ids(eventId)).execute().get();
				if (r != null && r.getHits().hits().length > 0) {
					final SearchHit hit = r.getHits().hits()[0];
					final Event event = jsonMapper.readValue(hit.getSourceAsString(), Event.class);
					event.setId(hit.getId());
					return event;
				} else {
					return null;
				}
			} catch (final Exception e) {
				throw new DataAccessException("Failed to load for sniffer=" + snifferId + " the event: " + eventId,
						e);
			}
		}
	});
}
 
Example 8
Source Project: vertexium   Source File: ElasticsearchResource.java    License: Apache License 2.0 6 votes vote down vote up
private Client getRemoteClient() {
    if (remoteClient == null) {
        Settings settings = Settings.builder()
            .put("cluster.name", System.getProperty("REMOTE_ES_CLUSTER_NAME", "elasticsearch"))
            .build();
        TransportAddress[] transportAddresses = Arrays.stream(getRemoteEsAddresses().split(","))
            .map(address -> {
                String[] parts = address.split(":");
                try {
                    InetAddress inetAddress = InetAddress.getByName(parts[0]);
                    int port = parts.length > 1 ? Integer.parseInt(parts[1]) : 9300;
                    return new InetSocketTransportAddress(inetAddress, port);
                } catch (Exception ex) {
                    throw new VertexiumException("cannot find host: " + address, ex);
                }
            })
            .toArray(TransportAddress[]::new);
        remoteClient = new PreBuiltTransportClient(settings)
            .addTransportAddresses(transportAddresses);
    }
    return remoteClient;
}
 
Example 9
@Builder
private FullTextSearchLookupDescriptor(
		@NonNull final Client elasticsearchClient,
		@NonNull final String modelTableName,
		@NonNull final String esIndexName,
		@NonNull final Set<String> esSearchFieldNames,
		@Nullable final ISqlLookupDescriptor sqlLookupDescriptor,
		@NonNull final LookupDataSource databaseLookup)
{
	this.elasticsearchClient = elasticsearchClient;

	this.modelTableName = modelTableName;

	this.esIndexName = esIndexName;
	esKeyColumnName = InterfaceWrapperHelper.getKeyColumnName(modelTableName);

	this.esSearchFieldNames = esSearchFieldNames.toArray(new String[esSearchFieldNames.size()]);

	this.sqlLookupDescriptor = sqlLookupDescriptor;
	this.databaseLookup = databaseLookup;
}
 
Example 10
/**
 * If _ttl is enabled in the mapping, the _ttl field delivers the time stamp
 * when the object is expired.
 */
@Test
public void testTTLEnabled() {
    esSetup.execute(deleteAll(), createIndex("ttlenabled").withSettings(
            fromClassPath("essetup/settings/test_a.json")).withMapping("d",
                    "{\"d\": {\"_ttl\": {\"enabled\": true, \"default\": \"1d\"}}}"));
    Client client = esSetup.client();
    client.prepareIndex("ttlenabled", "d", "1").setSource("field1", "value1").execute().actionGet();
    client.admin().indices().prepareRefresh().execute().actionGet();

    Date now = new Date();
    ExportResponse response = executeExportRequest(
            "{\"output_cmd\": \"cat\", \"fields\": [\"_id\", \"_ttl\"]}");
    List<Map<String, Object>> infos = getExports(response);
    String stdout = infos.get(1).get("stdout").toString();
    assertTrue(stdout.startsWith("{\"_id\":\"1\",\"_ttl\":"));
    String lsplit  = stdout.substring(18);
    long ttl = Long.valueOf(lsplit.substring(0, lsplit.length() - 2));
    long diff = ttl - now.getTime();
    assertTrue(diff < 86400000 && diff > 86390000);
}
 
Example 11
Source Project: Dodder   Source File: TorrentDaoImpl.java    License: MIT License 6 votes vote down vote up
@Override
public void index(Torrent torrent) throws IOException {
    Client client = elasticsearchTemplate.getClient();
    XContentBuilder source = jsonBuilder()
            .startObject()
            .field("fileName", torrent.getFileName())
            .field("fileType", torrent.getFileType())
            .field("fileSize", torrent.getFileSize())
            .field("createDate", torrent.getCreateDate())
            .endObject();

    IndexRequest indexRequest = new IndexRequest("dodder", "torrent", torrent.getInfoHash())
            .source(source);
    UpdateRequest updateRequest = new UpdateRequest("dodder", "torrent", torrent.getInfoHash())
            .doc(indexRequest)
            .docAsUpsert(true);
    client.update(updateRequest);
}
 
Example 12
Source Project: Elasticsearch   Source File: RestForceMergeAction.java    License: Apache License 2.0 6 votes vote down vote up
@Inject
public RestForceMergeAction(Settings settings, RestController controller, Client client) {
    super(settings, controller, client);
    controller.registerHandler(POST, "/_forcemerge", this);
    controller.registerHandler(POST, "/{index}/_forcemerge", this);

    controller.registerHandler(GET, "/_forcemerge", this);
    controller.registerHandler(GET, "/{index}/_forcemerge", this);

    // TODO: Remove for 3.0
    controller.registerHandler(POST, "/_optimize", this);
    controller.registerHandler(POST, "/{index}/_optimize", this);

    controller.registerHandler(GET, "/_optimize", this);
    controller.registerHandler(GET, "/{index}/_optimize", this);
}
 
Example 13
Source Project: Elasticsearch   Source File: RestListTasksAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    boolean detailed = request.paramAsBoolean("detailed", false);
    String[] nodesIds = Strings.splitStringByCommaToArray(request.param("node_id"));
    TaskId taskId = new TaskId(request.param("taskId"));
    String[] actions = Strings.splitStringByCommaToArray(request.param("actions"));
    TaskId parentTaskId = new TaskId(request.param("parent_task_id"));
    boolean waitForCompletion = request.paramAsBoolean("wait_for_completion", false);
    TimeValue timeout = request.paramAsTime("timeout", null);

    ListTasksRequest listTasksRequest = new ListTasksRequest();
    listTasksRequest.setTaskId(taskId);
    listTasksRequest.setNodesIds(nodesIds);
    listTasksRequest.setDetailed(detailed);
    listTasksRequest.setActions(actions);
    listTasksRequest.setParentTaskId(parentTaskId);
    listTasksRequest.setWaitForCompletion(waitForCompletion);
    listTasksRequest.setTimeout(timeout);
    client.admin().cluster().listTasks(listTasksRequest, new RestToXContentListener<ListTasksResponse>(channel));
}
 
Example 14
Source Project: flink   Source File: ElasticsearchSinkTestBase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the Elasticsearch sink works properly.
 */
public void runElasticsearchSinkTest() throws Exception {
	final String index = "elasticsearch-sink-test-index";

	final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

	DataStreamSource<Tuple2<Integer, String>> source = env.addSource(new SourceSinkDataTestKit.TestDataSourceFunction());

	source.addSink(createElasticsearchSinkForEmbeddedNode(
			1,
			CLUSTER_NAME,
			new SourceSinkDataTestKit.TestElasticsearchSinkFunction(index)));

	env.execute("Elasticsearch Sink Test");

	// verify the results
	Client client = embeddedNodeEnv.getClient();
	SourceSinkDataTestKit.verifyProducedSinkData(client, index);

	client.close();
}
 
Example 15
Source Project: Elasticsearch   Source File: RestForceMergeAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));
    mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions()));
    mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments()));
    mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes()));
    mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush()));
    client.admin().indices().forceMerge(mergeRequest, new RestBuilderListener<ForceMergeResponse>(channel) {
        @Override
        public RestResponse buildResponse(ForceMergeResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example 16
Source Project: crate   Source File: ReadOnlyNodeIntegrationTest.java    License: Apache License 2.0 5 votes vote down vote up
private SQLResponse executeWrite(String stmt, Object[] args) {
    if (writeExecutor == null) {
        writeExecutor = new SQLTransportExecutor(
            new SQLTransportExecutor.ClientProvider() {
                @Override
                public Client client() {
                    // make sure we use NOT the read-only client
                    return internalCluster().client(internalCluster().getNodeNames()[0]);
                }

                @Nullable
                @Override
                public String pgUrl() {
                    return null;
                }

                @Override
                public SQLOperations sqlOperations() {
                    // make sure we use NOT the read-only operations
                    return internalCluster().getInstance(SQLOperations.class, internalCluster().getNodeNames()[0]);
                }
            }
        );
    }
    response = writeExecutor.exec(stmt, args);
    return response;
}
 
Example 17
@Override
public Collection<Object> createComponents(Client client,
                                           ClusterService clusterService,
                                           ThreadPool threadPool,
                                           ResourceWatcherService resourceWatcherService,
                                           ScriptService scriptService,
                                           NamedXContentRegistry xContentRegistry) {
    Collection<Object> components = new ArrayList<>();
    components.add(pluginComponent);
    return components;
}
 
Example 18
public PatchableResourceApiAction(Settings settings, Path configPath, RestController controller, Client client,
        AdminDNs adminDNs, ConfigurationRepository cl, ClusterService cs,
                                  PrincipalExtractor principalExtractor, PrivilegesEvaluator evaluator, ThreadPool threadPool,
                                  AuditLog auditLog) {
    super(settings, configPath, controller, client, adminDNs, cl, cs, principalExtractor, evaluator, threadPool,
            auditLog);
}
 
Example 19
@Bean
@ConditionalOnMissingBean(DatabaseRepositoryFactory.class)
@ConditionalOnBean(value={Client.class, JsonSerializationFactory.class, DatabaseScrollingFactory.class})
DatabaseRepositoryFactory databaseRepositoryFactory(
  final Client client,
  final JsonSerializationFactory serialization,
  final DatabaseScrollingFactory factory) {
  return new ElasticSearchRepositoryFactory(serialization, client, factory);
}
 
Example 20
Source Project: Raigad   Source File: TestElasticsearchIndexManager.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRunIndexManagement() throws Exception {
    String serializedIndexMetadata = "[{\"retentionType\": \"yearly\", \"retentionPeriod\": 3, \"indexName\": \"nf_errors_log\"}]";
    when(config.getIndexMetadata()).thenReturn(serializedIndexMetadata);

    Map<String, IndexStats> indexStats = new HashMap<>();
    indexStats.put("nf_errors_log2018", new IndexStats("nf_errors_log2018", new ShardStats[]{}));
    indexStats.put("nf_errors_log2017", new IndexStats("nf_errors_log2017", new ShardStats[]{}));
    indexStats.put("nf_errors_log2016", new IndexStats("nf_errors_log2016", new ShardStats[]{}));
    indexStats.put("nf_errors_log2015", new IndexStats("nf_errors_log2015", new ShardStats[]{}));
    indexStats.put("nf_errors_log2014", new IndexStats("nf_errors_log2014", new ShardStats[]{}));
    indexStats.put("nf_errors_log2013", new IndexStats("nf_errors_log2013", new ShardStats[]{}));
    indexStats.put("nf_errors_log2012", new IndexStats("nf_errors_log2012", new ShardStats[]{}));

    IndicesStatsResponse indicesStatsResponse = mock(IndicesStatsResponse.class);
    when(indicesStatsResponse.getIndices()).thenReturn(indexStats);

    doReturn(indicesStatsResponse).when(elasticsearchIndexManager).getIndicesStatsResponse(elasticsearchClient);

    elasticsearchIndexManager.runIndexManagement();

    verify(elasticsearchIndexManager, times(1)).checkIndexRetention(any(Client.class), anySet(), any(IndexMetadata.class), any(DateTime.class));

    verify(elasticsearchIndexManager, times(1)).deleteIndices(any(Client.class), eq("nf_errors_log2012"), eq(AUTO_CREATE_INDEX_TIMEOUT));
    verify(elasticsearchIndexManager, times(1)).deleteIndices(any(Client.class), eq("nf_errors_log2013"), eq(AUTO_CREATE_INDEX_TIMEOUT));

    verify(elasticsearchIndexManager, times(0)).preCreateIndex(any(Client.class), any(IndexMetadata.class), any(DateTime.class));
}
 
Example 21
private KPIDataLoader(
		@NonNull final Client elasticsearchClient,
		@NonNull final KPI kpi,
		@NonNull final JSONOptions jsonOptions)
{
	this.elasticsearchClient = elasticsearchClient;
	this.kpi = kpi;
	this.jsonOptions = jsonOptions;
}
 
Example 22
@Override
protected void handleGet(RestChannel channel, RestRequest request, Client client, final JsonNode content) throws IOException{
    final SecurityDynamicConfiguration<?> configuration = load(getConfigName(), true);

    filter(configuration);

    successResponse(channel, configuration);
}
 
Example 23
Source Project: trident-elasticsearch   Source File: NodeClientFactory.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public Client makeClient(Map conf) {
    String clusterName = (String) conf.get(CLUSTER_NAME);
    synchronized (MUTEX) {
        LOG.info("Attaching node client to cluster: '{}'", clusterName);
        Node node = NODES.get(clusterName);
        if (node == null) {
            node = nodeBuilder().clusterName(clusterName).client(true).data(false).node();
            NODES.put(clusterName, node);
        }
        return node.client();
    }
}
 
Example 24
@Inject
public ResourceListingRequestHandler(Settings settings, Client client, RestController controller) {
    super(settings, controller, client);
    controller.registerHandler(GET, API_DOCS_PATH + "/v1.2", this);
    controller.registerHandler(GET, API_DOCS_PATH + "/index/{index}/v1.2/", this);
    controller.registerHandler(GET, API_DOCS_PATH + "/alias/{alias}/v1.2/", this);
}
 
Example 25
Source Project: elasticsearch-gatherer   Source File: AbstractNodeTest.java    License: Apache License 2.0 5 votes vote down vote up
public void closeAllNodes() {
    for (Client client : clients.values()) {
        client.close();
    }
    clients.clear();
    for (Node node : nodes.values()) {
        node.close();
    }
    nodes.clear();
}
 
Example 26
Source Project: ElasticUtils   Source File: ElasticSearchUtils.java    License: MIT License 5 votes vote down vote up
public static CreateIndexResponse createIndex(Client client, String indexName) {
    try {
        return internalCreateIndex(client, indexName);
    } catch(Exception e) {
        if(log.isErrorEnabled()) {
            log.error("Error Creating Index", e);
        }
        throw new CreateIndexFailedException(indexName, e);
    }
}
 
Example 27
@Inject
public RolesApiAction(Settings settings, final Path configPath, RestController controller, Client client, AdminDNs adminDNs, ConfigurationRepository cl,
		ClusterService cs, final PrincipalExtractor principalExtractor, final PrivilegesEvaluator evaluator, ThreadPool threadPool, AuditLog auditLog) {
	super(settings, configPath, controller, client, adminDNs, cl, cs, principalExtractor, evaluator, threadPool, auditLog);
	controller.registerHandler(Method.GET, "/_opendistro/_security/api/roles/", this);
	controller.registerHandler(Method.GET, "/_opendistro/_security/api/roles/{name}", this);
	controller.registerHandler(Method.DELETE, "/_opendistro/_security/api/roles/{name}", this);
	controller.registerHandler(Method.PUT, "/_opendistro/_security/api/roles/{name}", this);
       controller.registerHandler(Method.PATCH, "/_opendistro/_security/api/roles/", this);
       controller.registerHandler(Method.PATCH, "/_opendistro/_security/api/roles/{name}", this);

}
 
Example 28
@Override
protected void handlePost(RestChannel channel, final RestRequest request, final Client client, final JsonNode content) throws IOException {

	// Just do nothing here. Eligible authenticators will intercept calls and
	// provide own responses.
    successResponse(channel,"");
}
 
Example 29
Source Project: elasticsearch-auth   Source File: IndexAuthenticator.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public IndexAuthenticator(final Settings settings, final Client client,
        final AuthService authService) {
    super(settings);
    this.client = client;
    this.authService = authService;

    authIndex = settings.get("auth.authenticator.index.index", "auth");
    userType = settings.get("auth.authenticator.index.type", "user");
    usernameKey = settings.get("auth.authenticator.index.username",
            "username");
    passwordKey = settings.get("auth.authenticator.index.password",
            "password");

}
 
Example 30
public AuditLogImpl(final Settings settings, final Path configPath, Client clientProvider, ThreadPool threadPool,
					final IndexNameExpressionResolver resolver, final ClusterService clusterService) {
	super(settings, threadPool, resolver, clusterService);

	this.messageRouter = new AuditMessageRouter(settings, clientProvider, threadPool, configPath);
	this.enabled = messageRouter.isEnabled();

	log.info("Message routing enabled: {}", this.enabled);

	final SecurityManager sm = System.getSecurityManager();

	if (sm != null) {
		log.debug("Security Manager present");
		sm.checkPermission(new SpecialPermission());
	}

	AccessController.doPrivileged(new PrivilegedAction<Object>() {
		@Override
		public Object run() {
			Runtime.getRuntime().addShutdownHook(new Thread() {

				@Override
				public void run() {
					try {
						close();
					} catch (final IOException e) {
						log.warn("Exception while shutting down message router", e);
					}
				}
			});
			log.debug("Shutdown Hook registered");
			return null;
		}
	});

}