private boolean thisHost(final HostStoreInfo host) { return host.getHost().equals(hostInfo.host()) && host.getPort() == hostInfo.port(); }
private boolean thisHost(final HostStoreInfo host) { return host.getHost().equals(hostInfo.host()) && host.getPort() == hostInfo.port(); }
/** * Start an embedded Jetty Server * @throws Exception */ void start() throws Exception { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); jettyServer = new Server(); jettyServer.setHandler(context); ResourceConfig rc = new ResourceConfig(); rc.register(this); rc.register(JacksonFeature.class); ServletContainer sc = new ServletContainer(rc); ServletHolder holder = new ServletHolder(sc); context.addServlet(holder, "/*"); final ServerConnector connector = new ServerConnector(jettyServer); connector.setHost(hostInfo.host()); connector.setPort(hostInfo.port()); jettyServer.addConnector(connector); context.start(); try { jettyServer.start(); } catch (final java.net.SocketException exception) { log.error("Unavailable: " + hostInfo.host() + ":" + hostInfo.port()); throw new Exception(exception.toString()); } }
public String host() { return hostInfo.host(); } public int port() {
private void encodePartitionsByHost(final DataOutputStream out) throws IOException { // encode partitions by host out.writeInt(partitionsByHost.size()); for (final Map.Entry<HostInfo, Set<TopicPartition>> entry : partitionsByHost.entrySet()) { final HostInfo hostInfo = entry.getKey(); out.writeUTF(hostInfo.host()); out.writeInt(hostInfo.port()); writeTopicPartitions(out, entry.getValue()); } }
@RequestMapping("/charts/top-five") @SuppressWarnings("unchecked") public List<SongPlayCountBean> topFive(@RequestParam(value="genre") String genre) { HostInfo hostInfo = interactiveQueryService.getHostInfo(KafkaStreamsInteractiveQuerySample.TOP_FIVE_SONGS_STORE, KafkaStreamsInteractiveQuerySample.TOP_FIVE_KEY, new StringSerializer()); if (interactiveQueryService.getCurrentHostInfo().equals(hostInfo)) { logger.info("Top Five songs request served from same host: " + hostInfo); return topFiveSongs(KafkaStreamsInteractiveQuerySample.TOP_FIVE_KEY, KafkaStreamsInteractiveQuerySample.TOP_FIVE_SONGS_STORE); } else { //find the store from the proper instance. logger.info("Top Five songs request served from different host: " + hostInfo); RestTemplate restTemplate = new RestTemplate(); return restTemplate.postForObject( String.format("http://%s:%d/%s", hostInfo.host(), hostInfo.port(), "charts/top-five?genre=Punk"), "punk", List.class); } }
RestTemplate restTemplate = new RestTemplate(); SongBean song = restTemplate.postForObject( String.format("http://%s:%d/%s", hostInfo.host(), hostInfo.port(), "song/idx?id=" + songPlayCount.getSongId()), "id", SongBean.class); results.add(new SongPlayCountBean(song.getArtist(),song.getAlbum(), song.getName(),