當前位置: 首頁>>代碼示例>>Java>>正文


Java Duration.standardHours方法代碼示例

本文整理匯總了Java中org.joda.time.Duration.standardHours方法的典型用法代碼示例。如果您正苦於以下問題:Java Duration.standardHours方法的具體用法?Java Duration.standardHours怎麽用?Java Duration.standardHours使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.Duration的用法示例。


在下文中一共展示了Duration.standardHours方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.joda.time.Duration; //導入方法依賴的package包/類
public static void main(String args[]) throws InterruptedException, ExecutionException, IncompleteOfferingQueryException, IOException, AccessToNonSubscribedOfferingException, AccessToNonActivatedOfferingException {
		
		// Initialize consumer with Consumer ID and Marketplace URL
		Consumer consumer = new Consumer(CONSUMER_ID, MARKETPLACE_URI);
		
//		consumer.setProxy("127.0.0.1", 3128); //Enable this line if you are behind a proxy
//		consumer.addProxyBypass("172.17.17.100"); //Enable this line and the addresses for internal hosts
		
		// Authenticate consumer on the marketplace
		consumer.authenticate(CONSUMER_SECRET);
				
	    // Construct Offering Query incrementally
		OfferingQuery query = OfferingQuery.create("RandomNumberQuery")
				.withInformation(new Information("Random Number Query", "bigiot:RandomNumber"))
	    		//.addOutputData("value", new RDFType("schema:random"), ValueType.NUMBER)
				//.inRegion(RegionFilter.city(""))
				.withPricingModel(PricingModel.PER_ACCESS)
				.withMaxPrice(Euros.amount(0.002))             
				.withLicenseType(LicenseType.OPEN_DATA_LICENSE);

		// Discover available offerings based on Offering Query
		CompletableFuture<List<SubscribableOfferingDescription>> listFuture = consumer.discover(query);
		listFuture.thenApply(SubscribableOfferingDescription::showOfferingDescriptions);			
		List<SubscribableOfferingDescription> list = listFuture.get();	
		
		// Select Offering that has been offered by a local provider instance 
		SubscribableOfferingDescription selectedOfferingDescription = list.get(0); 
		
		if (selectedOfferingDescription != null) { 
			
			// Subscribe to a selected OfferingDescription (if successful, returns accessible Offering instance)		
			CompletableFuture<Offering> offeringFuture = selectedOfferingDescription.subscribe();
			Offering offering = offeringFuture.get();
	
			// Prepare Access Parameters
			AccessParameters accessParameters = AccessParameters.create();
			
			// EXAMPLE 1: ONE-TIME ACCESS to the Offering
			AccessResponse response = offering.accessOneTime(accessParameters).get();
            System.out.println("Received data: " + response.asJsonNode().toString());
            
            // EXAMPLE 2: CONTINUOUS ACCESS to the Offering 
			// Create an Access Feed with callbacks for the received results		
			Duration feedDuration = Duration.standardHours(2);
			Duration feedInterval = Duration.standardSeconds(2);
			AccessFeed accessFeed = offering.accessContinuous(accessParameters, 
										feedDuration.getMillis(), 
										feedInterval.getMillis(), 
										(f,r) -> {
											System.out.println("Received data: " + r.asJsonNode().toString());
										},
										(f,r) -> {
											System.out.println("Feed operation failed");
											f.stop();
										});
			
			// Run until user presses the ENTER key
			System.out.println(">>>>>>  Terminate ExampleConsumer by pressing ENTER  <<<<<<");
			Scanner keyboard = new Scanner(System.in);
			keyboard.nextLine();
	
			// Stop Access Feed
			accessFeed.stop();
			
			// Unsubscribe the Offering
			offering.unsubscribe();
	
		}
		else {
			// No active Offerings could be discovered 
			System.out.println(">>>>>>  No matching offering found  <<<<<<");
		}
		
		// Terminate consumer instance
		consumer.terminate();
			
	}
 
開發者ID:BIG-IoT,項目名稱:example-projects,代碼行數:78,代碼來源:ExampleConsumer.java


注:本文中的org.joda.time.Duration.standardHours方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。