Java 8 stream support in MongoTemplate - spring-data-mongodb

Why don't we have java 8 stream support in MongoTemplate in spring-data-mongodb-1.8.2.RELEASE.jar ?
I see that stream support have bean added in MongoRepository interface but I use pure MongoTemplate.

In short
There is stream support but without exposing Stream on MongoOperations.
Explanation
Spring Data Mongo has stream support by exposing CloseableIterator<T> stream(final Query query, final Class<T> entityType). It does not use the Stream type on MongoOperations because Spring Data Mongo supports Java back to 1.6. You can obtain the Stream object by using StreamUtils.createStreamFromIterator(Iterator<T>). StreamUtils takes care of closing the stream and releasing resources.
HTH, Mark

Mark's answer is correct (and should stay the accepted answer). Maybe a few more details on why you don't find a Stream on the MongoTemplate:
The core reason that there's no Stream on the MongoTemplate level is that Spring Data MongoDB is still compatible with Java 6. So we can't use Java 8 types in method signatures of classes we provide. With repositories, it's a different story as that's user code we inspect at runtime and — if Java 8 is present — dynamically adapt to, e.g. by converting the CloseableIterator<T> into a Stream.

Related

Programmatically getting Apache Camel components operations, parameters, options decriptions

Is there a way to get any Apache Camel component "metadata" using Java code, like the list of options and other parameters and their types? I think some automatic help builder was mentioned somewhere that might be of use for this task without using reflection.
A way to get the registered components of all types (including data formats and languages) with java code is also sought. Thanks
Yeah take a look at the camel-catalog JAR which includes all such details. This JAR is what the tooling uses such as some of the Maven tooling itself, or IDE plugs for IntelliJ or Eclipse etc. The JAR has both Java API and metadata files embedded in the JAR you can load.
At runtime you can also access this catalog via RuntimeCamelCatalog which you can access via CamelContext. The runtime catalog is a little bit more limited than CamelCatalog as it has a view of what actually is available at runtime in the current Camel application.
Also I cover this in my book Camel in Action 2nd edition where there is a full chapter devoted on Camel tooling and how to build custom tooling etc.
This is what I've found so far
http://camel.apache.org/componentconfiguration.html

Apache Camel Concept Data format vs Data type

I am using Apache Camel. While I have an idea about the following concepts, would like to get a clear understanding of the following concepts. Yes, I have gone through Apache Camel documentation.
Data Format conversion
Data Type conversion
Marshalling and Unmarshalling
What I am looking for is a clear conceptual differentiation. Thanks in advance.
These terms have a lot of different meaning in programming and computers in general. Additionally, across Camel components the terms Data Format and Data Type may be used interchangeably.
Data Format -- typically the format of "data on the wire". This is like Text, or binary for file handling and messaging scenarios (.txt, .csv, .bin, JMS, MQTT, STOMP, etc).. or JSON and XML for REST and SOAP web services (generally over http)
Data Type -- totally overloaded.. in Camel, (I'll risk being flamed for this..).. it generally has a meaning of what Java class is used as the input or output to a component. Camel also has a ton of auto-type conversion routines, so some of the subtle differences go unnoticed by users. For example, consuming from a JMS queue.. may generate a javax.jms.TextMessage, but the next step may use a java.lang.String class. Camel can auto-convert between those types.
Marshalling and Unmarshalling is the step in converting from Java Class -> Data Format and Data Format -> Java Class. For example, a JSON payload would be unmarshalled to a com.bobtire.Order Java class and used by a Java processor in Camel. Conversely, after doing some processing, one may need to marshall a com.bobtire.Order Java class to JSON to send to a REST endpoint. These functions are handled by "data format" modules within Camel. Common ones: JSON, JAXB (for XML), Bindy, PGP and JCE (for encryption)

java backend for qooxdoo with the date hack

is there a skeleton java backend (json rpc) for qooxdoo js framework?
Could any json RPC backend work for qooxdoo or we need the date hack to have it work?
Regards,
TL;DR: If you set the "protocol" property to "2.0", you should be able to interoperate with any standards-based JSON-RPC 2.0 server.
Detailed answer:
The qooxdoo JSON RPC client supports both its original protocol, a variation of JSON-RPC 1.0 called "qx1" (the default, for age-old backward compatibility), and the standardized JSON-RPC 2.0. You'll want to switch it to 2.0 by setting the "protocol" property to "2.0". If I recall correctly, our JSON-RPC client is then fully 2.0 standards-compliant except that we don't support batch requests.
Additionally, as you've noted, qooxdoo used to try to fix the "bug" in JSON/JavaScript, that there is no literal form for a Date object as there is for all other types in JavaScript. The qooxdoo JSON-RPC implementation has provisions for automatically converting Date objects into a string format that is easily parsed.
As of many years ago, we realized that it was poor form to muck with JSON-RPC since mucking with it allowed us to communicate only with qooxdoo-enhanced JSON-RPC servers. At that time, we changed the default to not do any date conversions. This is controlled by the static variable, qx.io.remote.Rpc.CONVERT_DATES, which can be set to true to "fix the bug" as we did originally, or left at its now default null (or false) value, which says "do not muck with dates."
That's all a long-winded answer to say that qooxdoo's JSON-RPC client, if you switch it to use the 2.0 protocol, should interoperate fine with any standards-based JSON-RPC 2.0 server.
Derrell

Extract data from JSON in vanilla Java/Camel/Spring

I am trying to write a Camel route to get JMX data from an ActiveMQ server through the Jolokia REST API. I was able to successfully get the JSON object from the ActiveMQ server, but I am running into an issue where I cannot figure out how to parse the JSON object in my Camel route. Camel is integrated with Jackson, Gson, and XStream, but each of those appear to require an extra library that I do not have. Camel also has support for JSONPath, but it requires another library that I do not have. All of my research so far seems to point to using a new software library, so I am looking for someone who knows a solution to possibly save me some time from trying several more dead ends.
The big catch is that I am trying to parse JSON with something that comes with Java/Camel/Spring/ActiveMQ/apache-commons. I would prefer a solution that only uses Camel/Spring XML, but another solution using Java would work (maybe JXPath with Apache Commons?).
The reason I am trying to use libraries that I currently have is the long process that our company has for getting new software libraries approved. I can wait several months to get a library approved or I can write my own specialized parser, but I am hoping there is some other way for me to extract some of the information from the JSON object that I am getting from the Jolokia JMX REST API in ActiveMQ.
There is no JSOn library out of the box in Java itself. But there is a RFE to maybe add that in a future Java release, maybe Java 9.
So if you want to parse json, you need to use a 3rd party library. So you better get your company to approve a library.
camel-core 2.15.x has a json scheme parser we use to parse the component docs json schemas that is shipped now. But its not a general purpose json parser, but can parse simple schemas.
Its at org.apache.camel.util.JsonSchemaHelper

What are my options for streaming for silverlight?

I would like to implement limited scope streaming (LAN, multicast, even broadcast) where the client is implemented in silverlight. More importantly, I would like to stream from a desktop OS, not a server OS. As a result, I can't use the MS media server, which I believe requires WS2003 or WS2008.
Ideally the solution would have some sort of API so I can plug in or provide a custom frame source.
If I need to encode my own video, how can I encode using H.264 or another Silverlight supported codec?
if I need to implement my own server, where can I find information about how a client starts to receive a stream?
thank you! I know, it's a lot of questions, but it basically boils down to "how do I stream from a non-server OS?"
My Friend Vikram wrote a blog post about Overview of Live Smooth Streaming,Live Encoding and Streaming with Expression Encoder 2 – Part 8. Check it out and see if it helps. I dont think he used a server for the article.

Resources