Creating Aion accounts with the intelliJ Maven plugins - java

I'm looking to create an Aion account/address when a user creates a new account on a website. The only way I have found is via the web3 API. Is there a way to do it on the backend with using the Java plugins?
Or is there a third party API that can facilitate this?
Or what is the best practice for creating user accounts that are relatively seamless and the user does not need to know much about the interactions?
I have checked the https://docs.aion.network page but there does not seem to be any relevant information.

Welcome to StackOverflow!
There is currently no way to programmatically create an account from within a Java contract. There is the Blockchain.create() function, but that is specifically for creating Java contracts.
There is this repo that you can use to create a private and public key using Java.
If you're creating a frontend however, you should use something like Web3.js to create an account object:
async function createAccount() {
const account = web3.eth.accounts.create(web3.utils.randomHex(32));
return account;
}
Then you could have a button in your HTML that calls createAccount().

Related

How to retrieve a specific Member from a Discord Guild using Java JDA

I am trying to get a specific Member object from a Guild by using the following:
event.getGuild().getMember(user)
Here, user is the User object of the user I want to get the Member object from. I have also tried using the .getMemberById, using the userID instead. However, in both cases I get a null-pointer exception.
I am sure that both my User object and userID are correct, because when adding a breakpoint it does show these, but it doesn't retrieve the Member, this stays null. Am I approaching this wrong?
I have also tried putting the following in my main file where I start the bot:
JDABuilder builder = JDABuilder.createDefault(BOT_TOKEN);
builder.enableIntents(GatewayIntent.GUILD_MEMBERS);
On the Discord developer portal I have enabled both the 'Privileged Gateway Intents' options.
The documentation of Guild#getMember tells you to see also Guild#retrieveMember which can be used to load members that are not cached.
If you have an event with a getMember() or retrieveMember() method, that should be used instead. Otherwise you can do this:
guild.retrieveMember(user).queue(member -> {
... use member here
});
Other alternatives are outlined in the JDA wiki here: Gateway Intents and Member Cache Policy
Most of these retrieval methods DO NOT require the privileged intent GUILD_MEMBERS. It is only required if you want to interact with the entire member list of a server, through methods like loadMembers or findMembers for example.

How to obtain a file stored in alfresco repository from JavaDelegate - serviceTask?

Greetings to the community! I am using alfresco community edition 6.0.0 and currently I am trying to implement a workflow where i have a serviceTask calling a custom class implementing the JavaDelegate class.
serviceTask in bpmn code:
<serviceTask id="delegate"
activiti:class="org.nick.java.GenerateDocument"
name="Get the document">
</serviceTask>
Java Delegate class
public class GenerateDocument implements JavaDelegate {
#Autowired
RelatedContentService relatedContentService;
public void execute(DelegateExecution execution) throws Exception {
ProcessEngine p = ProcessEngines.getDefaultProcessEngine();
}
}
what I would like to do is the service task calls the GenerateDocument class, I could somehow retrieve a document that is stored inside my alfresco repository (I know it's name and it's id in case there is a method needed).
Ideally, if I retrieve this file, I would like to perform changes on it and save it as a new file in the alfresco repository? Is the above scenario feasible? According to my so-far search on the web i will may need this RelatedContentService relatedContentService to do this, is this correct?
Thanks in advance for any help :)
Something that is cool about JavaDelegates running in Activiti embedded within Alfresco is that you have access to the ServiceRegistry. From there you can get any bean you might need.
For example, suppose your JavaDelegate needed to run an Alfresco action. You can use the ServiceRegistry to get the ActionService, and away you go:
ActionService actionService = getServiceRegistry().getActionService();
Action mailAction = actionService.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, SUBJECT);
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, notificationEmailAddress);
In your case, if you want to find a node, you probably want to use the SearchService to run a query or to find a node using its node reference.
Take a look at the Alfresco foundational Java API to see the collection of services that are available for finding, updating, and creating nodes.

How to make server-side domain models available to client-side web browser?

In my web application utilizing Spring MVC, I have a rich domain model.
I would like to make this domain model available to a client web browser. For example, as my domain model includes a class Person with methods Set<Person> getFriends() and DateTime getBirthday(), I would like to use these methods on the client side. Usage scenarios include
dynamically updating the visiting browser's HTML to list all friends when requested so by the user, or
sort persons in the HTML by their birthday.
Please notice I'm not looking here for accessing my domain model in the "view rendering stage" (e.g. JSP). I am looking here for accessing my domain model on my web application's users' browsers. So for example I don't want to sort Person instances during the "view rendering stage". I want this sorting to happen later, on my user's browser.
What are solutions to my challenge?
Javascript - there are frameworks that could help ease the burden. The scenario you have described is an Ajax call to some service. You could represent the data as json which would be lightweight and easy enough to add to the page using javascript.
Ember.js (specifically its Models) and Grails do exactly what you want when used together. I'm sure that you can use any Java framework to do this, but Grails makes it stupidly easy. Below are a few patterns to get you started, but here's a complete example app!
Domain class:
class Person {
String name
}
Controller:
class PersonsController {
def index() { render (["person": Person.list()] as JSON) }
}
Ember.js App:
App.Store = DS.Store.extend({
revision: 11,
adapter: DS.RESTAdapter.create({
namespace: 'app'
})
)};
App.Person = DS.Model.extend({
name: DS.attr('string')
)};
In your browser, this single command will populate the in-browser data store by fetching /app/persons from the backend. Modifying the in-browser instances will automatically HTTP POST the updated instance to your Controller.
App.Person.list()
You'll want to check out my answer on getting the two to play together in perfect harmony for more complex applications.
Abdull have you looked at GWT(Google Web ToolKit) http://bit.ly/YYz2Yx?
Here is some sample code that illustrates creation of client side components.
e.g. loading contacts
VerticalPanel contactsPanel = new VerticalPanel();
contactsPanel.setSpacing(4);
String[] contactNames = constants.cwStackPanelContacts();
String[] contactEmails = constants.cwStackPanelContactsEmails();
for (int i = 0; i < contactNames.length; i++) {
final String contactName = contactNames[i];
final String contactEmail = contactEmails[i];
final Anchor contactLink = new Anchor(contactName);
contactsPanel.add(contactLink)
http://bit.ly/12MOhZQ (for actual code sample)
If you were not limited to the browser - and thus javascript, I'd scream RMI about now. Luckily, there seems to be a solution to make it work. I have not tried it, but it might be worthwhile:
jabsorb is a simple, lightweight JSON-RPC library for communicating
between Javascript running in the browser and Java running on the
server. It allows you to call Java methods on the server from
Javascript as if they were local, complete with automatic parameter
and result serialization.
https://code.google.com/p/jabsorb/
Two populer javascript MVC frameworks:
http://backbonejs.org/
http://knockoutjs.com/
You can try them personally. suggestion are always subjective, your choice are always subjective as well. so just feel it yourself.

How to dynamically differentiate the memcahce instances in java code?

Can anyone suggest any design pattern to dynamically differentiate the memcahce instances in java code?
Previously in my application there is only one memcache instance configured this way
Step-1:
dev.memcached.location=33.10.77.88:11211
dev.memcached.poolsize=5
Step-2:
Then i am accessing that memcache in code as follows,
private MemcachedInterface() throws IOException {
String location =stringParam("memcached.location", "33.10.77.88:11211");
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(location));
}
Then i am invoking that memcache as follows in code using above MemcachedInterface(),
Step-3:
MemcachedInterface.getSoleInstance();
And then i am using that MemcachedInterface() to get/set data as follows,
MemcachedInterface.set(MEMCACHED_CUSTS, "{}");
resp = MemcachedInterface.gets(MEMCACHED_CUSTS);
My question is if i introduce an new memcache instance in our architechture,configuration is done as follows,
Step-1:
dev.memcached.location=33.10.77.89:11211
dev.memcached.poolsize=5
So, first memcache instance is in 33.10.77.88:11211 and second memcache instance is in 33.10.77.89:11211
until this its ok...but....
how to handle Step-2 and Step-3 in this case,To get the MemcachedInterface dynamically.
1)should i use one more interface called MemcachedInterface2() in step-2
Now the actual problem comes in,
I am having 4 webservers in my application.Previoulsy all are writing to MemcachedInterface(),but now as i will introduce one more memcache instance ex:MemcachedInterface2() ws1 and ws2 should write in MemcachedInterface() and ws3 and ws4 should write in ex:MemcachedInterface2()
So,if i use one more interface called MemcachedInterface2() as mentioned above,
This an code burden as i should change all the classes using WS3 and WS4 to Ex:MemcachedInterface2() .
Can anyone suggest one approach with limited code changes??
xmemcached supports constistent hashing which will allow your client to choose the right memcached server instance from the pool. You can refer to this answer for a bit more detail Do client need to worry about multiple memcache servers?
So, if I understood correctly, you'll have to
use only one memcached client in all your webapps
since you have your own wrapper class around the memcached client MemcachedInterface, you'll have to add some method to this interface, that enables to add/remove server to an existing client. See the user guide (scroll down a little): https://code.google.com/p/xmemcached/wiki/User_Guide#JMX_Support
as far as i can see is, you have duplicate code running on different machines as like parallel web services. thus, i recommend this to differentiate each;
Use Singleton Facade service for wrapping your memcached client. (I think you are already doing this)
Use Encapsulation. Encapsulate your memcached client for de-couple from your code. interface L2Cache
For each server, give them a name in global variable. Assign those values via JVM or your own configuration files via jar or whatever. JVM: --Dcom.projectname.servername=server-1
Use this global variable as a parameter, configure your Service getInstance method.
public static L2Cache getCache() {
if (System.getProperty("com.projectname.servername").equals("server-1"))
return new L2CacheImpl(SERVER_1_L2_REACHIBILITY_ADDRESSES, POOL_SIZE);
}
good luck with your design!
You should list all memcached server instances as space separated in your config.
e.g.
33.10.77.88:11211 33.10.77.89:11211
So, in your code (Step2):
private MemcachedInterface() throws IOException
{
String location =stringParam("memcached.location", "33.10.77.88:11211 33.10.77.89:11211");
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(location));
}
Then in Step3 you don't need to change anything...e.g. MemcachedInterface.getSoleInstance(); .
You can read more in memcached tutorial article:
Use Memcached for Java enterprise performance, Part 1: Architecture and setup
http://www.javaworld.com/javaworld/jw-04-2012/120418-memcached-for-java-enterprise-performance.html
Use Memcached for Java enterprise performance, Part 2: Database-driven web apps
http://www.javaworld.com/javaworld/jw-05-2012/120515-memcached-for-java-enterprise-performance-2.html

Are there any plugins or modules like Django flatpages for Java in Spring?

Current I use Django and Python for web development.
I know Java, Spring, and Hibernate but not to an advanced level.
My main aim is to build a website with user registration and some static pages.
Now in Django, the flat pages modules are best for static pages and this is most commonly used.
Is there anything like that which I can use in Java with Spring? So that I don't have to code. Because I find it very hard to code the whole administration section for simple websites.
A simple way to serve up static pages would be to create a simple Controller that has a basic ReqestMapping which takes a PathVariable. Create static pages for each identifier and let the Controller serve them up. As follows:
#Controller
public class StaticPagesController {
#RequestMapping("/static/{id}/view.do")
public String subscribersListingHandler(#PathVariable String id) {
return id;
}
}
In the above, id is the name of the JSP file. Example call: http://myapp.com/static/about/view.do.

Categories

Resources