List of usage examples for java.net InetAddress equals
public boolean equals(Object obj)
From source file:eu.faircode.netguard.ActivityLog.java
@Override protected void onCreate(Bundle savedInstanceState) { Util.setTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.logging);/*from w w w . j av a 2s. c o m*/ running = true; // Action bar View actionView = getLayoutInflater().inflate(R.layout.actionlog, null, false); SwitchCompat swEnabled = actionView.findViewById(R.id.swEnabled); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(actionView); getSupportActionBar().setTitle(R.string.menu_log); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get settings final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); resolve = prefs.getBoolean("resolve", false); organization = prefs.getBoolean("organization", false); boolean log = prefs.getBoolean("log", false); // Show disabled message TextView tvDisabled = findViewById(R.id.tvDisabled); tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); // Set enabled switch swEnabled.setChecked(log); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { prefs.edit().putBoolean("log", isChecked).apply(); } }); // Listen for preference changes prefs.registerOnSharedPreferenceChangeListener(this); lvLog = findViewById(R.id.lvLog); boolean udp = prefs.getBoolean("proto_udp", true); boolean tcp = prefs.getBoolean("proto_tcp", true); boolean other = prefs.getBoolean("proto_other", true); boolean allowed = prefs.getBoolean("traffic_allowed", true); boolean blocked = prefs.getBoolean("traffic_blocked", true); adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve, organization); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString()); } }); lvLog.setAdapter(adapter); try { vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { PackageManager pm = getPackageManager(); Cursor cursor = (Cursor) adapter.getItem(position); long time = cursor.getLong(cursor.getColumnIndex("time")); int version = cursor.getInt(cursor.getColumnIndex("version")); int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); final String saddr = cursor.getString(cursor.getColumnIndex("saddr")); final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"))); final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"))); final String dname = cursor.getString(cursor.getColumnIndex("dname")); final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"))); // Get external address InetAddress addr = null; try { addr = InetAddress.getByName(daddr); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } String ip; int port; if (addr.equals(vpn4) || addr.equals(vpn6)) { ip = saddr; port = sport; } else { ip = daddr; port = dport; } // Build popup menu PopupMenu popup = new PopupMenu(ActivityLog.this, findViewById(R.id.vwPopupAnchor)); popup.inflate(R.menu.log); // Application name if (uid >= 0) popup.getMenu().findItem(R.id.menu_application) .setTitle(TextUtils.join(", ", Util.getApplicationNames(uid, ActivityLog.this))); else popup.getMenu().removeItem(R.id.menu_application); // Destination IP popup.getMenu().findItem(R.id.menu_protocol) .setTitle(Util.getProtocolName(protocol, version, false)); // Whois final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.tcpiputils.com/whois-lookup/" + ip)); if (pm.resolveActivity(lookupIP, 0) == null) popup.getMenu().removeItem(R.id.menu_whois); else popup.getMenu().findItem(R.id.menu_whois).setTitle(getString(R.string.title_log_whois, ip)); // Lookup port final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.speedguide.net/port.php?port=" + port)); if (port <= 0 || pm.resolveActivity(lookupPort, 0) == null) popup.getMenu().removeItem(R.id.menu_port); else popup.getMenu().findItem(R.id.menu_port).setTitle(getString(R.string.title_log_port, port)); if (!prefs.getBoolean("filter", false)) { popup.getMenu().removeItem(R.id.menu_allow); popup.getMenu().removeItem(R.id.menu_block); } final Packet packet = new Packet(); packet.version = version; packet.protocol = protocol; packet.daddr = daddr; packet.dport = dport; packet.time = time; packet.uid = uid; packet.allowed = (allowed > 0); // Time popup.getMenu().findItem(R.id.menu_time) .setTitle(SimpleDateFormat.getDateTimeInstance().format(time)); // Handle click popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_application: { Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; } case R.id.menu_whois: startActivity(lookupIP); return true; case R.id.menu_port: startActivity(lookupPort); return true; case R.id.menu_allow: if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) { DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 0); ServiceSinkhole.reload("allow host", ActivityLog.this, false); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); } else startActivity(new Intent(ActivityLog.this, ActivityPro.class)); return true; case R.id.menu_block: if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) { DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 1); ServiceSinkhole.reload("block host", ActivityLog.this, false); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); } else startActivity(new Intent(ActivityLog.this, ActivityPro.class)); return true; default: return false; } } }); // Show popup.show(); } }); live = true; }
From source file:org.lealone.cluster.locator.TokenMetaData.java
/** * Store an end-point to host ID mapping. Each ID must be unique, and * cannot be changed after the fact.// w ww .ja v a 2 s . c o m * * @param hostId * @param endpoint */ public void updateHostId(UUID hostId, InetAddress endpoint) { assert hostId != null; assert endpoint != null; lock.writeLock().lock(); try { InetAddress storedEp = endpointToHostIdMap.inverse().get(hostId); if (storedEp != null) { if (!storedEp.equals(endpoint) && (FailureDetector.instance.isAlive(storedEp))) { throw new RuntimeException( String.format("Host ID collision between active endpoint %s and %s (id=%s)", storedEp, endpoint, hostId)); } } UUID storedId = endpointToHostIdMap.get(endpoint); if ((storedId != null) && (!storedId.equals(hostId))) logger.warn("Changing {}'s host ID from {} to {}", endpoint, storedId, hostId); endpointToHostIdMap.forcePut(endpoint, hostId); } finally { lock.writeLock().unlock(); } }
From source file:org.lealone.cluster.locator.TokenMetaData.java
public void addBootstrapTokens(Collection<Token> tokens, InetAddress endpoint) { assert tokens != null && !tokens.isEmpty(); assert endpoint != null; lock.writeLock().lock();/*from ww w. ja v a2 s . c o m*/ try { InetAddress oldEndpoint; for (Token token : tokens) { oldEndpoint = bootstrapTokens.get(token); if (oldEndpoint != null && !oldEndpoint.equals(endpoint)) throw new RuntimeException("Bootstrap Token collision between " + oldEndpoint + " and " + endpoint + " (token " + token); oldEndpoint = tokenToEndpointMap.get(token); if (oldEndpoint != null && !oldEndpoint.equals(endpoint)) throw new RuntimeException("Bootstrap Token collision between " + oldEndpoint + " and " + endpoint + " (token " + token); } bootstrapTokens.removeValue(endpoint); for (Token token : tokens) bootstrapTokens.put(token, endpoint); } finally { lock.writeLock().unlock(); } }
From source file:com.zhengde163.netguard.ActivityLog.java
@Override protected void onCreate(Bundle savedInstanceState) { // Util.setTheme(this); setTheme(R.style.AppThemeBlue);//from w w w . j a v a 2 s . co m super.onCreate(savedInstanceState); setContentView(R.layout.logging); running = true; // Action bar View actionView = getLayoutInflater().inflate(R.layout.actionlog, null, false); // SwitchCompat swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled); ImageView ivEnabled = (ImageView) actionView.findViewById(R.id.ivEnabled); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(actionView); getSupportActionBar().setTitle(R.string.menu_log); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get settings final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); resolve = prefs.getBoolean("resolve", false); organization = prefs.getBoolean("organization", false); log = prefs.getBoolean("log", false); // Show disabled message // TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); // tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); final LinearLayout ly = (LinearLayout) findViewById(R.id.lldisable); ly.setVisibility(log ? View.GONE : View.VISIBLE); ImageView ivClose = (ImageView) findViewById(R.id.ivClose); ivClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ly.setVisibility(View.GONE); } }); // Set enabled switch // swEnabled.setChecked(log); if (ivEnabled != null) { if (log) { ivEnabled.setImageResource(R.drawable.on); } else { ivEnabled.setImageResource(R.drawable.off); } ivEnabled.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { log = !log; boolean isChecked = log; prefs.edit().putBoolean("log", isChecked).apply(); } }); } // swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // prefs.edit().putBoolean("log", isChecked).apply(); // } // }); // Listen for preference changes prefs.registerOnSharedPreferenceChangeListener(this); lvLog = (ListView) findViewById(R.id.lvLog); boolean udp = prefs.getBoolean("proto_udp", true); boolean tcp = prefs.getBoolean("proto_tcp", true); boolean other = prefs.getBoolean("proto_other", true); boolean allowed = prefs.getBoolean("traffic_allowed", true); boolean blocked = prefs.getBoolean("traffic_blocked", true); adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve, organization); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString()); } }); lvLog.setAdapter(adapter); try { vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { PackageManager pm = getPackageManager(); Cursor cursor = (Cursor) adapter.getItem(position); long time = cursor.getLong(cursor.getColumnIndex("time")); int version = cursor.getInt(cursor.getColumnIndex("version")); int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); final String saddr = cursor.getString(cursor.getColumnIndex("saddr")); final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"))); final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"))); final String dname = cursor.getString(cursor.getColumnIndex("dname")); final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"))); // Get external address InetAddress addr = null; try { addr = InetAddress.getByName(daddr); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } String ip; int port; if (addr.equals(vpn4) || addr.equals(vpn6)) { ip = saddr; port = sport; } else { ip = daddr; port = dport; } // Build popup menu PopupMenu popup = new PopupMenu(ActivityLog.this, findViewById(R.id.vwPopupAnchor)); popup.inflate(R.menu.log); // Application name if (uid >= 0) popup.getMenu().findItem(R.id.menu_application) .setTitle(TextUtils.join(", ", Util.getApplicationNames(uid, ActivityLog.this))); else popup.getMenu().removeItem(R.id.menu_application); // Destination IP popup.getMenu().findItem(R.id.menu_protocol) .setTitle(Util.getProtocolName(protocol, version, false)); // Whois final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.tcpiputils.com/whois-lookup/" + ip)); if (pm.resolveActivity(lookupIP, 0) == null) popup.getMenu().removeItem(R.id.menu_whois); else popup.getMenu().findItem(R.id.menu_whois).setTitle(getString(R.string.title_log_whois, ip)); // Lookup port final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.speedguide.net/port.php?port=" + port)); if (port <= 0 || pm.resolveActivity(lookupPort, 0) == null) popup.getMenu().removeItem(R.id.menu_port); else popup.getMenu().findItem(R.id.menu_port).setTitle(getString(R.string.title_log_port, port)); if (!prefs.getBoolean("filter", false)) { popup.getMenu().removeItem(R.id.menu_allow); popup.getMenu().removeItem(R.id.menu_block); } final Packet packet = new Packet(); packet.version = version; packet.protocol = protocol; packet.daddr = daddr; packet.dport = dport; packet.time = time; packet.uid = uid; packet.allowed = (allowed > 0); // Time popup.getMenu().findItem(R.id.menu_time) .setTitle(SimpleDateFormat.getDateTimeInstance().format(time)); // Handle click popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_application: { Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; } case R.id.menu_whois: startActivity(lookupIP); return true; case R.id.menu_port: startActivity(lookupPort); return true; case R.id.menu_allow: DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 0); ServiceSinkhole.reload("allow host", ActivityLog.this); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; case R.id.menu_block: DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 1); ServiceSinkhole.reload("block host", ActivityLog.this); Intent main1 = new Intent(ActivityLog.this, ActivityMain.class); main1.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main1); return true; default: return false; } } }); // Show popup.show(); } }); live = true; }
From source file:com.vuze.plugin.azVPN_Air.Checker.java
/** * @return rebind sucessful, or rebinding to already bound address *///w ww .j a v a2 s . c om private boolean rebindNetworkInterface(NetworkInterface networkInterface, InetAddress onlyToAddress, final StringBuilder sReply) { vpnIP = onlyToAddress; /** if (true) { sReply.append("Would rebind to " + networkInterface.getDisplayName() + onlyToAddress + "\n"); return false; } /**/ String ifName = networkInterface.getName(); String configBindIP = config.getCoreStringParameter(PluginConfig.CORE_PARAM_STRING_LOCAL_BIND_IP); int bindNetworkInterfaceIndex = -1; if (onlyToAddress != null) { Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); for (int j = 0; inetAddresses.hasMoreElements(); j++) { InetAddress element = inetAddresses.nextElement(); if (element.equals(onlyToAddress)) { bindNetworkInterfaceIndex = j; break; } } } if (configBindIP.equals(ifName) || (bindNetworkInterfaceIndex >= 0 && configBindIP.equals(ifName + "[" + bindNetworkInterfaceIndex + "]"))) { addReply(sReply, CHAR_GOOD, "airvpn.already.bound.good", new String[] { ifName }); } else { String newConfigBindIP = ifName; if (bindNetworkInterfaceIndex >= 0) { newConfigBindIP += "[" + bindNetworkInterfaceIndex + "]"; } final AESemaphore sem = new AESemaphore("AirVPN BindWait"); NetworkAdmin.getSingleton().addPropertyChangeListener(new NetworkAdminPropertyChangeListener() { public void propertyChanged(String property) { if (property.equals(NetworkAdmin.PR_DEFAULT_BIND_ADDRESS)) { sem.releaseForever(); NetworkAdmin.getSingleton().removePropertyChangeListener(this); addReply(sReply, CHAR_GOOD, "airvpn.bind.complete.triggered"); } } }); // I think setting CORE_PARAM_STRING_LOCAL_BIND_IP is actually synchronous // We set up a PropertyChangeListener in case it ever becomes asynchronous config.setCoreStringParameter(PluginConfig.CORE_PARAM_STRING_LOCAL_BIND_IP, newConfigBindIP); config.setUnsafeBooleanParameter("Enforce Bind IP", true); config.setUnsafeBooleanParameter("Check Bind IP On Start", true); config.setUnsafeBooleanParameter("upnp.enable", false); config.setUnsafeBooleanParameter("natpmp.enable", false); addReply(sReply, CHAR_GOOD, "airvpn.change.binding", new String[] { "" + newConfigBindIP, networkInterface.getName() + " (" + networkInterface.getDisplayName() + ")" }); sem.reserve(11000); return sem.isReleasedForever(); } return true; }
From source file:org.lealone.cluster.service.StorageService.java
private void updatePeerInfo(InetAddress endpoint) { if (endpoint.equals(Utils.getBroadcastAddress())) return;//from www .java 2 s . co m EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(endpoint); for (Map.Entry<ApplicationState, VersionedValue> entry : epState.getApplicationStateMap().entrySet()) { updatePeerInfo(endpoint, entry.getKey(), entry.getValue()); } }
From source file:org.opennms.ng.services.capsd.SuspectEventProcessor.java
/** * Responsible for setting the value of the 'isSnmpPrimary' field of the * ipInterface table to 'P' (Primary) for the primary SNMP interface * address./*from www .ja v a 2 s. c om*/ * * @param dbc Database connection. * @param node DbNodeEntry object representing the suspect interface's * parent node table entry * @param newPrimarySnmpIf New primary SNMP interface. * @param oldPrimarySnmpIf Old primary SNMP interface. * @throws java.sql.SQLException if an error occurs updating the ipInterface table */ static void setPrimarySnmpInterface(Connection dbc, DbNodeEntry node, InetAddress newPrimarySnmpIf, InetAddress oldPrimarySnmpIf) throws SQLException { if (newPrimarySnmpIf == null) { LOG.debug("setPrimarySnmpInterface: newSnmpPrimary is null, nothing to set, returning."); return; } else { LOG.debug("setPrimarySnmpInterface: newSnmpPrimary = {}", newPrimarySnmpIf); } // Verify that old and new primary interfaces are different // if (oldPrimarySnmpIf != null && oldPrimarySnmpIf.equals(newPrimarySnmpIf)) { // Old and new primary interfaces are the same LOG.debug("setPrimarySnmpInterface: Old and new primary interfaces are the same"); } // Set primary SNMP interface 'isSnmpPrimary' field to 'P' for primary // if (newPrimarySnmpIf != null) { LOG.debug("setPrimarySnmpInterface: Updating primary SNMP interface {}", str(newPrimarySnmpIf)); // Update the appropriate entry in the 'ipInterface' table // final DBUtils d = new DBUtils(SuspectEventProcessor.class); try { PreparedStatement stmt = dbc.prepareStatement( "UPDATE ipInterface SET isSnmpPrimary='P' WHERE nodeId=? AND ipaddr=? AND isManaged!='D'"); d.watch(stmt); stmt.setInt(1, node.getNodeId()); stmt.setString(2, str(newPrimarySnmpIf)); stmt.executeUpdate(); LOG.debug("setPrimarySnmpInterface: Completed update of new primary interface to PRIMARY."); } finally { d.cleanUp(); } } }
From source file:org.lealone.cluster.service.StorageService.java
public synchronized void start() throws ConfigurationException { if (started)/*ww w. j a v a 2 s. c o m*/ return; started = true; if (Boolean.parseBoolean(Config.getProperty("load.ring.state", "true"))) { logger.info("Loading persisted ring state"); Multimap<InetAddress, Token> loadedTokens = ClusterMetaData.loadTokens(); Map<InetAddress, UUID> loadedHostIds = ClusterMetaData.loadHostIds(); for (InetAddress ep : loadedTokens.keySet()) { if (ep.equals(Utils.getBroadcastAddress())) { // entry has been mistakenly added, delete it ClusterMetaData.removeEndpoint(ep); } else { tokenMetaData.updateNormalTokens(loadedTokens.get(ep), ep); if (loadedHostIds.containsKey(ep)) tokenMetaData.updateHostId(loadedHostIds.get(ep), ep); Gossiper.instance.addSavedEndpoint(ep); } } } addShutdownHook(); prepareToJoin(); if (Boolean.parseBoolean(Config.getProperty("join.ring", "true"))) { joinTokenRing(RING_DELAY); } else { Collection<Token> tokens = ClusterMetaData.getSavedTokens(); if (!tokens.isEmpty()) { tokenMetaData.updateNormalTokens(tokens, Utils.getBroadcastAddress()); // order is important here, the gossiper can fire in between adding these two states. // It's ok to send TOKENS without STATUS, but *not* vice versa. List<Pair<ApplicationState, VersionedValue>> states = new ArrayList<>(2); states.add(Pair.create(ApplicationState.TOKENS, VALUE_FACTORY.tokens(tokens))); states.add(Pair.create(ApplicationState.STATUS, VALUE_FACTORY.hibernate(true))); Gossiper.instance.addLocalApplicationStates(states); } logger.info( "Not joining ring as requested. Use JMX (StorageService->joinRing()) to initiate ring joining"); } }
From source file:edu.uci.ics.asterix.aoya.AsterixApplicationMaster.java
/** * Attempts to find the Node in the Cluster Description that matches this container * // w w w . j a v a 2s .c o m * @param c * The container to resolve * @return The node this container corresponds to * @throws java.net.UnknownHostException * if the container isn't present in the description */ Node containerToNode(Container c, Cluster cl) throws UnknownHostException { String containerHost = c.getNodeId().getHost(); InetAddress containerIp = InetAddress.getByName(containerHost); LOG.info("Resolved Container IP: " + containerIp); for (Node node : cl.getNode()) { InetAddress nodeIp = InetAddress.getByName(node.getClusterIp()); LOG.info(nodeIp + "?=" + containerIp); if (nodeIp.equals(containerIp)) return node; } //if we find nothing, this is bad... throw new java.net.UnknownHostException("Could not resolve container" + containerHost + " to node"); }
From source file:org.lealone.cluster.service.StorageService.java
/** * Handle notification that a node being actively removed from the ring via 'removenode' * * @param endpoint node/* www . j ava 2 s.co m*/ * @param pieces either REMOVED_TOKEN (node is gone) or REMOVING_TOKEN (replicas need to be restored) */ private void handleStateRemoving(InetAddress endpoint, String[] pieces) { assert (pieces.length > 0); if (endpoint.equals(Utils.getBroadcastAddress())) { logger.info( "Received removenode gossip about myself. Is this node rejoining after an explicit removenode?"); try { // drain(); } catch (Exception e) { throw new RuntimeException(e); } return; } if (tokenMetaData.isMember(endpoint)) { String state = pieces[0]; Collection<Token> removeTokens = tokenMetaData.getTokens(endpoint); if (VersionedValue.REMOVED_TOKEN.equals(state)) { excise(removeTokens, endpoint, extractExpireTime(pieces)); } else if (VersionedValue.REMOVING_TOKEN.equals(state)) { if (logger.isDebugEnabled()) logger.debug("Tokens {} removed manually (endpoint was {})", removeTokens, endpoint); // Note that the endpoint is being removed tokenMetaData.addLeavingEndpoint(endpoint); // find the endpoint coordinating this removal that we need to notify when we're done // String[] coordinator = Gossiper.instance.getEndpointStateForEndpoint(endpoint).getApplicationState( // ApplicationState.REMOVAL_COORDINATOR).value.split(VersionedValue.DELIMITER_STR, -1); // UUID hostId = UUID.fromString(coordinator[1]); } } else // now that the gossiper has told us about this nonexistent member, notify the gossiper to remove it { if (VersionedValue.REMOVED_TOKEN.equals(pieces[0])) addExpireTimeIfFound(endpoint, extractExpireTime(pieces)); removeEndpoint(endpoint); } }