当前位置: 首页>>代码示例>>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;未经允许,请勿转载。