I am looking for something very close to an application server with these features:
it should handle a series of threads/daemons, allowing the user to start-stop-reload each one without affecting the others
it should keep libraries separated between different threads/daemons
it should allow to share some libraries
Currently we have some legacy code reinventing the wheel... and not a perflectly round-shaped one at that!
I thought to use Tomcat, but I don't need a web server, except maybe for the simple backoffice user interface (/manager/html).
Any suggestion? Is there a non-web application server, or is there a better alternative to Tomcat (more lightweight, for example, or easier to configure)? Thanks in advance.
I'm currently working on an application that has to render several Freemarker templates. So far I have a Generator class that handles the rendering. The class looks more or less like this:
public class Generator {
public static void generate(…) {
renderTemplate1();
renderTemplate2();
renderTemplate3();
}
private static void render(…) {
// renders the template
}
private static void renderTemplate1() {
// Create config object for the rendering
// and calls render();
};
private static void renderTemplate1() {
// Create config object for the rendering
// and calls render();
};
…
}
This works, but it doesn't really feel right. What I would like to do is create a class that holds all the renderTemplate...() methods and then call them dynamically from my Generator class. This would make it cleaner and easier to extend. I was thinking about using something like reflection, but it doesn't really feel like a good solution either.
Any idea on how to implement this properly ?
Assign the following 25 scores to a one dimensional int array called "temp"
34,24,78,65,45,100,90,97,56,89,78,98,74,90,98,24,45,76,89,54,12,20,22,55,66
Move the scores to a 2 dimensional int array called "scores" row wise
-- meaning the first 5 scores go into row 0 etc
I have an Enum for Days of week (with Everyday, weekend and weekdays) as follows where each entry has an int value.
public enum DaysOfWeek {
Everyday(127),
Weekend(65),
Weekdays(62),
Monday(2),
Tuesday(4),
Wednesday(8),
Thursday(16),
Friday(32),
Saturday(64),
Sunday(1);
private int bitValue;
private DaysOfWeek(int n){
this.bitValue = n;
}
public int getBitValue(){
return this.bitValue;
}
}
Given a TOTAL of any combination of the entries, what would be the simplest way to calculate all individual values and make an arraylist from it. For example given the number 56 (i.e. Wed+Thur+Fri), how to calculate the list of individual values.
Hi,
Could anyone please tell me the reason of getting an output as: ab for the following RegExp code using Relcutant quantifier?
Pattern p = Pattern.compile("abc*?");
Matcher m = p.matcher("abcfoo");
while(m.find())
System.out.println(m.group()); // ab
and getting empty indices for the following code?
Pattern p = Pattern.compile(".*?");
Matcher m = p.matcher("abcfoo");
while(m.find())
System.out.println(m.group());
For a project, I have to convert a binary string into (an array of) bytes and write it out to a file in binary.
Say that I have a sentence converted into a code string using a huffman encoding. For example, if the sentence was: "hello" h = 00 e = 01, l = 10, o = 11
Then the string representation would be 0001101011.
How would I convert that into a byte? <-- If that question doesn't make sense it's because I know little about bits/byte bitwise shifting and all that has to do with manipulating 1's and 0's.
Using series.add(180, 1); produces a perfectly valid chart like this (little red dot at the bottom with some PolarItemRenderer Mods!)
but using series.add(3000/(6000/360), 1); produces this beast:
I assume it's because somewhere, 6000/360 = 16.6... is getting rounded? How can I stop this happening? Thanks :)
Consider this line:
if (object.getAttribute("someAttr").equals("true")) { // ....
Obviously this line is a potential bug, the attribute might be null and we will get a NullPointerException. So we need to refactor it to one of two choices:
First option:
if ("true".equals(object.getAttribute("someAttr"))) { // ....
Second option:
String attr = object.getAttribute("someAttr");
if (attr != null) {
if (attr.equals("true")) { // ....
The first option is awkward to read but more concise, while the second one is clear in intent, but verbose.
Which option do you prefer in terms of readability?
Hi all I have the following issue. I have a table of reserves in my MySQL DB, the date columns is defined DATETIME. I need to make a query using hibernate to find all reserves in one day no matter the hour, just that its the same year month and date, and I'm doing this
public List<Reserve> bringAllResByDate(Date date){
em = emf.createEntityManager();
Query q = em.createQuery("SELECT r FROM Reserve r WHERE r.date=:date ");
q.setParameter("date", date);
...
I really dont know how to make it compare, and bring me just those from the specified date, any help??
In the course of my work i need to develop an authorization engine ( i'm already authenticated and i check access of a user to an action ) in order to store all the authorization logic inside a same place and be able to reuse it and i have created the mini library.
http://github.com/eltados/canny (updated)
what do you think about it? What are the limits of my approch ?
Do you understand the benefit or it?
Is there any lightweight Authorization engine library i could have a look at?
I had a look at spring security and it does not really answer my requirement. The main idea is that i want to be able to reuse the same code to controll access in the controllers and the views.
So I am using DocumentBuilderFactory and DocumentBuilder to parse an xml.
So it is DOM parser.
But what I am trying to do is extract byte-array data (its an image encoded in base64)
Store it in one object and later in code write it out to another xml encoded in base64.
What is the best way to store this in btw.
Store it as string? or as ByteArray?
How can I extract byte array data in best way and write it out.
I am not experienced with this so wanted to get opinion from the group.
UPDATE: I am given XML I do not have control of incoming XML that comes in binary64 encoded
< byte-array >
... base64 encoded image ...
< /byte-array >
Using parser I have I need to store this node and question is should that be byte or string
and then writing it out to another node in new xml. again in base64 encoding.
thanks
Hi folks:
some methods in our model pojos have been annotated like this:
@Column(name="cli_clipping_id", updatable=false, columnDefinition = "varchar(" + ModelUtils.ID_LENGTH + ") COLLATE utf8_bin")
columnDefinition attribute is database vendor dependant, so when trying to drop schema in HSQLDB using Hibernate it fails:
[ERROR] 16 jun 12:58:42.480 PM main [org.hibernate.tool.hbm2ddl.SchemaExport]
Unexpected token: COLLATE in statement [create table cms.edi_editorial_obj (edi_uuid varchar(23) COLLATE
]
To fix this, i'm thinking on this solution (but don't want to spend time if it isn't possible) , at runtime, for each method column annotated:
Get @Column annotation
Create a copy of the column annotation, setting columnDefinition null using javaassist.
set column method annotation to the copy column annotation object overriding the old one (i don't know it this is possible)
Is it possible to "hack" these methods this way?
Any help would be much appreciated ...
when coding. try to solve the puzzle:
how to design the class/methods when InputStreamDigestComputor throw IOException?
It seems we can't use this degisn structure due to the template method throw exception but overrided method not throw it. but if change the overrided method to throw it, will cause other subclass both throw it.
So can any good suggestion for this case?
abstract class DigestComputor{
String compute(DigestAlgorithm algorithm){
MessageDigest instance;
try {
instance = MessageDigest.getInstance(algorithm.toString());
updateMessageDigest(instance);
return hex(instance.digest());
} catch (NoSuchAlgorithmException e) {
LOG.error(e.getMessage(), e);
throw new UnsupportedOperationException(e.getMessage(), e);
}
}
abstract void updateMessageDigest(MessageDigest instance);
}
class ByteBufferDigestComputor extends DigestComputor{
private final ByteBuffer byteBuffer;
public ByteBufferDigestComputor(ByteBuffer byteBuffer) {
super();
this.byteBuffer = byteBuffer;
}
@Override
void updateMessageDigest(MessageDigest instance) {
instance.update(byteBuffer);
}
}
class InputStreamDigestComputor extends DigestComputor{
// this place has error. due to exception. if I change the overrided method to throw it. evey caller will handle the exception. but
@Override
void updateMessageDigest(MessageDigest instance) {
throw new IOException();
}
}
I need help figuring out how to get the user to input a number of integers no more than 10, and then add them to an array and print them out from the array. The code I have below, when run, asks the user for the integers and then runs forever and doesn't work. What am I doing wrong?
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // create a new scanner
System.out.print("Enter integers between 1 and 100\n ");
int[] nextNumber = new int[10];
int i = 0;
int number = input.nextInt();
while (i < nextNumber.length){
i++;
nextNumber[i] = number;
number = input.nextInt();
}
int a = 0;
while (a < nextNumber.length){
a++;
System.out.println(nextNumber[a]);
}
I came across the following program and it behaving in unexpected manner.
public class ShiftProgram
{
public static void main(String[] args)
{
int i = 0;
while(-1 << i != 0)
i++;
System.out.println(i);
}
}
If we think about this program output, when it reaches 32 while loop condition should return false and terminate and it should print 32.
If you ran this program, it does not print anything but goes into an infinite loop. Any idea whats going on? Thank you in advance.
Hi
I'm not too sure how to go about getting the external IP address of the machine as a computer outside of a network would see it. My following IPAddress class only gets the local IP address of the machine.
Any help would be appreciated.
Thanks.
public class IPAddress {
private InetAddress thisIp;
private String thisIpAddress;
private void setIpAdd(){
try{
InetAddress thisIp = InetAddress.getLocalHost();
thisIpAddress = thisIp.getHostAddress().toString();
}
catch(Exception e){}
}
protected String getIpAddress(){
setIpAdd();
return thisIpAddress;
}
}
Hello Internet !
I'm having trouble with doubling up on my code for no reason other than my own lack of ability to do it more efficiently...
`for (Method curr: all){
if (curr.isAnnotationPresent(anno)){
if (anno == Pre.class){
for (String str : curr.getAnnotation(Pre.class).value()){
if (str.equals(method.getName()) && curr.getReturnType() == boolean.class && curr.getParameterTypes().length == 0){
toRun.add(curr);
}
}
} if (anno == Post.class) {
for (String str : curr.getAnnotation(Post.class).value()){
if (str.equals(method.getName()) && curr.getReturnType() == boolean.class && curr.getParameterTypes().length == 0){
toRun.add(curr);
}
}
}
}
}`
anno is a parameter - Class, and Pre and Post are my annotations, both have a value() which is an array of strings.
Of course, this is all due to the fact that i let Eclipse auto fill code that i don't understand yet.
I have a class Foo which overrides equals() and hashCode() properly.
I would like to also would like to use a HashSet<Foo> to keep track of "canonical values" e.g. I have a class that I would like to write like this, so that if I have two separate objects that are equivalent I can coalesce them into references to the same object:
class Canonicalizer<T>
{
final private Set<T> values = new HashSet<T>();
public T findCanonicalValue(T value)
{
T canonical = this.values.get(value);
if (canonical == null)
{
// not in the set, so put it there for the future
this.values.add(value);
return value;
}
else
{
return canonical;
}
}
}
except that Set doesn't have a "get" method that would return the actual value stored in the set, just the "contains" method that returns true or false. (I guess that it assumes that if you have an object that is equal to a separate object in the set, you don't need to retrieve the one in the set)
Is there a convenient way to do this? The only other thing I can think of is to use a map and a list:
class Canonicalizer<T>
{
// warning: neglects concurrency issues
final private Map<T, Integer> valueIndex = new HashMap<T, Integer>();
final private List<T> values = new ArrayList<T>();
public T findCanonicalValue(T value)
{
Integer i = this.valueIndex.get(value);
if (i == null)
{
// not in the set, so put it there for the future
i = this.values.size();
this.values.add(value);
this.valueIndex.put(value, i);
return value;
}
else
{
// in the set
return this.values.get(i);
}
}
}
What is the elegant way to convert JSONObject to URL parameters.
For example, JSONObject:
{stat: {123456: {x: 1, y: 2}, 123457: {z: 5, y: 2}}}}
this should be like:
stat[123456][x]=1&stat[123456][y]=2&stat[123457][z]=5&stat[123457][y]=2
of course with escaped symbols, and of course JSON object could be more complicated..
Maybe there already exist some mechanisms for that?
Thanks,
private static char[] quicksort (char[] array , int left , int right) {
if (left < right) {
int p = partition(array , left, right);
quicksort(array, left, p - 1 );
quicksort(array, p + 1 , right);
}
for (char i : array)
System.out.print(i + ” ”);
System.out.println();
return array;
}
private static int partition(char[] a, int left, int right) {
char p = a[left];
int l = left + 1, r = right;
while (l < r) {
while (l < right && a[l] < p) l++;
while (r > left && a[r] >= p) r--;
if (l < r) {
char temp = a[l];
a[l] = a[r];
a[r] = temp;
}
}
a[left] = a[r];
a[r] = p;
return r;
}
}
hi guys just a quick question regarding the above coding, i know that the above coding returns the following
B I G C O M P U T E R
B C E G I M P U T O R
B C E G I M P U T O R
B C E G I M P U T O R
B C E G I M P U T O R
B C E G I M O P T U R
B C E G I M O P R T U
B C E G I M O P R T U
B C E G I M O P R T U
B C E G I M O P R T U
B C E G I M O P R T U
B C E G I M O P R T U
B C E G I M O P R T U
when the sequence BIGCOMPUTER is used but my question is can someone explain to me what is happening in the code and how?
i know abit about the quick-sort algorithm but it doesnt seem to be the same in the above example.
I have one class that declares an enumeration type as:
public enum HOME_LOAN_TERMS {FIFTEEN_YEAR, THIRTY_YEAR};
Is this type usable in another class? I'm basically trying to complete a homework assignment where we have two types of loans, and one loanManager class. When I try to use the HOME_LOAN_TERMS.THIRTY_YEAR in my loanManager class that does not extend or implement the loan class, I get an error saying it 'cannot find symbol HOME_LOAN_TERMS.' So I did not know if my loanManager class needed to implement the two different loan classes. Thanks.