List of usage examples for java.util.concurrent LinkedBlockingDeque LinkedBlockingDeque
public LinkedBlockingDeque()
From source file:com.addthis.hydra.task.source.DataSourceStreamList.java
@Override public void postDecode() { sourceInitService = MoreExecutors.getExitingExecutorService(new ThreadPoolExecutor(sourceInitThreads, sourceInitThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<Runnable>(), new ThreadFactoryBuilder().setNameFormat("SourceInitThread-%d").build())); peekerService = MoreExecutors.getExitingExecutorService(new ThreadPoolExecutor(peekerThreads, peekerThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<Runnable>(), new ThreadFactoryBuilder().setNameFormat("TaskDataSourcePeeker-%d").build())); }
From source file:org.apache.streams.twitter.provider.TwitterStreamProvider.java
@Override public synchronized StreamsResultSet readCurrent() { StreamsResultSet current;//from ww w. j av a2s . c om synchronized (this) { Queue<StreamsDatum> drain = new LinkedBlockingDeque<>(); drainTo(drain); current = new StreamsResultSet(drain); current.setCounter(new DatumStatusCounter()); current.getCounter().add(countersCurrent); countersTotal.add(countersCurrent); countersCurrent = new DatumStatusCounter(); } return current; }
From source file:org.wso2.carbon.event.output.adapter.ui.UIEventAdapter.java
@Override public void init() throws OutputEventAdapterException { tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); //ExecutorService will be assigned if it is null if (executorService == null) { int minThread; int maxThread; long defaultKeepAliveTime; int jobQueSize; //If global properties are available those will be assigned else constant values will be assigned if (globalProperties.get(UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) { minThread = Integer/* w w w.j ava 2s . c o m*/ .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME)); } else { minThread = UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE; } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) { maxThread = Integer .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME)); } else { maxThread = UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE; } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) { defaultKeepAliveTime = Integer .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME)); } else { defaultKeepAliveTime = UIEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS; } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) { jobQueSize = Integer.parseInt( globalProperties.get(UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME)); } else { jobQueSize = UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE; } executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(jobQueSize)); } streamId = eventAdapterConfiguration.getOutputStreamIdOfWso2eventMessageFormat(); if (streamId == null || streamId.isEmpty()) { throw new OutputEventAdapterRuntimeException("UI event adapter needs a output stream id"); } ConcurrentHashMap<Integer, ConcurrentHashMap<String, String>> tenantSpecifcEventOutputAdapterMap = UIEventAdaptorServiceInternalValueHolder .getTenantSpecificOutputEventStreamAdapterMap(); ConcurrentHashMap<String, String> streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); if (streamSpecifAdapterMap == null) { streamSpecifAdapterMap = new ConcurrentHashMap<String, String>(); if (null != tenantSpecifcEventOutputAdapterMap.putIfAbsent(tenantId, streamSpecifAdapterMap)) { streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); } } String adapterName = streamSpecifAdapterMap.get(streamId); if (adapterName != null) { throw new OutputEventAdapterException(("An Output ui event adapter \"" + adapterName + "\" is already" + " exist for stream id \"" + streamId + "\"")); } else { streamSpecifAdapterMap.put(streamId, eventAdapterConfiguration.getName()); ConcurrentHashMap<Integer, ConcurrentHashMap<String, LinkedBlockingDeque<Object>>> tenantSpecificStreamMap = UIEventAdaptorServiceInternalValueHolder .getTenantSpecificStreamEventMap(); ConcurrentHashMap<String, LinkedBlockingDeque<Object>> streamSpecificEventsMap = tenantSpecificStreamMap .get(tenantId); if (streamSpecificEventsMap == null) { streamSpecificEventsMap = new ConcurrentHashMap<String, LinkedBlockingDeque<Object>>(); if (null != tenantSpecificStreamMap.putIfAbsent(tenantId, streamSpecificEventsMap)) { streamSpecificEventsMap = tenantSpecificStreamMap.get(tenantId); } } streamSpecificEvents = streamSpecificEventsMap.get(streamId); if (streamSpecificEvents == null) { streamSpecificEvents = new LinkedBlockingDeque<Object>(); if (null != streamSpecificEventsMap.putIfAbsent(streamId, streamSpecificEvents)) { streamSpecificEvents = streamSpecificEventsMap.get(streamId); } } } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME) != null) { try { queueSize = Integer .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME)); } catch (NumberFormatException e) { log.error("String does not have the appropriate format for conversion." + e.getMessage()); queueSize = UIEventAdapterConstants.EVENTS_QUEUE_SIZE; } } else { queueSize = UIEventAdapterConstants.EVENTS_QUEUE_SIZE; } }
From source file:org.opencommercesearch.feed.SearchFeed.java
@Override public void doStartService() throws ServiceException { super.doStartService(); endpointUrl = getProductService().getUrl4Endpoint(Endpoint.PRODUCTS); mapper = new ObjectMapper().setDateFormat(new ISO8601DateFormat()) .setSerializationInclusion(JsonInclude.Include.NON_NULL); if (getWorkerCount() <= 0) { if (isLoggingInfo()) { logInfo("At least one worker is required to process the feed, setting number of workers to 1"); setWorkerCount(1);/*from www. j a va 2s . co m*/ } } productTaskExecutor = Executors.newFixedThreadPool(getWorkerCount()); processedProductCount = new AtomicInteger(0); indexedProductCount = new AtomicInteger(0); failedProductCount = new AtomicInteger(0); sendTaskExecutor = Executors.newSingleThreadExecutor(); sendQueue = new LinkedBlockingDeque<SendQueueItem>(); }
From source file:org.wso2.carbon.device.mgt.iot.output.adapter.ui.UIEventAdapter.java
@Override public void init() throws OutputEventAdapterException { tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); //ExecutorService will be assigned if it is null if (executorService == null) { int minThread; int maxThread; long defaultKeepAliveTime; int jobQueSize; //If global properties are available those will be assigned else constant values will be assigned if (globalProperties.get(UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) { minThread = Integer/*from w w w .j ava 2s .co m*/ .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME)); } else { minThread = UIEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE; } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) { maxThread = Integer .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME)); } else { maxThread = UIEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE; } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) { defaultKeepAliveTime = Integer .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME)); } else { defaultKeepAliveTime = UIEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS; } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) { jobQueSize = Integer.parseInt( globalProperties.get(UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME)); } else { jobQueSize = UIEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE; } executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(jobQueSize)); } streamId = eventAdapterConfiguration.getOutputStreamIdOfWso2eventMessageFormat(); if (streamId == null || streamId.isEmpty()) { throw new OutputEventAdapterRuntimeException("UI event adapter needs a output stream id"); } // fetch the "streamDefinition" corresponding to the "streamId" and then fetch the different attribute types // of the streamDefinition corresponding to the event's streamId. They are required when validating values in // the events against the streamDef attributes. StreamDefinition streamDefinition = getStreamDefinition(streamId); streamMetaAttributes = streamDefinition.getMetaData(); streamCorrelationAttributes = streamDefinition.getCorrelationData(); streamPayloadAttributes = streamDefinition.getPayloadData(); ConcurrentHashMap<Integer, ConcurrentHashMap<String, String>> tenantSpecifcEventOutputAdapterMap = UIEventAdaptorServiceDataHolder .getTenantSpecificOutputEventStreamAdapterMap(); ConcurrentHashMap<String, String> streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); if (streamSpecifAdapterMap == null) { streamSpecifAdapterMap = new ConcurrentHashMap<>(); if (null != tenantSpecifcEventOutputAdapterMap.putIfAbsent(tenantId, streamSpecifAdapterMap)) { streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); } } String adapterName = streamSpecifAdapterMap.get(streamId); if (adapterName != null) { throw new OutputEventAdapterException(("An Output ui event adapter \"" + adapterName + "\" is already" + " exist for stream id \"" + streamId + "\"")); } else { streamSpecifAdapterMap.put(streamId, eventAdapterConfiguration.getName()); ConcurrentHashMap<Integer, ConcurrentHashMap<String, LinkedBlockingDeque<Object>>> tenantSpecificStreamMap = UIEventAdaptorServiceDataHolder .getTenantSpecificStreamEventMap(); ConcurrentHashMap<String, LinkedBlockingDeque<Object>> streamSpecificEventsMap = tenantSpecificStreamMap .get(tenantId); if (streamSpecificEventsMap == null) { streamSpecificEventsMap = new ConcurrentHashMap<>(); if (null != tenantSpecificStreamMap.putIfAbsent(tenantId, streamSpecificEventsMap)) { streamSpecificEventsMap = tenantSpecificStreamMap.get(tenantId); } } streamSpecificEvents = streamSpecificEventsMap.get(streamId); if (streamSpecificEvents == null) { streamSpecificEvents = new LinkedBlockingDeque<>(); if (null != streamSpecificEventsMap.putIfAbsent(streamId, streamSpecificEvents)) { streamSpecificEvents = streamSpecificEventsMap.get(streamId); } } } if (globalProperties.get(UIEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME) != null) { try { queueSize = Integer .parseInt(globalProperties.get(UIEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME)); } catch (NumberFormatException e) { log.error("String does not have the appropriate format for conversion." + e.getMessage()); queueSize = UIEventAdapterConstants.EVENTS_QUEUE_SIZE; } } else { queueSize = UIEventAdapterConstants.EVENTS_QUEUE_SIZE; } }
From source file:org.wso2.carbon.device.mgt.output.adapter.websocket.WebsocketEventAdapter.java
@Override public void init() throws OutputEventAdapterException { tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); //ExecutorService will be assigned if it is null if (executorService == null) { int minThread; int maxThread; long defaultKeepAliveTime; int jobQueSize; //If global properties are available those will be assigned else constant values will be assigned if (globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) { minThread = Integer.parseInt( globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME)); } else {/*from ww w. j a v a 2 s . c o m*/ minThread = WebsocketEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE; } if (globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) { maxThread = Integer.parseInt( globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME)); } else { maxThread = WebsocketEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE; } if (globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) { defaultKeepAliveTime = Integer.parseInt( globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME)); } else { defaultKeepAliveTime = WebsocketEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS; } if (globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) { jobQueSize = Integer.parseInt( globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME)); } else { jobQueSize = WebsocketEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE; } executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(jobQueSize)); } streamId = eventAdapterConfiguration.getOutputStreamIdOfWso2eventMessageFormat(); if (streamId == null || streamId.isEmpty()) { throw new OutputEventAdapterRuntimeException("UI event adapter needs a output stream id"); } // fetch the "streamDefinition" corresponding to the "streamId" and then fetch the different attribute types // of the streamDefinition corresponding to the event's streamId. They are required when validating values in // the events against the streamDef attributes. StreamDefinition streamDefinition = getStreamDefinition(streamId); streamMetaAttributes = streamDefinition.getMetaData(); streamCorrelationAttributes = streamDefinition.getCorrelationData(); streamPayloadAttributes = streamDefinition.getPayloadData(); ConcurrentHashMap<Integer, ConcurrentHashMap<String, String>> tenantSpecifcEventOutputAdapterMap = WebsocketEventAdaptorServiceDataHolder .getTenantSpecificOutputEventStreamAdapterMap(); ConcurrentHashMap<String, String> streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); if (streamSpecifAdapterMap == null) { streamSpecifAdapterMap = new ConcurrentHashMap<>(); if (null != tenantSpecifcEventOutputAdapterMap.putIfAbsent(tenantId, streamSpecifAdapterMap)) { streamSpecifAdapterMap = tenantSpecifcEventOutputAdapterMap.get(tenantId); } } String adapterName = streamSpecifAdapterMap.get(streamId); if (adapterName != null) { throw new OutputEventAdapterException(("An Output websocket event adapter \"" + adapterName + "\" is already" + " exist for stream id \"" + streamId + "\"")); } else { streamSpecifAdapterMap.put(streamId, eventAdapterConfiguration.getName()); ConcurrentHashMap<Integer, ConcurrentHashMap<String, LinkedBlockingDeque<Object>>> tenantSpecificStreamMap = WebsocketEventAdaptorServiceDataHolder .getTenantSpecificStreamEventMap(); ConcurrentHashMap<String, LinkedBlockingDeque<Object>> streamSpecificEventsMap = tenantSpecificStreamMap .get(tenantId); if (streamSpecificEventsMap == null) { streamSpecificEventsMap = new ConcurrentHashMap<>(); if (null != tenantSpecificStreamMap.putIfAbsent(tenantId, streamSpecificEventsMap)) { streamSpecificEventsMap = tenantSpecificStreamMap.get(tenantId); } } streamSpecificEvents = streamSpecificEventsMap.get(streamId); if (streamSpecificEvents == null) { streamSpecificEvents = new LinkedBlockingDeque<>(); if (null != streamSpecificEventsMap.putIfAbsent(streamId, streamSpecificEvents)) { streamSpecificEvents = streamSpecificEventsMap.get(streamId); } } } if (globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME) != null) { try { queueSize = Integer.parseInt( globalProperties.get(WebsocketEventAdapterConstants.ADAPTER_EVENT_QUEUE_SIZE_NAME)); } catch (NumberFormatException e) { log.error("String does not have the appropriate format for conversion." + e.getMessage()); queueSize = WebsocketEventAdapterConstants.EVENTS_QUEUE_SIZE; } } else { queueSize = WebsocketEventAdapterConstants.EVENTS_QUEUE_SIZE; } }
From source file:com.portfolioeffect.quant.client.ClientConnection.java
/** * Establishes connection to the server. Should be followed by the a call to * logon(), otherwise client will be disconneted shortly. * /*from w w w.ja v a 2 s . c o m*/ * @throws IOException * @throws FastConnectionException */ public void start() throws IOException, FastConnectionException { logger.setLevel(Level.ERROR); // load connection properties from persistent storage endpoint = new TcpEndpoint(host, port); //create XML message loader template and populate its parameters XMLMessageTemplateLoader loader = new XMLMessageTemplateLoader(); loader.setLoadTemplateIdFromAuxId(true); loader.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(templatesFileName)); // get template registry from message loader and create opefast context templateRegistry = loader.getTemplateRegistry(); Context context = new Context(); context.setTemplateRegistry(templateRegistry); // create message block reader & writer messageBlockWriterFactory = new MessageBlockWriterFactory(Variant.DEFAULT, 0, false); messageBlockReaderFactory = new MessageBlockReaderFactory(Variant.DEFAULT, 0, false); // create connection connection = endpoint.connect(); // create input stream in = new MessageInputStream(connection.getInputStream(), context); in.setBlockReader(messageBlockReaderFactory.create()); // create output stream out = new MessageOutputStream(connection.getOutputStream(), context); out.setBlockWriter(messageBlockWriterFactory.create()); isConnected = true; logger.info("Client connected to endpoint " + endpoint); clientMessageQueue = new LinkedBlockingDeque<ClientMessage>(); serviceMessageQueue = new LinkedBlockingDeque<ServiceMessage>(); inboundMessageRouter = new Thread(new InboundMessageWorker()); inboundMessageRouter.start(); heartbeatMonitor = new Thread(new HeartbeatMonitor()); heartbeatMonitor.start(); }
From source file:poke.client.ClientConnection.java
private void init() { // the queue to support client-side surging outbound = new LinkedBlockingDeque<com.google.protobuf.GeneratedMessage>(); // Configure the client. bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); bootstrap.setOption("connectTimeoutMillis", 10000); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); // Set up the pipeline factory. clientPipeline = new ClientDecoderPipeline(); bootstrap.setPipelineFactory(clientPipeline); channel = connect();//from ww w . ja v a 2 s. com // start outbound message processor worker = new OutboundWorker(this); worker.start(); }
From source file:co.beem.project.beem.FacebookTextService.java
/** * {@inheritDoc}/*ww w. ja va 2 s . c om*/ */ @Override public void onCreate() { super.onCreate(); smackAndroid = SmackAndroid.init(FacebookTextService.this); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); savingMessageQueue = new LinkedBlockingQueue<co.beem.project.beem.service.Message>(); loadingUserAvatarQueue = new LinkedBlockingDeque<String>(); stateChangeQueue = new LinkedBlockingQueue<User>(); databaseHelper = getHelper(); try { setupDatabaseConnection(); } catch (Exception e) { e.printStackTrace(); } isRunning = true; sessionManager = new SessionManager(FacebookTextService.this); savingMessageOnBackgroundThread(new SavingNewMessageTask()); savingMessageOnBackgroundThread(new UpdateUserStateTask()); handler = new Handler(); registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); registerReceiver(mOnOffReceiver, new IntentFilter(FacebookTextApplication.GET_AVATAR)); registerReceiver(mOnOffReceiver, new IntentFilter(FacebookTextApplication.UPDATE_USER_STATE)); registerReceiver(mOnOffReceiver, new IntentFilter(FacebookTextApplication.PUSH_NOTIFICATION_FAVORITE_ONLINE)); mSettings = PreferenceManager.getDefaultSharedPreferences(this); mSettings.registerOnSharedPreferenceChangeListener(mPreferenceListener); if (mSettings.getBoolean(FacebookTextApplication.USE_AUTO_AWAY_KEY, false)) { mOnOffReceiverIsRegistered = true; registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); // registerReceiver(sma, filter) } String tmpJid = mSettings.getString(FacebookTextApplication.ACCOUNT_USERNAME_KEY, "").trim(); mLogin = StringUtils.parseName(tmpJid); boolean useSystemAccount = mSettings.getBoolean(FacebookTextApplication.USE_SYSTEM_ACCOUNT_KEY, false); mPort = DEFAULT_XMPP_PORT; mService = StringUtils.parseServer(tmpJid); mHost = mService; initMemorizingTrustManager(); if (mSettings.getBoolean(FacebookTextApplication.ACCOUNT_SPECIFIC_SERVER_KEY, false)) { mHost = mSettings.getString(FacebookTextApplication.ACCOUNT_SPECIFIC_SERVER_HOST_KEY, "").trim(); if ("".equals(mHost)) mHost = mService; String tmpPort = mSettings.getString(FacebookTextApplication.ACCOUNT_SPECIFIC_SERVER_PORT_KEY, "5222"); if (!"".equals(tmpPort)) mPort = Integer.parseInt(tmpPort); } if (mSettings.getBoolean(FacebookTextApplication.FULL_JID_LOGIN_KEY, false) || "gmail.com".equals(mService) || "googlemail.com".equals(mService) || useSystemAccount) { mLogin = tmpJid; } configure(ProviderManager.getInstance()); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Roster.setDefaultSubscriptionMode(SubscriptionMode.manual); mBind = new XmppFacade(this); savingMessageOnBackgroundThread(new DownloadAvatarTask()); Log.d(TAG, "Create FacebookTextService \t id: " + mLogin + " \t host: " + mHost + "\tmPort" + mPort + "\t service" + mService); }
From source file:com.edgenius.wiki.webapp.action.SpaceAction.java
/** * Redeploy shell - request spaceUname as input parameter * @return/* ww w . j a v a2s . c o m*/ */ public String shellDeploy() { securityDummy.checkSpaceAdmin(spaceUname); Space space = spaceService.getSpaceByUname(spaceUname); if (space.isPrivate() || space.containExtLinkType(Space.EXT_LINK_SHELL_DISABLED) || StringUtils.equalsIgnoreCase(SharedConstants.SYSTEM_SPACEUNAME, space.getUnixName())) { getRequest().setAttribute("error", "Deploy failed: Space is private or shell service is disabled."); return RET_SHELL; } User anonymous = userReadingService.getUserByName(null); final LinkedBlockingDeque<String[]> pageQ = new LinkedBlockingDeque<String[]>(); //This will make GW request Shell.key again - so if Shell site cleans the data, re-deploy still can work out. //If shell data is still there, it will return same key as GW instanceID and address won't changed. Shell.key = null; new Thread(new Runnable() { public void run() { int pageCount = 0; //in shell side, page request also verify if space exists or not, if not, it will do space request //however, if space already exist, it won't refresh space - if space has menu, it won't refresh again. //so, we also refresh space Shell.notifySpaceCreate(spaceUname); do { try { String[] str = pageQ.take(); if (StringUtils.equalsIgnoreCase(SharedConstants.SYSTEM_SPACEUNAME, str[0])) break; Shell.notifyPageCreate(str[0], str[1], true); pageCount++; //don't explode the too many concurrent request to Shell! Thread.sleep(1000); if ((pageCount % QUOTA_RESET_COUNT) == 0) { log.warn( "Maximumn page shell request count arrived {}, sleep another 24 hours on space {}.", QUOTA_RESET_COUNT, spaceUname); //google app engine has quota limitation. Here will sleep 24 hours to wait next quota reset. Thread.sleep(24 * 3600 * 1000); log.warn( "Maximumn page shell request sleep is end, restart page request process on space{}.", spaceUname); } } catch (InterruptedException e) { log.error("Thread interrupted for shell request", e); } } while (true); log.info("Shell page request is done for {} pages on space {}.", pageCount, spaceUname); } }).start(); int pageCount = 0; long start = System.currentTimeMillis(); log.info("Shell on space {} redeploy request starting...", spaceUname); List<String> pages = pageService.getPagesUuidInSpace(spaceUname, anonymous); if (pages != null) { for (String puuid : pages) { try { pageQ.put(new String[] { spaceUname, puuid }); pageCount++; } catch (InterruptedException e) { log.error("Thread interrupted for shell Page Queue on space " + spaceUname, e); } } } log.info("All shell on space {} request put into queue. Pages{}; Takes {}s", new Object[] { spaceUname, pageCount, (System.currentTimeMillis() - start) / 1000 }); try { pageQ.put(new String[] { SharedConstants.SYSTEM_SPACEUNAME, "" }); } catch (InterruptedException e) { log.error("Thread interrupted for shell Page Queue - end sign", e); } getRequest().setAttribute("message", "Shell is redeploying, this may take a couple of minutes to complete."); return shell(); }