private void createPlaylist() { String showName = MediaFileAPI.GetMediaTitle(mediaFile); int numberOfMediaFileSegments = MediaFileAPI.GetNumberOfSegments(mediaFile); Log.debug("Number of media file segments: " + numberOfMediaFileSegments); for (int i = 0; i < numberOfMediaFileSegments; i++) { // get length of current media file segment long mediaFileSegmentDurationInMillis = MediaFileAPI.GetDurationForSegment(mediaFile, i); long mediaFileSegmentDurationInSeconds = mediaFileSegmentDurationInMillis / 1000; // milliseconds to seconds Log.debug( "mediaFileSegmentDurationInMillis (" + i + "): " + mediaFileSegmentDurationInMillis); Log.debug( "mediaFileSegmentDurationInSeconds (" + i + "): " + mediaFileSegmentDurationInSeconds); int sequence = 0; for (int j = 0; j < mediaFileSegmentDurationInSeconds; j += SegmentPlaylist.TARGET_DURATION) { long currentDuration = Math.min(SegmentPlaylist.TARGET_DURATION, mediaFileSegmentDurationInSeconds - j); Segment newSegment = new Segment(currentDuration, sequence, i, showName); segmentList.add(newSegment); sequence++; } } if (segmentList != null) { Log.debug("segmentList size: " + segmentList.size()); } }
/* ------------------------------------------------------------ */ protected void doStart() throws Exception { if (_server == null) throw new IllegalStateException("No server"); // open listener port open(); super.doStart(); if (_threadPool == null) _threadPool = _server.getThreadPool(); if (_threadPool != _server.getThreadPool() && (_threadPool instanceof LifeCycle)) ((LifeCycle) _threadPool).start(); // Start selector thread synchronized (this) { _acceptorThread = new Thread[getAcceptors()]; for (int i = 0; i < _acceptorThread.length; i++) { if (!_threadPool.dispatch(new Acceptor(i))) { Log.warn("insufficient maxThreads configured for {}", this); break; } } } Log.info("Started {}", this); }
static { try { org.mortbay.log.Log.setLog(new org.mortbay.log.Slf4jLog()); } catch (Throwable t) { logger.error(t.getMessage(), t); } }
public NodeHeartbeatResponse nodeHeartbeat( Map<ApplicationId, List<ContainerStatus>> conts, boolean isHealthy, int resId) throws Exception { NodeHeartbeatRequest req = Records.newRecord(NodeHeartbeatRequest.class); NodeStatus status = Records.newRecord(NodeStatus.class); status.setResponseId(resId); status.setNodeId(nodeId); for (Map.Entry<ApplicationId, List<ContainerStatus>> entry : conts.entrySet()) { Log.info("entry.getValue() " + entry.getValue()); status.setContainersStatuses(entry.getValue()); } NodeHealthStatus healthStatus = Records.newRecord(NodeHealthStatus.class); healthStatus.setHealthReport(""); healthStatus.setIsNodeHealthy(isHealthy); healthStatus.setLastHealthReportTime(1); status.setNodeHealthStatus(healthStatus); req.setNodeStatus(status); req.setLastKnownContainerTokenMasterKey(this.currentContainerTokenMasterKey); req.setLastKnownNMTokenMasterKey(this.currentNMTokenMasterKey); NodeHeartbeatResponse heartbeatResponse = resourceTracker.nodeHeartbeat(req); MasterKey masterKeyFromRM = heartbeatResponse.getContainerTokenMasterKey(); if (masterKeyFromRM != null && masterKeyFromRM.getKeyId() != this.currentContainerTokenMasterKey.getKeyId()) { this.currentContainerTokenMasterKey = masterKeyFromRM; } masterKeyFromRM = heartbeatResponse.getNMTokenMasterKey(); if (masterKeyFromRM != null && masterKeyFromRM.getKeyId() != this.currentNMTokenMasterKey.getKeyId()) { this.currentNMTokenMasterKey = masterKeyFromRM; } return heartbeatResponse; }
public ArrayList fiterOYPContent(String content) { ArrayList result = new ArrayList(); Matcher m = p2.matcher(content); Log.info(content); while (m.find()) { ArrayList line = new ArrayList(); String no = m.group(1); String oz = m.group(4); String oh = m.group(7); String ok = m.group(11); String yz = m.group(2); String yh = m.group(6); String yk = m.group(9); line.add(no); line.add(oz); line.add(oh); line.add(ok); line.add(yz); line.add(yh); line.add(yk); result.add(line); } return result; }
protected void startJetty() throws Exception { // Bridge Jetty logging to Android logging // TODO: Make configurable AndroidLog.__isDebugEnabled = false; System.setProperty("org.mortbay.log.class", "org.mortbay.log.AndroidLog"); org.mortbay.log.Log.setLog(new AndroidLog()); // Set jetty.home System.setProperty("jetty.home", IJetty.__JETTY_DIR.getAbsolutePath()); server = newServer(); configureConnectors(); configureHandlers(); configureDeployers(); configureRealm(); server.start(); // TODO // Less than ideal solution to the problem that dalvik doesn't know about manifests of jars. // A as the version field is private to Server, its difficult // if not impossible to set it any other way. Note this means that // ContextHandler.SContext.getServerInfo() // will still return 0.0. HttpGenerator.setServerVersion("i-jetty " + pi.versionName); }
public void fetchOYPData() { this.logger.info("[{}]线程开始执行,欧亚盘指数..."); String year = DateUtils.formatDate(new Date(), "yyyy"); String content; try { String url = "http://www.cailele.com/lottery/dcspf/spfhomeAction.php?term="; String pContent = HttpUtil.getContentByURL(FetchConstant.CURPERIOD_URL, false); Pattern p4 = Pattern.compile(FetchConstant.CUR_PERIOD); Matcher m = p4.matcher(pContent); if (m.find()) { String period = year.substring(2, year.length()) + m.group(1).substring(1, m.group(1).length()); url = "http://www.cailele.com/lottery/dcspf/spfhomeAction.php?term=" + period; Log.info("==============【" + url + "】============"); } else { url = FetchConstant.OYP_URL; } content = HttpUtil.getContentByURL(url, false); // ArrayList datas = fiterOYPContent(content); // BuildOYPXMLDoc(datas); // } catch (JDOMException e) { // e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } this.logger.info("[{}]线程开始执行结束,欧亚盘指数..."); }
protected void setMessage(String message) { try { if (_formEncoded) setRequestContent(new ByteArrayBuffer("message=" + URLEncoder.encode(message, "utf-8"))); else setRequestContent(new ByteArrayBuffer(message, "utf-8")); } catch (Exception e) { Log.warn(e); } }
// clarify with Tomcat, whether this is on a per Session or SessionManager basis... public void setMaxInactiveInterval(int interval) { checkState(); try { _state.setMaxInactiveInterval(interval); } catch (RemoteException e) { Log.warn("could not set MaxInactiveInterval", e); } }
public void removeState(State state) { try { synchronized (_sessions) { _sessions.remove(state.getId()); } } catch (Exception e) { Log.warn("could not remove session", e); } }
public void storeState(State state) { try { synchronized (_sessions) { _sessions.put(state.getId(), state); } } catch (Exception e) { Log.warn("could not store session"); } }
public boolean dispatch(Runnable job) { try { executor.execute(job); return true; } catch (RejectedExecutionException e) { Log.warn(e); return false; } }
/** * Construct a resource from a string. * * @param resource A URL or filename. * @param useCaches controls URLConnection caching * @return A Resource object. */ public static Resource newResource(String resource, boolean useCaches) throws MalformedURLException, IOException { URL url = null; try { // Try to format as a URL? url = new URL(resource); } catch (MalformedURLException e) { if (!resource.startsWith("ftp:") && !resource.startsWith("file:") && !resource.startsWith("jar:")) { try { // It's a file. if (resource.startsWith("./")) resource = resource.substring(2); File file = new File(resource).getCanonicalFile(); url = file.toURI().toURL(); URLConnection connection = url.openConnection(); connection.setUseCaches(useCaches); FileResource fileResource = new FileResource(url, connection, file); return fileResource; } catch (Exception e2) { Log.debug(Log.EXCEPTION, e2); throw e; } } else { Log.warn("Bad Resource: " + resource); throw e; } } // Make sure that any special characters stripped really are ignorable. String nurl = url.toString(); if (nurl.length() > 0 && nurl.charAt(nurl.length() - 1) != resource.charAt(resource.length() - 1)) { if ((nurl.charAt(nurl.length() - 1) != '/' || nurl.charAt(nurl.length() - 2) != resource.charAt(resource.length() - 1)) && (resource.charAt(resource.length() - 1) != '/' || resource.charAt(resource.length() - 2) != nurl.charAt(nurl.length() - 1))) { return new BadResource(url, "Trailing special characters stripped by URL in " + resource); } } return newResource(url); }
public void setLastAccessedTime(long time) throws IllegalStateException { checkState(); try { _state.setLastAccessedTime(time); } catch (RemoteException e) { Log.warn("could not set LastAccessedTime", e); throw new IllegalStateException("problem with distribution layer"); } }
public void removeValue(String name) throws IllegalStateException { checkState(); try { _state.removeAttribute(name, false); } catch (RemoteException e) { Log.warn("could not remove Value", e); throw new IllegalStateException("problem with distribution layer"); } }
public Enumeration getAttributeNames() throws IllegalStateException { checkState(); try { return _state.getAttributeNameEnumeration(); } catch (RemoteException e) { Log.warn("could not get AttributeNames", e); throw new IllegalStateException("problem with distribution layer"); } }
public Object getValue(String name) throws IllegalStateException { checkState(); try { return _state.getAttribute(name); } catch (RemoteException e) { Log.warn("could not get Value", e); throw new IllegalStateException("problem with distribution layer"); } }
public long getCreationTime() throws IllegalStateException { checkState(); try { return _state.getCreationTime(); } catch (RemoteException e) { Log.warn("could not get CreationTime", e); throw new IllegalStateException("problem with distribution layer"); } }
public String[] getValueNames() throws IllegalStateException { checkState(); try { return _state.getAttributeNameStringArray(); } catch (RemoteException e) { Log.warn("could not get ValueNames", e); throw new IllegalStateException("problem with distribution layer"); } }
@GET @Produces(MediaType.WILDCARD) public Response redirectToWebadmin() { try { return Response.seeOther(new URI(Configurator.DEFAULT_WEB_ADMIN_PATH)).build(); } catch (URISyntaxException e) { Log.warn(e.getMessage()); return Response.serverError().build(); } }
/* ------------------------------------------------------------ */ protected void onConnectionFailed(Throwable ex) { super.onConnectionFailed(ex); if (++_connectFailures < 5) { try { _client.send(this); } catch (IOException e) { Log.warn(e); } } }
/* ------------------------------------------------------------ */ protected void configure(Socket socket) throws IOException { try { socket.setTcpNoDelay(true); if (_maxIdleTime >= 0) socket.setSoTimeout(_maxIdleTime); if (_soLingerTime >= 0) socket.setSoLinger(true, _soLingerTime / 1000); else socket.setSoLinger(false, 0); } catch (Exception e) { Log.ignore(e); } }
@Override public ApiResponse generateRequestResponse(ApiRequest request) throws Exception { ApiResponse response = new ApiResponse(); // prevent spam UserEntry user = request.getUser(); long businessesCreated = user.getStats().getBusinessesCreated(); if (businessesCreated >= MAXIMUM_BUSINESS_CREATIONS) { Log.warn("Prevented business creation from user: "******"Spam prevention: You may not create any more businesses. Please contact us if you want to increase your quota.")); return response; } String name = request.getParameter("name"); String mail = request.getParameter("mail"); boolean addQueue = request.getParameterAsBoolean("addQueue", false); // create the business BusinessEntry businessEntry = new BusinessEntry(); businessEntry.setName(name); businessEntry.setMail(mail); Key businessKey = BusinessHelper.saveEntry(businessEntry); businessEntry.setKey(businessKey); // update user stats user.getStats().setBusinessesCreated(businessesCreated + 1); UserHelper.saveEntry(user); // add permission for business PermissionHelper.grantPermission(user, businessEntry, PermissionEntry.PERMISSION_OWN); if (addQueue) { // create a default queue QueueEntry queueEntry = new QueueEntry(businessKey.getId()); queueEntry.parseFromRequest(request); Key queueKey = QueueHelper.saveEntry(queueEntry); queueEntry.setKey(queueKey); // add permission for queue PermissionHelper.grantPermission( request.getUser(), queueEntry, PermissionEntry.PERMISSION_OWN); // add the new queue to the business in order to return both as one response ArrayList<QueueEntry> queues = new ArrayList<QueueEntry>(); queues.add(queueEntry); businessEntry.setQueues(queues); } response.setContent(businessEntry); return response; }
public String toString() { StringBuilder sb = new StringBuilder(); String showName = MediaFileAPI.GetMediaTitle(mediaFile); int numberOfMediaFileSegments = MediaFileAPI.GetNumberOfSegments(mediaFile); int segmentCount = (isFileCurrentlyRecording) ? segmentList.size() - 1 : segmentList.size(); Log.debug("Show: " + showName); Log.debug("MediaFileId: " + mediaFileId); Log.debug("Number Of MediaFile segments: " + numberOfMediaFileSegments); Log.debug("Is file currently recording: " + isFileCurrentlyRecording); Log.debug("Number of playlist segments: " + segmentCount); sb.append("#EXTM3U" + LINE_TERM); Log.debug("#EXTM3U"); sb.append("#EXT-X-TARGETDURATION:" + TARGET_DURATION + LINE_TERM); Log.debug("#EXT-X-TARGETDURATION:" + SegmentPlaylist.TARGET_DURATION); // sb.append("#EXT-X-MEDIA-SEQUENCE:1" + LINE_TERM); // Log.debug("#EXT-X-MEDIA-SEQUENCE:1"); for (int i = 0; i < segmentCount; i++) { Segment currentSegment = segmentList.get(i); Segment previousSegment = (i == 0) ? null : segmentList.get(i - 1); Segment nextSegment = (i == segmentCount - 1) ? null : segmentList.get(i + 1); String str = currentSegment.toString(); sb.append(str); // first or last playlist segment for each media file segment // printing the whole playlist makes the log harder to read if ((previousSegment == null) || (nextSegment == null) || (previousSegment.mediaFileSegment != currentSegment.mediaFileSegment) || (currentSegment.mediaFileSegment != nextSegment.mediaFileSegment)) { Log.debug(str); } } // #EXT-X-MEDIA-SEQUENCE:<number> // #EXT-X-PROGRAM-DATE-TIME:<YYYY-MM-DDThh:mm:ssZ> // #EXT-X-ALLOW-CACHE:<YES|NO> // #EXT-X-STREAM-INF if (!isFileCurrentlyRecording) { sb.append("#EXT-X-ENDLIST" + LINE_TERM); Log.debug("#EXT-X-ENDLIST"); } return sb.toString(); }
Handshake() { super("handshake"); setMessage(__HANDSHAKE); try { customize(this); _client.send(this); } catch (IOException e) { Log.warn(e); } }
/* ------------------------------------------------------------ */ protected boolean checkConnection() { super.checkConnection(); try { if (_jarConnection != _connection) newConnection(); } catch (IOException e) { Log.ignore(e); _jarConnection = null; } return _jarConnection != null; }
/* ------------------------------------------------------------ */ public void run() { Thread current = Thread.currentThread(); String name; synchronized (AbstractConnector.this) { if (_acceptorThread == null) return; _acceptorThread[_acceptor] = current; name = _acceptorThread[_acceptor].getName(); current.setName(name + " - Acceptor" + _acceptor + " " + AbstractConnector.this); } int old_priority = current.getPriority(); try { current.setPriority(old_priority - _acceptorPriorityOffset); while (isRunning() && getConnection() != null) { try { accept(_acceptor); } catch (EofException e) { Log.ignore(e); } catch (IOException e) { Log.ignore(e); } catch (ThreadDeath e) { throw e; } catch (Throwable e) { Log.warn(e); } } } finally { current.setPriority(old_priority); current.setName(name); try { if (_acceptor == 0) close(); } catch (IOException e) { Log.warn(e); } synchronized (AbstractConnector.this) { if (_acceptorThread != null) _acceptorThread[_acceptor] = null; } } }
@Override public void bind(InetSocketAddress addr, int backlog) throws IOException { if (_started) throw new BindException("Already started"); // check if there is already a connector listening Connector[] connectors = _server.getConnectors(); if (connectors != null) throw new BindException("Server already bound"); this._addr = addr; if (_executor != null && _server.getThreadPool() == null) { if (Log.isDebugEnabled()) Log.debug("using given Executor for server thread pool"); _server.setThreadPool(new ThreadPoolExecutorAdapter(_executor)); } SelectChannelConnector connector = new SelectChannelConnector(); connector.setAcceptors(1); connector.setAcceptQueueSize(backlog); connector.setPort(addr.getPort()); connector.setHost(addr.getHostName()); _server.addConnector(connector); }
public int getMaxInactiveInterval() { checkState(); try { return _state.getMaxInactiveInterval(); } catch (RemoteException e) { // Can I throw an exception of some type here - instead of // returning rubbish ? - TODO Log.warn("could not get MaxInactiveInterval", e); return 0; } }
Publish() { super("publish"); synchronized (_outQ) { if (_outQ.size() == 0) return; setMessages(_outQ); _outQ.clear(); } try { customize(this); _client.send(this); } catch (IOException e) { Log.warn(e); } }