I have some demo code as follwing.
Class<?> myClass = cl.loadClass("com.hp.ac.scriptengine.test." + generateClassName);
Object my_obj = myClass.newInstance();
MethodType mt;
MethodHandle mh;
MethodHandles.Lookup lookup = MethodHandles.lookup();
mt = MethodType.methodType(void.class, int.class);
mh = lookup.findVirtual(my_obj.getClass(), "ToDoit", mt);
mh.invokeExact(my_obj,1);
here '"com.hp.ac.scriptengine.test." + generateClassName' is a generated class.
I got the message as follows.
java.lang.invoke.WrongMethodTypeException: (I)V cannot be called as (Ljava/lang/Object;I)V
at com.hp.ac.scriptengine.test.compliebyCommandline.main(compliebyCommandline.java:138)
Here line 138 is mh.invokeExact(my_obj,1);'
I tried that demo code(such as ... mh.invokeExact("daddy",'d','n')...) in Java 7 API document. It works fine. Such call(mh.invokeExact("daddy",'d','n'))just invoke (CC)Ljava/lang/String other than (Ljava/lang/String;CC)Ljava/lang/String.
But why, in my code, mh.invokeExact(my_obj,1) invoke (Ljava/lang/Object;I)V other than (I)V ?
I think the problem is with int.class. Try Integeer.class or Integer.TYPE instead.
Related
I have a proto with imported Data types. something similar to:
import "google/protobuf/wrappers.proto";
message someMessage
.google.protobuf.StringValue someString = 1;
.google.protobuf.Int64Value someInt = 2;
.google.protobuf.DoubleValue someDouble = 3;
previously my proto looked like:
message someMessage {
string someString = 1;
Prior to adding data types, the code below worked just fine. Now when I run, I get an error similar to com.google.protobuf.InvalidProtocolBufferException: Invalid wrapper type: google.protobuf.StringValue
DynamicMessage.Builder dynamicMessageBuilder = DynamicMessage.newBuilder(someDescriptor);
JsonFormat.parser().merge(stringPayload, dynamicMessageBuilder);
byte[] blah = dynamicMessageBuilder.build().toByteArray();
How do I get my proto messages to build correctly with typed data?
Hello The answer actually lied in a different part of the code:
FileDescriptorProto myFile = DescriptorProtos.FileDescriptorSet.parseFrom(is).getFile(0);
someDescriptor = Descriptors.FileDescriptor.buildFrom(myFile, new Descriptors.FileDescriptor[]{}).findMessageTypeByName("myMessage");
We ended up doing something like this. Note that the actual solution is dynamic and not hard coded, but it is not as easily unerstood.
Descriptors.FileDescriptor valuetypes = Descriptors.FileDescriptor.buildFrom(fileDescriptorProtoList.get(0), new Descriptors.FileDescriptor[]{});
someDescriptor = Descriptors.FileDescriptor.buildFrom(fileDescriptorProtoList.get(1), new Descriptors.FileDescriptor[]{valueTypes}).findMessageTypeByName("myMessage");
Also note this is important when generating the descriptor files
<includeDependenciesInDescriptorSet>true</includeDependenciesInDescriptorSet>
I have a program in ruby which creates deployments, services and ing in a specific namespace. When I want to create a namespace, it complains for NoMethodError.
This is the code:
namespace = Kubeclient::Resource.new
namespace.metadata = {}
namespace.metadata.name = ns
#kube_client.create_daemon_set namespace
And this is the exception:
Exception occurred undefined method `create_namespace' for #<Kubeclient::Client:0x0000000267b810>
All other functions including creating deployment and service works fine.
This is a snippet from a test:
namespace = Kubeclient::Resource.new
namespace.metadata = {}
namespace.metadata.name = 'development'
client = Kubeclient::Client.new('http://localhost:8080/api/')
created_namespace = client.create_namespace(namespace)
assert_instance_of(Kubeclient::Resource, created_namespace)
assert_equal(namespace.metadata.name, created_namespace.metadata.name)
You forgot parenthesis.
ApplicationContext context = new ClassPathXmlApplicationContext("HelloWorldBean.xml");
HelloWorld h1 = (HelloWorld) context.getBean("b1");
h1.getMsg();
h1.getName();
Here all things are good, maven dependencies are added , but this getMsg or getName method not giving any output.
If I write
System.out.println(h1.getMsg() + h1.getName() );
It will give value of msg and name variable.
What is wrong in this can anybody help?
In pojo , getMsg should have System.out.println(msg); then it will print, otherwise you have to manually put getMsg method to **sysout* as you shown.
I am having an issue with the IONotificationCreatePort function in IOKit:
var NotificationPort = IONotificationPortCreate(MasterPort)
IONotificationPortSetDispatchQueue(NotificationPort, DispatchQueue)
gives the following compiler error when NotificationPort is used in the function call in the second line
'Unmanaged IONotificationPort' is not identical to
'IONotificationPort'
if I use the following code based on the information in the Using Swift with Cocoa and Objective-C document, it compiles but generates a runtime error
var NotificationPort = IONotificationPortCreate(MasterPort).takeRetainedValue()
IONotificationPortSetDispatchQueue(NotificationPort, DispatchQueue)
Thread 1: EXC_BAD_ACCESS(code=1, address=0xwhatever)
So I think I have the run time error figured out, the IONotificationPort object does not have takeRetainedValue method
The crux of the problem as I see it, is that the IONotificationPortCreate function creates an IONotificationPort object and returns the reference to it.
I have looked all over the place and there is lots of information about and ways to pass references into a function call from Swift but nowhere can I find how to deal with references as a return value.
Can Swift call an object by reference?
Or am I way off the mark here????
Here is the objective C code that I am trying to convert to swift:
_notificationPort = IONotificationPortCreate(masterPort);
IONotificationPortSetDispatchQueue(_notificationPort, _controllerQueue);
Here is the complete code snippet from my swift file:
//Get IOKit Master Port
var MasterPort: mach_port_t = 0
let BootstrapPort: mach_port_t = 0
var MasterPortReturnCode: kern_return_t = 0
MasterPortReturnCode = IOMasterPort(BootstrapPort, &MasterPort)
println("Master port returned as \(MasterPort) with return code of \(MasterPortReturnCode)")
//Set up notification port and send queue
let DispatchQueue = dispatch_queue_create("com.apparata.AVB_Browser", DISPATCH_QUEUE_SERIAL)
var NotificationPort = IONotificationPortCreate(MasterPort)
IONotificationPortSetDispatchQueue(NotificationPort, DispatchQueue)
I am trying to flush the mondrian dimension cache by following code -
org.olap4j.metadata.Schema OlapSchema = olapConnection.getOlapSchema();
NamedList<org.olap4j.metadata.Cube> cubeList = OlapSchema.getCubes();
org.olap4j.metadata.Member m = null;
for(org.olap4j.metadata.Cube cube: cubeList) {
m = cube.lookupMember(IdentifierNode.parseIdentifier( "[Time].[2013].[Jul2013]").getSegmentList());
final CacheControl cacheControl = olapConnection.getCacheControl(null);
CacheControl.MemberSet regionTime = cacheControl.createMemberSet(mondrian.olap.Member)m, false);
cacheControl.flush(regionTime);
}
But this code is throwing a runtime error "MondrianOlap4jMember and mondrian.olap.member are incompatible"
Looks like you need to do the following to flush the cache -
unwrap the member object returned by lookupMember function using Olap wrapper class like so -
m = cube.lookupMember(IdentifierNode.parseIdentifier( "[Time].[2013].[Jul2013]").getSegmentList());
OlapWrapper wrapper = (OlapWrapper)m;
mondrian.olap.Member MondrianMember = wrapper.unwrap(mondrian.olap.Member.class);
And now call the flush method -
cacheControl.flush(MondrianMember);