/** * Removes receiver and sender feedback from RTCP packets. * * @param inPacket the <tt>RTCPCompoundPacket</tt> to filter. * @return the filtered <tt>RawPacket</tt>. */ public RawPacket gateway(RTCPCompoundPacket inPacket) { if (inPacket == null || inPacket.packets == null || inPacket.packets.length == 0) { logger.info("Ignoring empty RTCP packet."); return null; } ArrayList<RTCPPacket> outPackets = new ArrayList<RTCPPacket>(inPacket.packets.length); for (RTCPPacket p : inPacket.packets) { switch (p.type) { case RTCPPacket.RR: case RTCPPacket.SR: case RTCPPacket.SDES: // We generate our own RR/SR/SDES packets. We only want // to forward NACKs/PLIs/etc. break; case RTCPFBPacket.PSFB: RTCPFBPacket psfb = (RTCPFBPacket) p; switch (psfb.fmt) { case RTCPREMBPacket.FMT: // We generate its own REMB packets. break; default: // We let through everything else, like NACK // packets. outPackets.add(psfb); break; } break; default: // We let through everything else, like BYE and APP // packets. outPackets.add(p); break; } } if (outPackets.size() == 0) { return null; } // We have feedback messages to send. Pack them in a compound // RR and send them. TODO Use RFC5506 Reduced-Size RTCP, if the // receiver supports it. Collection<RTCPRRPacket> rrPackets = makeRTCPRRPackets(System.currentTimeMillis()); if (rrPackets != null && rrPackets.size() != 0) { outPackets.addAll(0, rrPackets); } else { logger.warn("We might be sending invalid RTCPs."); } RTCPPacket[] pkts = outPackets.toArray(new RTCPPacket[outPackets.size()]); RTCPCompoundPacket outPacket = new RTCPCompoundPacket(pkts); return generator.apply(outPacket); }
@VisibleForTesting List<String> processMessage(String message) { // Split leaves a trailing empty line if there's a terminating newline. ArrayList<String> split = Lists.newArrayList(message.split("\r?\n", -1)); Preconditions.checkArgument(split.size() > 0); synchronized (this) { buffer.append(split.get(0)); if (split.size() == 1) // no newlines. return ImmutableList.of(); split.set(0, buffer.toString()); buffer = new StringBuilder().append(split.remove(split.size() - 1)); } return split; }
private void getServersFile() throws Exception { InputStream is = this.getClass().getResourceAsStream("/servers"); if (is == null) throw new IOException("Cannot find servers file"); BufferedReader br = new BufferedReader(new InputStreamReader(is)); configuredServers.clear(); String line; while ((line = br.readLine()) != null) { configuredServers.add(line); } Collections.sort(configuredServers); if (configuredServers.size() < 1) throw new IOException("No entries found in servers file"); int lnum = 1; for (int i = 0; i < configuredServers.size(); i++) { LOG.debug("servers file line " + lnum + " [" + configuredServers.get(i) + "]"); lnum++; } }
/*public int numTickGroups() { return ticks.size(); }*/ public String[][] threadInfo() { ArrayList<String[]> V = new ArrayList(); for (Iterator<CMLibrary> e = CMLib.libraries(); e.hasNext(); ) { CMLibrary lib = e.next(); SupportThread thread = lib.getSupportThread(); if (thread != null) { String[] S = new String[3]; S[0] = thread.getName(); S[1] = CMLib.english().returnTime(thread.milliTotal, thread.tickTotal); S[2] = thread.status; V.add(S); } } return V.toArray(new String[V.size()][]); }
private synchronized void getZkRunning() throws Exception { LOG.debug("Reading " + parentZnode + Constants.DEFAULT_ZOOKEEPER_ZNODE_SERVERS_RUNNING); List<String> children = getChildren( parentZnode + Constants.DEFAULT_ZOOKEEPER_ZNODE_SERVERS_RUNNING, new RunningWatcher()); if (!children.isEmpty()) { for (String child : children) { // If stop-wms.sh is executed and WMS_MANAGES_ZK then zookeeper // is stopped abruptly. // Second scenario is when ZooKeeper fails for some reason // regardless of whether WMS // manages it. When either happens the WmsServer running znodes // still exist in ZooKeeper // and we see them at next startup. When they eventually timeout // we get node deleted events for a server that no longer // exists. So, only recognize // WmsServer running znodes that have timestamps after last // WmsMaster startup. Scanner scn = new Scanner(child); scn.useDelimiter(":"); String hostName = scn.next(); String instance = scn.next(); int infoPort = Integer.parseInt(scn.next()); long serverStartTimestamp = Long.parseLong(scn.next()); scn.close(); if (serverStartTimestamp < startupTimestamp) continue; if (!runningServers.contains(child)) { LOG.debug("Watching running [" + child + "]"); zkc.exists( parentZnode + Constants.DEFAULT_ZOOKEEPER_ZNODE_SERVERS_RUNNING + "/" + child, new RunningWatcher()); runningServers.add(child); } } metrics.setTotalRunning(runningServers.size()); } else { metrics.setTotalRunning(0); } }
private synchronized void restartServer(String znodePath) throws Exception { String child = znodePath.replace( parentZnode + Constants.DEFAULT_ZOOKEEPER_ZNODE_SERVERS_RUNNING + "/", ""); Scanner scn = new Scanner(child); scn.useDelimiter(":"); String hostName = scn.next(); String instance = scn.next(); int infoPort = Integer.parseInt(scn.next()); long serverStartTimestamp = Long.parseLong(scn.next()); scn.close(); LOG.error("WmsServer [" + hostName + ":" + instance + "] failed."); if (runningServers.contains(child)) { LOG.debug("Found [" + child + "], deleting from running servers list"); runningServers.remove(child); metrics.setTotalRunning(runningServers.size()); } RestartHandler handler = new RestartHandler(child); restartQueue.add(handler); }
String[] getPluginDirectories() { ArrayList<String> directories = new ArrayList<String>(); PackageManager pm = this.mAppContext.getPackageManager(); List<ResolveInfo> plugins = pm.queryIntentServices( new Intent(PLUGIN_ACTION), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA); synchronized (mPackageInfoCache) { // clear the list of existing packageInfo objects mPackageInfoCache.clear(); for (ResolveInfo info : plugins) { // retrieve the plugin's service information ServiceInfo serviceInfo = info.serviceInfo; if (serviceInfo == null) { Log.w(LOGTAG, "Ignore bad plugin"); continue; } Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName); // retrieve information from the plugin's manifest PackageInfo pkgInfo; try { pkgInfo = pm.getPackageInfo( serviceInfo.packageName, PackageManager.GET_PERMISSIONS | PackageManager.GET_SIGNATURES); } catch (Exception e) { Log.w(LOGTAG, "Can't find plugin: " + serviceInfo.packageName); continue; } if (pkgInfo == null) { Log.w( LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Could not load package information."); continue; } /* * find the location of the plugin's shared library. The default * is to assume the app is either a user installed app or an * updated system app. In both of these cases the library is * stored in the app's data directory. */ String directory = pkgInfo.applicationInfo.dataDir + "/lib"; final int appFlags = pkgInfo.applicationInfo.flags; final int updatedSystemFlags = ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; // preloaded system app with no user updates if ((appFlags & updatedSystemFlags) == ApplicationInfo.FLAG_SYSTEM) { directory = PLUGIN_SYSTEM_LIB + pkgInfo.packageName; } // check if the plugin has the required permissions String permissions[] = pkgInfo.requestedPermissions; if (permissions == null) { Log.w( LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission."); continue; } boolean permissionOk = false; for (String permit : permissions) { if (PLUGIN_PERMISSION.equals(permit)) { permissionOk = true; break; } } if (!permissionOk) { Log.w( LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission (2)."); continue; } // check to ensure the plugin is properly signed Signature signatures[] = pkgInfo.signatures; if (signatures == null) { Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Not signed."); continue; } // determine the type of plugin from the manifest if (serviceInfo.metaData == null) { Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined"); continue; } String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE); if (!TYPE_NATIVE.equals(pluginType)) { Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType); continue; } try { Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name); // TODO implement any requirements of the plugin class here! boolean classFound = true; if (!classFound) { Log.e( LOGTAG, "The plugin's class' " + serviceInfo.name + "' does not extend the appropriate class."); continue; } } catch (NameNotFoundException e) { Log.e(LOGTAG, "Can't find plugin: " + serviceInfo.packageName); continue; } catch (ClassNotFoundException e) { Log.e(LOGTAG, "Can't find plugin's class: " + serviceInfo.name); continue; } // if all checks have passed then make the plugin available mPackageInfoCache.add(pkgInfo); directories.add(directory); } } return directories.toArray(new String[directories.size()]); }
public void deinit(Appendable out, boolean force) throws Exception { Settings settings = new Settings(platform.getConfigFile()); if (!force) { Justif justify = new Justif(80, 40); StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); try { String list = listFiles(platform.getGlobal()); if (list != null) { f.format("In global default environment:%n"); f.format(list); } list = listFiles(platform.getLocal()); if (list != null) { f.format("In local default environment:%n"); f.format(list); } if (settings.containsKey(JPM_CACHE_GLOBAL)) { list = listFiles(IO.getFile(settings.get(JPM_CACHE_GLOBAL))); if (list != null) { f.format("In global configured environment:%n"); f.format(list); } } if (settings.containsKey(JPM_CACHE_LOCAL)) { list = listFiles(IO.getFile(settings.get(JPM_CACHE_LOCAL))); if (list != null) { f.format("In local configured environment:%n"); f.format(list); } } list = listSupportFiles(); if (list != null) { f.format("jpm support files:%n"); f.format(list); } f.format("%n%n"); f.format( "All files listed above will be deleted if deinit is run with the force flag set" + " (\"jpm deinit -f\" or \"jpm deinit --force\"%n%n"); f.flush(); justify.wrap(sb); out.append(sb.toString()); } finally { f.close(); } } else { // i.e. if(force) int count = 0; File[] caches = {platform.getGlobal(), platform.getLocal(), null, null}; if (settings.containsKey(JPM_CACHE_LOCAL)) { caches[2] = IO.getFile(settings.get(JPM_CACHE_LOCAL)); } if (settings.containsKey(JPM_CACHE_GLOBAL)) { caches[3] = IO.getFile(settings.get(JPM_CACHE_GLOBAL)); } ArrayList<File> toDelete = new ArrayList<File>(); for (File cache : caches) { if (cache == null || !cache.exists()) { continue; } listFiles(cache, toDelete); if (toDelete.size() > count) { count = toDelete.size(); if (!cache.canWrite()) { reporter.error(PERMISSION_ERROR + " (" + cache + ")"); return; } toDelete.add(cache); } } listSupportFiles(toDelete); for (File f : toDelete) { if (f.exists() && !f.canWrite()) { reporter.error(PERMISSION_ERROR + " (" + f + ")"); } } if (reporter.getErrors().size() > 0) { return; } for (File f : toDelete) { if (f.exists()) { IO.deleteWithException(f); } } } }
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner non-commercial license dialogPane = new JPanel(); contentPanel = new JPanel(); panel1 = new JPanel(); label2 = new JLabel(); ttfSizeW = new JTextField(); label4 = new JLabel(); ttfLongi = new JTextField(); btnGetMap = new JButton(); label3 = new JLabel(); ttfSizeH = new JTextField(); label5 = new JLabel(); ttfLati = new JTextField(); btnQuit = new JButton(); label1 = new JLabel(); ttfLicense = new JTextField(); label6 = new JLabel(); ttfZoom = new JTextField(); // ComboBox for Saved Locations ttfSave = new JComboBox(); scrollPane1 = new JScrollPane(); ttaStatus = new JTextArea(); panel2 = new JPanel(); panel3 = new JPanel(); checkboxRecvStatus = new JCheckBox(); checkboxSendStatus = new JCheckBox(); ttfProgressMsg = new JTextField(); progressBar = new JProgressBar(); lblProgressStatus = new JLabel(); // ======== this ======== setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setTitle("Google Static Maps"); setIconImage(null); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); // ======== dialogPane ======== { dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); dialogPane.setOpaque(false); dialogPane.setLayout(new BorderLayout()); // ======== contentPanel ======== { contentPanel.setOpaque(false); contentPanel.setLayout( new TableLayout( new double[][] { {TableLayout.FILL}, {TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED} })); ((TableLayout) contentPanel.getLayout()).setHGap(5); ((TableLayout) contentPanel.getLayout()).setVGap(5); // ======== panel1 ======== { panel1.setOpaque(false); panel1.setBorder( new CompoundBorder( new TitledBorder("Configure the inputs to Google Static Maps"), Borders.DLU2_BORDER)); panel1.setLayout( new TableLayout( new double[][] { {0.17, 0.17, 0.17, 0.17, 0.05, TableLayout.FILL}, {TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED} })); ((TableLayout) panel1.getLayout()).setHGap(5); ((TableLayout) panel1.getLayout()).setVGap(5); // ---- label2 ---- label2.setText("Size Width"); label2.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label2, new TableLayoutConstraints( 0, 0, 0, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfSizeW ---- ttfSizeW.setText("512"); panel1.add( ttfSizeW, new TableLayoutConstraints( 1, 0, 1, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- label4 ---- label4.setText("Latitude"); label4.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label4, new TableLayoutConstraints( 2, 0, 2, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfLongi ---- ttfLongi.setText("38.931099"); panel1.add( ttfLongi, new TableLayoutConstraints( 3, 0, 3, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- btnGetMap ---- btnGetMap.setText("Get Map"); btnGetMap.setHorizontalAlignment(SwingConstants.LEFT); btnGetMap.setMnemonic('G'); btnGetMap.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { startTaskAction(); if (Integer.parseInt(ttfZoom.getText()) < 14) { // coding for zoom values under 14 for (int i = 0; i < 14; i++) { if (Integer.parseInt(ttfZoom.getText()) == i) { countThis = 14 - i; // gets difference do { counter = counter * 2; // found out code zooms in powers of 2. pixelX = 0.000084525 * counter; // Values per Latitude, trial and error method used to // find these numbers. pixelY = 0.00006725 * counter; // Values per Longitude counter1++; } while (counter1 != countThis); // loops the amount of differences } counter = 1; // Resetters counter1 = 0; } } else if (Integer.parseInt(ttfZoom.getText()) > 14) { // coding for zoom values over 14 for (int i = 14; i < 19; i++) { if (Integer.parseInt(ttfZoom.getText()) == i) { countThis = i - 14; // gets difference do { counter = counter * 2; pixelX = 0.000084525 / counter; // Values per Latitude pixelY = 0.00006725 / counter; // Values per Longitude counter1++; } while (counter1 != countThis); // loops amount of differences } counter = 1; // Resetters counter1 = 0; } } else { // coding for zoom default value of 14. pixelX = 0.000084525; pixelY = 0.00006725; } BigDecimal sendPixelX = new BigDecimal(pixelX); BigDecimal sendPixelY = new BigDecimal(pixelY); pixelX = (sendPixelX.setScale(6, BigDecimal.ROUND_HALF_UP)) .doubleValue(); // allows for bigger decimal zoom variables pixelY = (sendPixelY.setScale(6, BigDecimal.ROUND_HALF_UP)) .doubleValue(); // Won't reach zoom 1-5 without these! } }); panel1.add( btnGetMap, new TableLayoutConstraints( 5, 0, 5, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- label3 ---- label3.setText("Size Height"); label3.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label3, new TableLayoutConstraints( 0, 1, 0, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfSizeH ---- ttfSizeH.setText("512"); panel1.add( ttfSizeH, new TableLayoutConstraints( 1, 1, 1, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- label5 ---- label5.setText("Longitude"); label5.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label5, new TableLayoutConstraints( 2, 1, 2, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfLati ---- ttfLati.setText("-77.3489"); panel1.add( ttfLati, new TableLayoutConstraints( 3, 1, 3, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- btnQuit ---- btnQuit.setText("Quit"); btnQuit.setMnemonic('Q'); btnQuit.setHorizontalAlignment(SwingConstants.LEFT); btnQuit.setHorizontalTextPosition(SwingConstants.RIGHT); btnQuit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { quitProgram(); } }); panel1.add( btnQuit, new TableLayoutConstraints( 5, 1, 5, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- label1 ---- label1.setText("License Key"); label1.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label1, new TableLayoutConstraints( 0, 2, 0, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfLicense ---- ttfLicense.setToolTipText("Enter your own URI for a file to download in the background"); panel1.add( ttfLicense, new TableLayoutConstraints( 1, 2, 1, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- label6 ---- label6.setText("Zoom"); label6.setHorizontalAlignment(SwingConstants.RIGHT); panel1.add( label6, new TableLayoutConstraints( 2, 2, 2, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfZoom ---- ttfZoom.setText("14"); panel1.add( ttfZoom, new TableLayoutConstraints( 3, 2, 3, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfSave ---- ttfSave.removeAllItems(); // JComboBox ttfSave = new JComboBox(); getSavedLocations(); // grabs a new list for (int i = 0; i < loc.size(); i++) // populates this list using a arrayList ttfSave.addItem(loc.get(i)); ttfSave.setSelectedIndex(0); panel1.add( ttfSave, new TableLayoutConstraints( 5, 2, 5, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // Action Listener to update the coordinates on selected Location ttfSave.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (mapIsUp == 0) { Object contents = ttfSave.getSelectedItem(); // grabs users selection System.out.println(contents); if (contents != null) { stringCoords = contents.toString(); setCoords = stringCoords.split("\\s+"); ttfLongi.setText( setCoords[ 1]); // sets the texts in the longitude and latitude fields to // coordinates selected ttfLati.setText(setCoords[0]); } } } }); } contentPanel.add( panel1, new TableLayoutConstraints( 0, 0, 0, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ======== scrollPane1 ======== { scrollPane1.setBorder( new TitledBorder("System.out - displays all status and progress messages, etc.")); scrollPane1.setOpaque(false); // ---- ttaStatus ---- ttaStatus.setBorder(Borders.createEmptyBorder("1dlu, 1dlu, 1dlu, 1dlu")); ttaStatus.setToolTipText( "<html>Task progress updates (messages) are displayed here,<br>along with any other output generated by the Task.<html>"); scrollPane1.setViewportView(ttaStatus); } contentPanel.add( scrollPane1, new TableLayoutConstraints( 0, 1, 0, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ======== panel2 ======== { panel2.setOpaque(false); panel2.setBorder( new CompoundBorder( new TitledBorder("Status - control progress reporting"), Borders.DLU2_BORDER)); panel2.setLayout( new TableLayout( new double[][] { {0.45, TableLayout.FILL, 0.45}, {TableLayout.PREFERRED, TableLayout.PREFERRED} })); ((TableLayout) panel2.getLayout()).setHGap(5); ((TableLayout) panel2.getLayout()).setVGap(5); // ======== panel3 ======== { panel3.setOpaque(false); panel3.setLayout(new GridLayout(1, 2)); // ---- checkboxRecvStatus ---- checkboxRecvStatus.setText("Enable \"Recieve\""); checkboxRecvStatus.setOpaque(false); checkboxRecvStatus.setToolTipText("Task will fire \"send\" status updates"); checkboxRecvStatus.setSelected(true); panel3.add(checkboxRecvStatus); // ---- checkboxSendStatus ---- checkboxSendStatus.setText("Enable \"Send\""); checkboxSendStatus.setOpaque(false); checkboxSendStatus.setToolTipText("Task will fire \"recieve\" status updates"); panel3.add(checkboxSendStatus); } panel2.add( panel3, new TableLayoutConstraints( 0, 0, 0, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- ttfProgressMsg ---- ttfProgressMsg.setText("Loading map from Google Static Maps"); ttfProgressMsg.setToolTipText("Set the task progress message here"); panel2.add( ttfProgressMsg, new TableLayoutConstraints( 2, 0, 2, 0, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- progressBar ---- progressBar.setStringPainted(true); progressBar.setString("progress %"); progressBar.setToolTipText("% progress is displayed here"); panel2.add( progressBar, new TableLayoutConstraints( 0, 1, 0, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); // ---- lblProgressStatus ---- lblProgressStatus.setText("task status listener"); lblProgressStatus.setHorizontalTextPosition(SwingConstants.LEFT); lblProgressStatus.setHorizontalAlignment(SwingConstants.LEFT); lblProgressStatus.setToolTipText( "Task status messages are displayed here when the task runs"); panel2.add( lblProgressStatus, new TableLayoutConstraints( 2, 1, 2, 1, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); } contentPanel.add( panel2, new TableLayoutConstraints( 0, 2, 0, 2, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); } dialogPane.add(contentPanel, BorderLayout.CENTER); } contentPane.add(dialogPane, BorderLayout.CENTER); setSize(675, 485); setLocationRelativeTo(null); // JFormDesigner - End of component initialization //GEN-END:initComponents }