[b][url=/bee-config]Bee Config[/url][/b], the simple Scala API for loading configuration files, has needed very few changes over the last few months and is now in preparation for full release. It is feature-complete and mostly ready for production use. It now has a Maven/Ivy repository for automatic dependency. If no significant changes are needed during December, the first release candidate will be announced in a few weeks.
Version 0.26.6 of Bee Client is now available. This brings a bugfix to date handling: issue 24 two-digit year Also, work to provide client-side caching, following HTTP practice, is nearly ready and a new version including it is to be expected soon. History of commits
Version 1.4.2 of Bee Config is now available. This is a bugfix release. ConfigSource now has a canBeOpened method. SourceChangeDetector has been simplified by using the canBeOpened logic. ConfigSource has been modified to ensure that the counter is always updated. History of commits
Version 1.5.0 of Bee Config is now available. This brings full Java support, whilst carrying forward the excellent Scala api. In previous versions, file i/o, parsing and config manipulation were all written in Scala, which was less easy to use from Java programs. Now, a new ConfigJ class in Java emulates the Config class in Scala. The Java parser is shared by both. The file i/o and parsing have been back-ported to Java, although this will not be evident in existing Scala programs (unless they happen to use the underlying utility classes explicitly).
Version 1.5.3 of Bee Config is now available. This brings JavaBean integration, a new feature for those who would like easy configuration files combined with pojos with typed properties. The new feature allows you to load your Config from a file (or wherever) as normal, then use it to populate JavaBeans, which may themselves contain further JavaBeans. You can create your own JavaBean and pass it in. Or you can specify the class of the bean and it will be created reflectively for you.
Version 1.5.4 of Bee Config is now available. This brings support for Scala 2.11 as well as 2.10 and 2.9.x. Previous announcement: v1.5.3 History of commits
Version 1.5.5 of Bee Config is now available. This includes a small bugfix in the DimensionedValue class, which now treats kilograms (kg) as a special case. Previous announcement: v1.5.4 History of commits
The CPA2014 conference held in Oxford over the last few days brought together an interesting group of around three dozen experts in the field of communicating process architectures. Discussions were on concurrency and parallelism topics, both theoretical and practical, in areas related to communicating process architectures (CPA). Also known as process-oriented programming, CPA is about both concurrency (the natural expression of things that are happening alongside each other) and parallelism (the physical execution of many parts of a program at the same time) by means of process algebra formalisms and CSP in particular.
I was very fortunate to join the London Scala Exchange conference over the last two days. A good range of quality talks were offered - some thought provoking, some highly entertaining. And most wrestled to some extent with concurrency. It seems that Scala is not yet at ease with itself in its concurrency model. The root of the issue is the JVM: threads are very expensive and limited to small numbers (say, 30).
Dispatch is a library for asynchronous HTTP interaction. It provides a Scala vocabulary for Java’s async-http-client. It is apparently popular and crops up as a transitive dependency of several other popular Scala products. So it can’t be all bad. However, a recent project of ours had an unhappy experience with it. Disclaimer I’ll say at the outset that there is an alternative HTTP client of my own. So I’m biased.
The new Bee Config API provides an alternative to using java.util.Properties in Scala programs. The API provides a very simple Scala API for loading configuration files. Simplicity is the key! Often, java.util.Properties is still used in Scala applications, but it is often unsatisfactory. This API is broadly similar in intent, but pimped to work well in Scala. Features Config files are like properties files, except they are always Unicode.
Can decision-makers realistically steer their development projects from Java to Scala yet, or is it too early? Clearly, such a transition is not without risk. Have the benefits now stacked up to outweigh the risks? An excellent blog post by Jim McBeath discusses the pros and cons in an objective way. This is well worth reading. Paulo Vilella of Accenture added his views: “For small to medium projects, I believe Scala is right now a great alternative to Java for higher productivity and agility, without compromising on performance and compatibility.
A significant part of the lines of code in any enterprise Java application are devoted to plain old java objects (pojos) that carry data. Although they are simple, they represent a non-trivial effort in development and testing. And they make an application resistant to change because often a small change requires alteration of code in several places. Pojos written in Scala are so simple that the value of mixing Scala into Java development becomes worth the extra startup effort.
Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages. It is also fully interoperable with Java. Code sizes are typically reduced by a factor of two to three when compared to an equivalent Java application. Scala - The New Kid on the Block Actually not so very new, Scala was initially developed during 2001 - 2003.
© Copyright 2012 Rick Beton Published under The MIT License. The MIT License Copyright (c) 2012 Rick Beton <firstname.lastname@example.org> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Thu, 20 Jun 2013 v1.4.0 Reloader enhanced to offer more robust multithreading support new SourceChangeDetector class hived off Reloader (it could be used for any file-based cache) Thu, 20 Jun 2013 v1.3.1 - New MutableConfig refactors out the parts of the JMX bean needed for mutability from the parts needed for JMX integration. Thu, 20 Jun 2013 v1.3.0 - added support for JMX (experimental): A Config instance can be inserted into a JMX MBean with operations that allow values to be queried and altered.
Config is loaded once only, when it is constructed. You can use Reloader to load changes on the fly if you want to. Reloader is constructed using a File or other source, and a max age in seconds import uk.co.bigbeeconsultants.bconfig.Reloader val reloader = Reloader(new File("src/test/resources/sample2.txt"), 10) Reloader wraps Config loading so that changes to the source can be reloaded dynamically. If the config file is edited whilst the application is running, the new values are loaded in.
A Config subsection is itself a Config instance - it’s easy to group your keys therefore. Here’s a sample file we’ll be discussing: xx.a.z1 = alpha-xx xx.a.z2 = beta-xx xx.b.z3 = gamma-xx xx.b.z4 = delta-xx [yy] a.z1 = alpha-yy a.z2 = beta-yy [zz] a.z1 = alpha-zz a.z2 = beta-zz There are two ways to deal with sections and hierarchies of settings. Prefixes The crudest is simply by choosing a common prefix on all the keys in the group.
Config extends ListMap, making it very easy to use. It assumed that you are familiar with Scala’s Map (and ListMap) collection classes. For clarity, the following examples have the explicit type declared on each val, which is not usually necessary in Scala. Here’s a sample file we’ll be discussing: a = something b = else easy = true tau = 6.2832 somewhen = 1979-05-27T07:32:00Z coronation = 1953-06-02 triangle = 3, 4, 5 actors = "\"Harry\", Daniel Radcliffe", "\"Ron\", Rupert Grint", "\"Hermione\", Emma Watson" timeout = 60s maxHeap = 2 GiB maxTemp = 90°C Simple Cases ∘ Load a string value directly.
Scala API Simply construct Config instances using the factory method. import uk.co.bigbeeconsultants.bconfig.Config val config = Config(new File("src/test/resources/sample1.txt")) You can create a new Config instance from a File or anything that provides an InputStream. Or use the Config.fromClasspath method to read a resource from the classpath. When constructing a Config, you can include another Config as a fallback source of default values; this too can have a fallback so a chain of any length of them is possible.
1. The Config File Writing your config file is easy. It’s like a java.util.Properties file except it must be Unicode (ISO-10646) encoding, not ISO-8859 or some such. Nowadays there are plenty of tools to transcode text files, notably uconv on Linux/Unix computers, various IDEs, native2ascii in the JDK tool suite may be useful in some cases. The config file may optionally start with a Unicode byte-order-mark (BOM) and this is required for automatic switching between UTF-8, UTF-16 and UTF-32.
Bintray Scala 2.11 Scala 2.10 Option 1: Maven / Ivy dependency Please use the Set Me Up link you’ll find on one of the ‘Download’ pages, above. Option 2: manual download Browse one of the ‘Download’ pages, above. Choose a version and navigate to the Files tab to find the jars. Download the jars and put them on your classpath. You need bee-config_1.X.X.jar and you may find the javadoc and source jars useful during development, too.
Bee Config provides a very simple Java and Scala API for loading configuration files. Config files become Maps Simplicity is the key! Still often used in Scala applications, java.util.Properties is rarely satisfactory. Bee Config is broadly similar in intent, but pimped to work well in Scala. Why is Bee Config different: well, Properties files are sooo 20th Century. We need something similar, something as simple but something refreshed. We need to move on from ASCII to Unicode.